소스 검색

统计用户余额

afa 5 달 전
부모
커밋
ea5444bb98
3개의 변경된 파일8개의 추가작업 그리고 8개의 파일을 삭제
  1. 1 0
      app/admin/controller/user/MoneyLog.php
  2. 4 3
      app/api/controller/MoneyLog.php
  3. 3 5
      app/common/model/MoneyLog.php

+ 1 - 0
app/admin/controller/user/MoneyLog.php

@@ -98,6 +98,7 @@ class MoneyLog extends Backend
                 $arr = self::getTypeAllByType((int)$params['type']);
                 $params['type_name'] = $arr[$params['type_name']];
             }
+            $params['create_month'] = date('Ym', strtotime($params['create_date']));
             $result = $row->save($params);
             if($this->callback){
                 $callback=$this->callback;

+ 4 - 3
app/api/controller/MoneyLog.php

@@ -95,7 +95,7 @@ class MoneyLog extends Base
                   $rows = $monuyModel->where('id', $data['id'])->where('user_id', $this->userinfo['id'])->whereDay('createtime')->where('status', $monuyModel::STATUS_NORMAL)->find();
                   if(!$rows) $this->error('数据不存在');
                   //发货数据
-                  $data['create_month'] = date('Ym', strtotime($data['create_date']));;//创建月份
+                  $data['create_month'] = date('Ym', strtotime($data['create_date']));//创建月份
                   $result = $rows->save($data);
 
                   Db::commit();
@@ -147,12 +147,13 @@ class MoneyLog extends Base
             $count = $monuyModel::getCountAllBalance($type, $time, $uids);
 
             //记账账户余额
-            $user = $monuyModel::getCountAllUserBalance($type, $time, $uids);
+            $account = $monuyModel::getCountAllUserBalance($type, $time, $uids);
+
             
             //月统计
             $month = $monuyModel::getCountAllMonthBalance($type, $time, $uids);
          
-            $this->success('ok', compact('count', 'user', 'month'));
+            $this->success('ok', compact('count', 'account', 'month'));
       }
 
 

+ 3 - 5
app/common/model/MoneyLog.php

@@ -117,9 +117,7 @@ class MoneyLog Extends Model
     //统计用户余额
     public static function getCountAllUserBalance(int $type, string $time = '', string $user_ids='')
     {
-        $list = self::alias('a')
-            ->join('user b', 'a.user_id=b.id')
-            ->where('a.status', self::STATUS_NORMAL);
+        $list = self::where('status', self::STATUS_NORMAL);
 
         if($type == 1 && !empty($time)) $list = $list->whereMonth('create_date', $time);
         if($type == 2 && !empty($time)) $list = $list->whereYear('create_date', $time);
@@ -129,8 +127,8 @@ class MoneyLog Extends Model
         }
         if(!empty($user_ids)) $list = $list->whereIn('user_id', $user_ids);
         $list = $list
-                ->field('a.user_id, sum(if(a.type=1,`change`,0)) as income, sum(if(a.type=2,`change`, 0)) as expenditure,b.nickname,b.avatar')
-                ->group('user_id')
+                ->field('bank_account, sum(if(type=1,`change`,0)) as income, sum(if(type=2,`change`, 0)) as expenditure')
+                ->group('bank_account')
                 ->select();
         return $list;
     }