wesmiler 1 неделя назад
Родитель
Сommit
c5d7dc64b6
2 измененных файлов с 13 добавлено и 7 удалено
  1. 4 2
      app/Http/Controllers/Api/v1/TestController.php
  2. 9 5
      app/Services/Api/PriceService.php

+ 4 - 2
app/Http/Controllers/Api/v1/TestController.php

@@ -6,6 +6,7 @@ use App\Http\Controllers\Api\webApp;
 use App\Services\Api\MemberService;
 use App\Services\Api\OrderService;
 use App\Services\Api\PriceService;
+use App\Services\Api\SettleService;
 use App\Services\MpService;
 
 /**
@@ -20,9 +21,10 @@ class TestController extends webApp
     public function check()
     {
         echo 666;;
-        $result = PriceService::make()->updatePrice(1);
+        $result = SettleService::make()->commissionSettle(22);
+//        $result = PriceService::make()->updatePrice(1);
 dump($result);
-        return showJson(PriceService::make()->getError(), true, $result);
+        return showJson(SettleService::make()->getError(), true, $result);
     }
 
 

+ 9 - 5
app/Services/Api/PriceService.php

@@ -136,13 +136,14 @@ class PriceService extends BaseService
             }
 
             // 昨日价格
-            $lastPriceData = $this->getPriceData($lastDate, $type);
+            $lastPrice = $this->getTodayPrice($type);
 
             // 昨日全网资产
             $lastPropertyTotal = isset($ptAccount['last_property'])?$ptAccount['last_property']:0;
-            $ptProperty = isset($ptAccount['pt_property'])?$ptAccount['pt_property']:0; // 平台初始资产
+            $ptProperty = isset($ptAccount['property'])?$ptAccount['property']:0; // 平台初始资产
 
             // 今日新增资产
+            $todayPropertyTotal = 0;
             $todayProperty = AccountLogModel::where(['date'=>$date,'type'=>8,'account_type'=>2,'mark'=>1])->sum('money');
             if($todayProperty>=0 && $lastPropertyTotal>0){
                 // 当日全网资产衰减后
@@ -150,7 +151,7 @@ class PriceService extends BaseService
 
                 // 当日全网总资产
                 $todayPropertyTotal = moneyFormat($propertyTotalByReduce + $todayProperty, 6);
-            }else{
+            }else if($lastPrice<=0){
                 // 当日全网总资产
                 $todayPropertyTotal = $ptProperty;
             }
@@ -161,7 +162,7 @@ class PriceService extends BaseService
             $todayPoolTotal = isset($ptAccount['today_pool'])?$ptAccount['today_pool']:0;
 
             // 当日价格
-            $price = moneyFormat($poolTotal/$todayPropertyTotal, 6);
+            $price = $todayPropertyTotal>0?moneyFormat($poolTotal/$todayPropertyTotal, 6) : 0;
             if($price>0){
                 $data = [
                     'type'=>$type,
@@ -171,6 +172,7 @@ class PriceService extends BaseService
                     'today_pool'=>$todayPoolTotal,
                     'last_property'=>$lastPropertyTotal,
                     'today_property'=>$todayProperty,
+                    'property_total'=>$todayPropertyTotal,
                     'date'=>$date,
                     'create_time'=>time(),
                     'status'=>1,
@@ -190,12 +192,14 @@ class PriceService extends BaseService
                     'today_pool'=> 0,
                     'update_time'=>time()
                 ];
-                if(PtAccountModel::where(['id'=>$accountId])->update($updateData)){
+                if(!PtAccountModel::where(['id'=>$accountId])->update($updateData)){
                     DB::rollBack();
                     $this->error = '更新平台账户数据失败';
                     return false;
                 }
 
+                DB::commit();
+
                 $data['id'] = $logId;
                 RedisService::set($cacheKey, $data, 600);
                 RedisService::clear("caches:prices:data_{$type}_{$date}");