shish 4 лет назад
Родитель
Сommit
b2b88051ed

+ 4 - 4
biz-ghs/order/classes/OrderClass.php

@@ -276,8 +276,8 @@ class OrderClass extends BaseClass
                 //退款统计
                 $payWay = $order->payWay ?? 0;
                 StatRefundClass::replace($shop, $payWay, $refundPrice);
-                //客户采购统计减少
-                StatKhCgClass::refundReplace($refund);
+                //供应商预订单退款给客户,客户采购金额减少
+                StatKhCgClass::ghsBookOrderChange(false, $order, $refundPrice);
             } else {
                 //欠款
                 $currentDebt = bcsub($currentPrice, $bookPrice, 2);
@@ -323,8 +323,8 @@ class OrderClass extends BaseClass
                 StatKdClass::replace($shop, $currentDebt, $payWay);
                 //每天销售收入统计
                 StatSaleClass::replace($shop, $currentDebt);
-                //客户采购统计
-                StatKhCgClass::replace($order, $currentDebt);
+                //预订单,客户补款给供应商,客户采购金额增加
+                StatKhCgClass::ghsBookOrderChange(true, $order, $currentDebt);
             }
         }
         return ['kiloFee' => $kiloFee, 'refund' => $refund, 'miniKilo' => $miniKilo];

+ 9 - 5
biz-hd/purchase/classes/PurchaseClass.php

@@ -180,6 +180,11 @@ class PurchaseClass extends BaseClass
             $shop->totalIncome = $currentTotalIncome;
             $shop->save();
 
+            //供应商退款,向供应商采购总金额减少
+            StatCgClass::replace($shop, $refundPrice, 0, false);
+            //供应商退款,按供应商分别采购的金额减少
+            StatCgGhsClass::hdCgGhsReplace(false, $cg, $refundPrice, 0);
+
             $currentType = dict::getDict('capitalType', 'hdBookRefund', 'id');
             $sjId = $cg->sjId ?? 0;
             $shopId = $cg->shopId ?? 0;
@@ -275,11 +280,10 @@ class PurchaseClass extends BaseClass
                 'event' => $event,
             ];
             ShopCapitalClass::addCapital($capitalData);
-            //采购总金额统计
-            StatCgClass::replace($shop, $currentDebt, 0);
-            //按供货商分别统计采购量
-            $num = 0;
-            StatCgGhsClass::hdCgGhsReplace($cg, $currentDebt, $num);
+            //补款给供应商,采购总金额增加
+            StatCgClass::replace($shop, $currentDebt, 0, true);
+            //补款给供应商,按供货商分别统计采购量增加
+            StatCgGhsClass::hdCgGhsReplace(true, $cg, $currentDebt, 0);
 
         }
         return ['refund' => $cgRefund];

+ 1 - 1
biz-hd/purchase/services/PurchaseService.php

@@ -407,7 +407,7 @@ class PurchaseService extends BaseService
         //按供货商分别统计采购量
         $num = $info->bigNum ?? 0;
         $amount = $info->orderPrice ?? 0;
-        StatCgGhsClass::hdCgGhsReplace($info, $amount, $num);
+        StatCgGhsClass::hdCgGhsReplace(true,$info, $amount, $num);
 
         //供应商资产变化
         $ghsId = $info->ghsId ?? 0;

+ 7 - 3
biz/stat/classes/StatCgClass.php

@@ -19,7 +19,7 @@ class StatCgClass extends BaseClass
     }
 
     //采购统计 ssh 20210828
-    public static function replace($shop, $amount, $num = 0)
+    public static function replace($shop, $amount, $num = 0, $add = true)
     {
         $mainId = $shop->mainId ?? 0;
         $sjId = $shop->sjId ?? 0;
@@ -33,13 +33,17 @@ class StatCgClass extends BaseClass
         if (empty($unique)) {
             util::fail('没有记录');
         }
-        $currentAmount = bcadd($unique->amount, $amount, 2);
+        if ($add) {
+            $currentAmount = bcadd($unique->amount, $amount, 2);
+        } else {
+            $currentAmount = bcsub($unique->amount, $amount, 2);
+        }
         $unique->amount = $currentAmount;
         $unique->totalAmount = $shop->totalPurchase;
         $unique->num += $num;
         $unique->save();
         //当月
-        StatCgMonthClass::replace($shop, $amount, $num);
+        StatCgMonthClass::replace($shop, $amount, $num, $add);
     }
 
     //今日采购

+ 7 - 3
biz/stat/classes/StatCgGhsClass.php

@@ -10,7 +10,7 @@ class StatCgGhsClass extends BaseClass
     public static $baseFile = '\biz\stat\models\StatCgGhs';
 
     //花店采购统计 ssh 20220402
-    public static function hdCgGhsReplace($cgInfo, $amount, $num, $date = null)
+    public static function hdCgGhsReplace($add, $cgInfo, $amount, $num, $date = null)
     {
         $sjId = $cgInfo->sjId ?? 0;
         $mainId = $cgInfo->mainId ?? 0;
@@ -23,12 +23,16 @@ class StatCgGhsClass extends BaseClass
         $id = $stat->id;
 
         $unique = self::getLockById($id);
-        $currentAmount = bcadd($unique->amount, $amount, 2);
+        if ($add) {
+            $currentAmount = bcadd($unique->amount, $amount, 2);
+        } else {
+            $currentAmount = bcsub($unique->amount, $amount, 2);
+        }
         $unique->amount = $currentAmount;
 
         $unique->num = bcadd($unique->num, $num);
         $unique->save();
-        StatCgGhsMonthClass::hdCgGhsReplace($cgInfo, $amount, $num, $time);
+        StatCgGhsMonthClass::hdCgGhsReplace($add, $cgInfo, $amount, $num, $time);
     }
 
     //城市批发商采购统计 ssh 2021012

