afa 5 månader sedan
förälder
incheckning
a63c49b870

+ 1 - 2
app/admin/controller/Dashboard.php

@@ -38,8 +38,7 @@ class Dashboard extends Backend
     {
         if($this->request->isAjax()){
             //顶部统计
-            $moneyLog = $moneyLog::getCountBalance();
-
+            $moneyLog = $moneyLog::getCountMonthBalance();
             $panel=[
                 rand(100,1000),
                 rand(100,1000),

+ 4 - 4
app/admin/controller/shop/ShopDelivery.php

@@ -46,10 +46,10 @@ class ShopDelivery extends Backend
             ->paginate($limit);
 
         //表格底部要有汇总:发货数量汇总  重量汇总 总价汇总
-        $total_num = $this->model->sum('num');
-        $this->assign('total_weigh', $this->model->sum('weigh'));
-        $this->assign('total_price', $this->model->sum('total_price'));
-        $result = ['total' => $list->total(), 'rows' => $list->items(), 'total_num' => $total_num];
+        $total_num = $this->model->where($where)->sum('num');
+        $total_weigh = $this->model->where($where)->sum('weigh');
+        $total_price = $this->model->where($where)->sum('total_price');
+        $result = ['total' => $list->total(), 'rows' => $list->items(), 'total_num' => $total_num, 'total_weigh' => $total_weigh, 'total_price' => $total_price];
         return json($result);
     }
 }

+ 17 - 19
app/admin/view/shop/shop_delivery/index.html

@@ -11,6 +11,7 @@
                 :show-summary="true"
                 :total-arr="totalArr"
                 :is-showtotal="true"
+                @data-loaded="handleData"
                 >
         </yun-table>
     </el-card>
@@ -46,29 +47,26 @@
            
             ],
             totalArr: [
-                {
-                    name:"发货数量汇总",
-                    value: Yunqi.data.total_num
-                },
-                {
-                    name:"发货重量汇总",
-                    value: Yunqi.data.total_weigh
-                },
-                {
-                    name:"发货总价汇总",
-                    value: Yunqi.data.total_price
-                },
-            ]
+                
+            ],
         },
         methods: {
-            test(){
-                console.log(this.$refs['yuntable'], "==");
+            handleData(data) {
+                this.totalArr = [
+                    {
+                        name:"发货数量汇总",
+                        value: data.total_num
+                    },{
+                        name:"发货重量汇总",
+                        value: data.total_weigh
+                    },{
+                        name:"发货总价汇总",
+                        value: data.total_price
+                    },
+                ]
             }
         },
-        
-        onLoad:function(query){
-            this.test()
-        },
+    
     }
 </script>
 <style>

+ 21 - 0
app/api/common.php

@@ -6,3 +6,24 @@ use think\Log;
 
 
 
+//获取某月天数
+function getDaysOfMonth($days)
+{
+    $date = new \DateTime("{$days}-01");
+    $days = $date->format('t');
+    return $days;
+}
+
+
+//获取某年多少天
+function getDaysOfYear($year)
+{
+    $year = intval($year);
+    if ($year % 400 == 0 || ($year % 4 == 0 && $year % 100 != 0)) {
+        return 366;
+    }
+    return 365;
+}
+
+
+

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

@@ -2,7 +2,7 @@
 
 namespace app\api\controller;
 
-use app\common\model\StockConfig;
+use DateTime;
 use app\common\model\MoneyLog as MonuyModel;
 use app\common\model\StockLog;
 use think\exception\ValidateException;
@@ -19,15 +19,36 @@ class MoneyLog extends Base
       {
 
             $time = $this->request->post('time/s', date('Y-m'));
-            $result['count'] = $monuyModel::getCountBalance($this->userinfo['id'], $time);
-            $result['list']  = $monuyModel//->where('user_id', $this->userinfo['id'])
+            $result['count'] = $monuyModel::getCountMonthBalance($this->userinfo['id'], $time);
+            $result['list']  = $monuyModel->where('user_id', $this->userinfo['id'])
                               ->whereMonth('create_date', $time)
                               ->order('id desc')
-                              //->group('create_date')
                               ->paginate(10);
             $this->success('ok', $result);
       }
 
+      //记账统计
+      public function getCount(MonuyModel $monuyModel)
+      {
+            
+            $type = $this->request->post('type/d, 1');
+            $time = $this->request->post('time/s', date('Y-m'));
+            //月统计 
+            if($type == 1){
+                  $result = $monuyModel::getCountMonthBalance($this->userinfo['id'], $time);
+                  //日均支出
+                  $day = getDaysOfMonth($time);
+                  $result['day_expenditure'] = ($result['expenditure'] > 0)? bcdiv($result['expenditure'], $day, 2): 0;
+            }else{
+                  $result = $monuyModel::getCountYearBalance($this->userinfo['id'], $time);
+                  //日均支出
+                  $day = getDaysOfYear($time);
+                  $result['day_expenditure'] = ($result['expenditure'] > 0)? bcdiv($result['expenditure'], $day, 2): 0;
+            }
+           
+            $this->success('ok', $result);
+      }
+
       //添加记账
       public function money(MonuyModel $monuyModel)
       {     

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

@@ -48,6 +48,8 @@ Route::group('user', function () {
     Route::rule('moneylog','MoneyLog/moneylog','POST');
     //记账类型配置
     Route::rule('getMoneyType','moneyLog/getConfig','POST');
+    //记账统计
+    Route::rule('getMoneyCount','MoneyLog/getCount','POST');
 
   })->middleware(AllowCrossDomain::class);
 

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

@@ -33,14 +33,12 @@ class MoneyLog Extends Model
     }
     
 
-
-    //按照类型统计 收入- 支出
-    public static function getCountBalance(int $user_id = 0, string $time = '')
+    //按照类型月统计 收入- 支出
+    public static function getCountMonthBalance(int $user_id = 0, string $time = '')
     {
         $income = self::where('type', self::TYPE_INCOME);
         if(!empty($user_id) && !empty($time)){
             $income = $income->where('user_id', $user_id)->whereMonth('create_date', $time);
-
         }
         $income = $income->sum('change');
         //支出
@@ -54,7 +52,30 @@ class MoneyLog Extends Model
             'balance' => $balance,
             'income' => $income,
             'expenditure' => $expenditure
-            
+        ];
+    }
+
+
+    //按照类型年统计 收入- 支出
+    public static function getCountYearBalance(int $user_id = 0, string $time = '')
+
+    {
+        $income = self::where('type', self::TYPE_INCOME);
+        if(!empty($user_id) && !empty($time)){
+            $income = $income->where('user_id', $user_id)->whereYear('create_date', $time);
+        }
+        $income = $income->sum('change');
+        //支出
+        $expenditure = self::where('type', self::TYPE_EXPENDITURE);
+        if(!empty($user_id) && !empty($time)){
+            $expenditure = $expenditure->where('user_id', $user_id)->whereYear('create_date', $time);
+        }
+        $expenditure = $expenditure->sum('change');
+        $balance = $income - $expenditure;
+        return [
+            'balance' => $balance,
+            'income' => $income,
+            'expenditure' => $expenditure
         ];
     }
 

+ 2 - 1
public/assets/js/components/Table.js

@@ -647,7 +647,8 @@ export default {
                 json.page=this.currentPage;
                 json.limit=this.pageSize;
                 Yunqi.ajax.json(this.extend.index_url,json).then(data=>{
-                    this.allData = data
+                    //this.allData = data
+                    this.$emit('data-loaded', data)
                     this.total=data.total;
                     this.render(data.rows);
                     Vue.nextTick(()=>{