Pārlūkot izejas kodu

当天当月收入

林琦海 5 gadi atpakaļ
vecāks
revīzija
0f4bc888d6

+ 41 - 2
biz-hd/stat/classes/StatIncomeClass.php

@@ -7,7 +7,46 @@ use bizHd\base\classes\BaseClass;
 
 class StatIncomeClass extends BaseClass
 {
-	
+
 	public static $baseFile = '\bizHd\stat\models\StatIncome';
 
-}
+    //更新当前商家的数据 linqh 2021.4.15
+    // 收入更新,若无则新增
+    public static function updateOrInsert($sjId,$shopId,$amount)
+    {
+        $time = date('Ymd');
+        $where = [
+            'merchantId'=>$sjId,
+            'shopId'=>$shopId,
+            'time'=>$time,
+        ];
+        $model = self::getByCondition($where);
+        if($model){
+            $id = $model['id'];
+            //累加金额 amount
+            $newAmount = bcadd($amount,$model['amount'],2);
+            $totalAmount = bcadd($amount,$model['totalAmount'],2);
+            self::updateById($id,['amount'=>$newAmount,'totalAmount'=>$totalAmount]);
+        }else{
+            //insert
+            $data = $where;
+            $data['amount'] = $amount;
+            //totalAmount = 前一天的 totalAmount
+            $totalAmount = 0;
+            $lastDate = date('Ymd',strtotime("-1 day"));
+            $lastWhere = [
+                'merchantId'=>$sjId,
+                'shopId'=>$shopId,
+                'time'=>$lastDate,
+            ];
+            $lastModel = self::getByCondition($lastWhere);
+            if($lastModel){
+                $totalAmount = $lastModel['totalAmount'];
+            }
+            $data['totalAmount'] = bcadd($amount,$totalAmount,2);
+            $data['createTime'] = date('Y-m-d H:i:s');
+            self::add($data);
+        }
+    }
+
+}

+ 43 - 2
biz-hd/stat/classes/StatIncomeMonthClass.php

@@ -7,7 +7,48 @@ use bizHd\base\classes\BaseClass;
 
 class StatIncomeMonthClass extends BaseClass
 {
-	
+
 	public static $baseFile = '\bizHd\stat\models\StatIncomeMonth';
 
-}
+    public static function updateOrInsert($sjId,$shopId,$amount)
+    {
+        $time = date('Ym');
+        $year = date('Y');
+        $month = date('m');
+        $where = [
+            'merchantId'=>$sjId,
+            'shopId'=>$shopId,
+            'year'=>$year,
+            'month'=>$month,
+            'time'=>$time,
+        ];
+        $model = self::getByCondition($where);
+        if($model){
+            $id = $model['id'];
+            //累加金额 amount
+            $newAmount = bcadd($amount,$model['amount'],2);
+            $totalAmount = bcadd($amount,$model['totalAmount'],2);
+            self::updateById($id,['amount'=>$newAmount,'totalAmount'=>$totalAmount]);
+        }else{
+            //insert
+            $data = $where;
+            $data['amount'] = $amount;
+            //totalAmount = 前一天的 totalAmount
+            $totalAmount = 0;
+            $lastTime =  date('Ym',strtotime("-1 month"));
+            $lastWhere = [
+                'merchantId'=>$sjId,
+                'shopId'=>$shopId,
+                'time'=>$lastTime,
+            ];
+            $lastModel = self::getByCondition($lastWhere);
+            if($lastModel){
+                $totalAmount = $lastModel['totalAmount'];
+            }
+            $data['totalAmount'] = bcadd($amount,$totalAmount,2);
+            $data['createTime'] = date('Y-m-d H:i:s');
+            self::add($data);
+        }
+    }
+
+}

+ 1 - 1
biz/stat/classes/StatOutClass.php

@@ -12,7 +12,7 @@ class StatOutClass extends BaseClass
     public static $baseFile = '\biz\stat\models\StatOut';
 
     //更新当前商家的数据 linqh 2021.4.13
-    // 当采购后台,将价格更新,若无则新增  ps 总支出金额暂不累计
+    // 当采购后台,将价格更新
     public static function updateOrInsert($sjId,$shopId,$amount)
     {
         $time = date('Ymd');

+ 10 - 1
sql.sql

@@ -2101,4 +2101,13 @@ ADD COLUMN `freezeBalance`  decimal(9,2) NOT NULL DEFAULT 0 COMMENT '提现时
 ADD COLUMN `totalExpend`  decimal(9,2) NOT NULL DEFAULT 0 COMMENT '总支出' AFTER `totalIncome`,
 ADD COLUMN `totalView`  int(11) NOT NULL DEFAULT 0 COMMENT '累计访问次数' AFTER `status`,
 ADD COLUMN `totalUser`  int(11) NOT NULL DEFAULT 0 COMMENT '总用户;总客户数' AFTER `totalView`,
-ADD COLUMN `totalPurchaseOrder`  int(11) NOT NULL DEFAULT 0 COMMENT '总采购订单' AFTER `totalUser`;
+ADD COLUMN `totalPurchaseOrder`  int(11) NOT NULL DEFAULT 0 COMMENT '总采购订单' AFTER `totalUser`;
+
+=======linqh 2021.4.15
+===
+ALTER TABLE `xhStatIncome`
+ADD COLUMN `totalAmount`  decimal(9,2) NOT NULL DEFAULT 0 COMMENT '总收入金额' AFTER `amount`;
+ALTER TABLE `xhStatIncomeMonth`
+ADD COLUMN `totalAmount`  decimal(9,2) NOT NULL DEFAULT 0 COMMENT '总收入' AFTER `amount`;
+
+