+ 6 - 2
biz/stat/classes/StatCgGhsMonthClass.php

@@ -9,7 +9,7 @@ class StatCgGhsMonthClass extends BaseClass
 
     public static $baseFile = '\biz\stat\models\StatCgGhsMonth';
 
-    public static function hdCgGhsReplace($order, $amount, $num, $date = null)
+    public static function hdCgGhsReplace($add, $order, $amount, $num, $date = null)
     {
         if ($date == null) {
             $time = date('Ym');
@@ -30,7 +30,11 @@ class StatCgGhsMonthClass extends BaseClass
         }
         $id = $stat->id;
         $unique = self::getLockById($id);
-        $currentAmount = bcadd($unique->amount, $amount, 2);
+        if ($add) {
+            $currentAmount = bcadd($unique->amount, $amount, 2);
+        } else {
+            $currentAmount = bcsub($unique->amount, $amount, 2);
+        }
         $unique->amount = $currentAmount;
         $unique->num = bcadd($unique->num, $num);
         $unique->save();

+ 6 - 2
biz/stat/classes/StatCgMonthClass.php

@@ -11,7 +11,7 @@ class StatCgMonthClass extends BaseClass
     public static $baseFile = '\biz\stat\models\StatCgMonth';
 
     //采购统计 ssh 20210528
-    public static function replace($shop, $amount, $num)
+    public static function replace($shop, $amount, $num, $add = true)
     {
         $time = date('Ym');
         $year = date('Y');
@@ -27,7 +27,11 @@ class StatCgMonthClass extends BaseClass
         if (empty($unique)) {
             util::fail('没有记录');
         }
-        $currentAmount = bcadd($unique->amount, $amount, 2);
+        if ($add) {
+            $currentAmount = bcadd($unique->amount, $amount, 2);
+        } else {
+            $currentAmount = bcsub($unique->amount, $amount, 2);
+        }
         $unique->amount = $currentAmount;
         $unique->totalAmount = $shop->totalPurchase;
         $unique->num += $num;

+ 27 - 0
biz/stat/classes/StatKhCgClass.php

@@ -9,6 +9,33 @@ class StatKhCgClass extends BaseClass
 
     public static $baseFile = '\biz\stat\models\StatKhCg';
 
+    //供应商预订单退款,客户采购金额减少
+    public static function ghsBookOrderChange($add, $order, $amount, $date = null)
+    {
+        $sjId = $order->sjId ?? 0;
+        $shopId = $order->shopId ?? 0;
+        $customId = $order->customId ?? 0;
+        $time = $date == null ? date('Ymd') : $date;
+        $stat = self::getByCondition(['sjId' => $sjId, 'shopId' => $shopId, 'customId' => $customId, 'time' => $time], true);
+        if (empty($stat)) {
+            $stat = self::add(['shopId' => $shopId, 'sjId' => $sjId, 'customId' => $customId, 'time' => $time], true);
+        }
+        $id = $stat->id;
+
+        $unique = self::getLockById($id);
+
+        if ($add == true) {
+            $currentAmount = bcadd($unique->amount, $amount, 2);
+        } else {
+            $currentAmount = bcsub($unique->amount, $amount, 2);
+        }
+
+        $unique->amount = $currentAmount;
+
+        $unique->save();
+        StatKhCgMonthClass::ghsBookOrderChange($add, $order, $amount, $time);
+    }
+
     //客户采购统计 ssh 2021012
     public static function replace($order, $amount, $date = null)
     {

+ 33 - 0
biz/stat/classes/StatKhCgMonthClass.php

@@ -11,6 +11,39 @@ class StatKhCgMonthClass extends BaseClass
 
     public static $baseFile = '\biz\stat\models\StatKhCgMonth';
 
+    //供应商预订单退款,客户采购金额减少
+    public static function ghsBookOrderChange($add, $order, $amount, $date = null)
+    {
+        if ($date == null) {
+            $time = date('Ym');
+            $year = date('Y');
+            $month = date('m');
+        } else {
+            $timestamp = strtotime($date);
+            $time = date('Ym', $timestamp);
+            $year = date('Y', $timestamp);
+            $month = date('m', $timestamp);
+        }
+        $sjId = $order->sjId ?? 0;
+        $shopId = $order->shopId ?? 0;
+        $customId = $order->customId ?? 0;
+        $stat = self::getByCondition(['sjId' => $sjId, 'shopId' => $shopId, 'customId' => $customId, 'time' => $time], true);
+        if (empty($stat)) {
+            $stat = self::add(['shopId' => $shopId, 'sjId' => $sjId, 'customId' => $customId, 'time' => $time, 'year' => $year, 'month' => $month], true);
+        }
+        $id = $stat->id;
+        $unique = self::getLockById($id);
+
+        if ($add == true) {
+            $currentAmount = bcadd($unique->amount, $amount, 2);
+        } else {
+            $currentAmount = bcsub($unique->amount, $amount, 2);
+        }
+        $unique->amount = $currentAmount;
+
+        $unique->save();
+    }
+
     //每月客户采购统计 ssh 20211012
     public static function replace($order, $amount, $date = null)
     {