afa 5 ヶ月 前
コミット
223ec91ab4
3 ファイル変更26 行追加0 行削除
  1. 10 0
      app/api/controller/MoneyLog.php
  2. 2 0
      app/api/route/route.php
  3. 14 0
      app/common/model/MoneyLog.php

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

@@ -28,6 +28,16 @@ class MoneyLog extends Base
             $this->success('ok', $result);
       }
 
+
+      //记账统计每天
+      public function getCountDay(MonuyModel $monuyModel)
+      {
+            $time = $this->request->post('time/s', date('Y-m'));
+            $result = $monuyModel::getCountDayBalance($time);
+            $this->success('ok', $result);
+      }
+
+
       //记账统计
       public function getCount(MonuyModel $monuyModel)
       {

+ 2 - 0
app/api/route/route.php

@@ -55,6 +55,8 @@ Route::group('user', function () {
     Route::rule('getMoneyType','moneyLog/getConfig','POST');
     //记账统计
     Route::rule('getMoneyCount','MoneyLog/getCount','POST');
+    //记账统计每天
+    Route::rule('getMoneyCountDay','MoneyLog/getCountDay','POST');
 
   })->middleware(AllowCrossDomain::class);
 

+ 14 - 0
app/common/model/MoneyLog.php

@@ -84,4 +84,18 @@ class MoneyLog Extends Model
         ];
     }
 
+
+    //按照类型天统计 收入- 支出
+    public static function getCountDayBalance(string $time = '')
+    {
+        $list = self::where('status', self::STATUS_NORMAL)->whereMonth('create_date', $time)
+                ->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;
+    }
+
+
 }