Przeglądaj źródła

wesmiler 报恩寺项目提交

wesmiler 4 lat temu
rodzic
commit
e2e8a9cee1
1 zmienionych plików z 18 dodań i 12 usunięć
  1. 18 12
      app/Services/TradeService.php

+ 18 - 12
app/Services/TradeService.php

@@ -48,7 +48,7 @@ class TradeService extends BaseService
         $page = isset($params['pageSize']) ? intval($params['pageSize']) : PAGE;
         $pageSize = isset($params['pageSize']) ? intval($params['pageSize']) : PERPAGE;
 
-        $model = $this->model::from('account_logs as a')
+        $dataList = $this->model::from('account_logs as a')
             ->leftJoin('member as m', 'm.id', '=', 'a.user_id')
             ->where(function ($query) use ($params) {
                 $query->where('a.mark', 1);
@@ -105,14 +105,10 @@ class TradeService extends BaseService
                 }
             })
             ->select(['a.id', 'a.user_id', 'm.nickname','a.type','a.pay_type','a.change_type','a.coin_type','a.money', 'a.balance', 'a.status', 'a.create_time', 'a.update_time','a.remark'])
-            ->orderBy('a.create_time', 'desc');
+            ->orderBy('a.create_time', 'desc')
+            ->->paginate($pageSize);
+
 
-        $countModel = $model;
-        $totals = $countModel->groupBy('a.change_type')->sum('a.money');
-        $moneyInc = isset($totals[0])? $totals[0] : 0;
-        $moneyDesc = isset($totals[1])? $totals[1] : 0;
-        $totalMoney = moneyFormat($moneyInc-$moneyDesc);
-        $dataList = $model->paginate($pageSize);
 
         $dataList = $dataList ? $dataList->toArray() : [];
         if ($dataList) {
@@ -122,15 +118,17 @@ class TradeService extends BaseService
             unset($item);
         }
 
+        $counts = $this->counts($params);
+
         return [
             'code' => 0,
             'success'=> true,
             'msg' => '操作成功',
             'count' => isset($dataList['total']) ? $dataList['total'] : 0,
             'counts'=> [
-                'total'=> $totalMoney,
-                'totalInc'=> $moneyInc,
-                'totalDesc'=> $moneyDesc,
+                'total'=> $counts[0],
+                'totalInc'=> $counts[1],
+                'totalDesc'=> $counts[2],
                 'today'=> rand(100,1000),
                 'week'=> rand(100,1000),
                 'month'=> rand(100,1000),
@@ -197,7 +195,15 @@ class TradeService extends BaseService
             })
             ->orderBy('a.create_time','desc')
             ->groupBy('a.change_type')
-            ->sum();
+            ->sum('a.money');
+
+        $count1 = isset($counts[0])? $counts[0] : 0;
+        $count2 = isset($counts[1])? $counts[1] : 0;
+        if($counts){
+            $counts[2] = moneyFormat($count1-$count2);
+        }else{
+            $counts = [0,0,0];
+        }
         return $counts;
     }