Browse Source

记账记录表

afa 5 tháng trước cách đây
mục cha
commit
0be7984137
2 tập tin đã thay đổi với 10 bổ sung12 xóa
  1. 7 10
      app/api/controller/MoneyLog.php
  2. 3 2
      app/common/model/MoneyLog.php

+ 7 - 10
app/api/controller/MoneyLog.php

@@ -17,22 +17,19 @@ class MoneyLog extends Base
       //记账记录
       public function moneylog(MonuyModel $monuyModel)
       {
-            $time = $this->request->post('time/s', date('Y-m'));
-            $result['count'] = $monuyModel::getCountMonthBalance($time);
-            $result['list']  = $monuyModel
-                              ->with('users')
-                              ->where('status', MonuyModel::STATUS_NORMAL)
-                              ->whereMonth('create_date', $time)
-                              ->order('create_date desc,id desc')
-                              ->paginate(10);
-            $this->success('ok', $result);
+            $time = $this->request->post('time/s', '');
+            $count = $monuyModel::getCountMonthBalance($time);
+            $list  = $monuyModel->with('users')->where('status', MonuyModel::STATUS_NORMAL);
+            if(!empty($time)) $list = $list->whereMonth('create_date', $time);              
+            $list = $list->order('create_date desc,id desc')->paginate(10);
+            $this->success('ok', compact('list', 'count'));
       }
 
 
       //记账统计每天
       public function getCountDay(MonuyModel $monuyModel)
       {
-            $time = $this->request->post('time/s', date('Y-m'));
+            $time = $this->request->post('time/s', '');
             $result = $monuyModel::getCountDayBalance($time);
             $this->success('ok', $result);
       }

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

@@ -88,8 +88,9 @@ class MoneyLog Extends Model
     //按照类型天统计 收入- 支出
     public static function getCountDayBalance(string $time = '')
     {
-        $list = self::where('status', self::STATUS_NORMAL)->whereMonth('create_date', $time)
-                ->group('create_date')
+        $list = self::where('status', self::STATUS_NORMAL);
+        if(!empty($time)) $list = $list->whereMonth('create_date', $time);
+        $list = $list->group('create_date')
                 ->field('create_date, sum(if(type=1,`change`,0)) as income, sum(if(type=2,`change`, 0)) as expenditure')
                 ->select();
         return $list;