shish 4 years ago
parent
commit
1abe299667

+ 8 - 0
biz-ghs/order/classes/OrderClass.php

@@ -163,6 +163,14 @@ class OrderClass extends BaseClass
             $val->xhPrice = $price;
             $val->save();
 
+            if ($val->xhPreNum > $num) {
+                //客户下单退货数增加
+                $subNum = bcsub($val->xhPreNum, $num);
+                StatKhCgClass::ghsBookOrderRefundNum($order, $subNum);
+                //花材销量榜减少
+                StatItemClass::ghsBookOrderRefundNum($order, $val, $subNum);
+            }
+
             $itemPrice = bcadd($itemPrice, $price, 2);
 
             $productWeight = $info[$productId]['weight'] ?? 0;

+ 19 - 0
biz/stat/classes/StatItemClass.php

@@ -11,6 +11,25 @@ class StatItemClass extends BaseClass
 
     public static $baseFile = '\biz\stat\models\StatItem';
 
+    //预订单到货之后退货数
+    public static function ghsBookOrderRefundNum($order, $info, $num, $date = null)
+    {
+        $sjId = $order->sjId ?? 0;
+        $shopId = $order->shopId ?? 0;
+        $productId = $info->productId ?? 0;
+        $time = $date == null ? date('Ymd') : $date;
+        $stat = self::getByCondition(['sjId' => $sjId, 'shopId' => $shopId, 'itemId' => $productId, 'time' => $time], true);
+        if (empty($stat)) {
+            $stat = self::add(['shopId' => $shopId, 'sjId' => $sjId, 'itemId' => $productId, 'time' => $time], true);
+        }
+        $id = $stat->id;
+        $unique = self::getLockById($id);
+        $currentNum = bcadd($unique->refundNum, $num, 2);
+        $unique->refundNum = $currentNum;
+        $unique->save();
+        StatItemMonthClass::ghsBookOrderRefundNum($order, $info, $num, $time);
+    }
+
     //每日花材统计 ssh 2021012
     public static function replace($item, $date = null)
     {

+ 26 - 0
biz/stat/classes/StatItemMonthClass.php

@@ -11,6 +11,32 @@ class StatItemMonthClass extends BaseClass
 
     public static $baseFile = '\biz\stat\models\StatItemMonth';
 
+    public static function ghsBookOrderRefundNum($order, $info, $num, $date)
+    {
+        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;
+        $productId = $info->productId ?? 0;
+        $stat = self::getByCondition(['sjId' => $sjId, 'shopId' => $shopId, 'itemId' => $productId, 'time' => $time], true);
+        if (empty($stat)) {
+            $stat = self::add(['shopId' => $shopId, 'sjId' => $sjId, 'itemId' => $productId, 'time' => $time, 'year' => $year, 'month' => $month], true);
+        }
+        $id = $stat->id;
+        $unique = self::getLockById($id);
+        $currentNum = bcadd($unique->refundNum, $num, 2);
+        $unique->refundNum = $currentNum;
+        $unique->save();
+    }
+
     //每月花材统计 ssh 20211012
     public static function replace($item, $date = null)
     {

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

@@ -9,6 +9,28 @@ class StatKhCgClass extends BaseClass
 
     public static $baseFile = '\biz\stat\models\StatKhCg';
 
+    //预订单数量减少
+    public static function ghsBookOrderRefundNum($order, $num, $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);
+
+        $currentNum = bcadd($unique->refundNum, $num, 2);
+        $unique->refundNum = $currentNum;
+        $unique->save();
+
+        StatKhCgMonthClass::ghsBookOrderRefundNum($order, $num, $time);
+    }
+
     //供应商预订单退款,客户采购金额减少
     public static function ghsBookOrderChange($add, $order, $amount, $date = null)
     {

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

@@ -11,6 +11,35 @@ class StatKhCgMonthClass extends BaseClass
 
     public static $baseFile = '\biz\stat\models\StatKhCgMonth';
 
+    public static function ghsBookOrderRefundNum($order, $num, $date)
+    {
+        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);
+
+        $currentNum = bcadd($unique->refundNum, $num, 2);
+        $unique->refundNum = $currentNum;
+        $unique->save();
+
+        $unique->save();
+    }
+
     //供应商预订单退款,客户采购金额减少
     public static function ghsBookOrderChange($add, $order, $amount, $date = null)
     {