shish 4 lat temu
rodzic
commit
34c6d50c2c

+ 1 - 1
biz-ghs/order/services/OrderService.php

@@ -651,7 +651,7 @@ class OrderService extends BaseService
         //销售统计
         StatSaleClass::replace($shop, $amount);
         //客户采购统计
-        StatKhCgClass::replace($order);
+        StatKhCgClass::replace($order, $amount);
 
         //显示已下单流程
         $time = date("Y-m-d H:i:s");

+ 3 - 3
biz/stat/classes/StatKhCgClass.php

@@ -10,7 +10,7 @@ class StatKhCgClass extends BaseClass
     public static $baseFile = '\biz\stat\models\StatKhCg';
 
     //客户采购统计 shish 2021012
-    public static function replace($order, $date = null)
+    public static function replace($order, $amount, $date = null)
     {
         $sjId = $order->sjId ?? 0;
         $shopId = $order->shopId ?? 0;
@@ -21,7 +21,7 @@ class StatKhCgClass extends BaseClass
             $stat = self::add(['shopId' => $shopId, 'sjId' => $sjId, 'customId' => $customId, 'time' => $time], true);
         }
         $id = $stat->id;
-        $amount = $order->actPrice ?? 0;
+
         $unique = self::getLockById($id);
 
         $num = $order->itemNum ?? 0;
@@ -33,7 +33,7 @@ class StatKhCgClass extends BaseClass
         $unique->amount = $currentAmount;
 
         $unique->save();
-        StatKhCgMonthClass::replace($order, $time);
+        StatKhCgMonthClass::replace($order, $amount, $time);
     }
 
     //客户退款统计

+ 1 - 2
biz/stat/classes/StatKhCgMonthClass.php

@@ -12,7 +12,7 @@ class StatKhCgMonthClass extends BaseClass
     public static $baseFile = '\biz\stat\models\StatKhCgMonth';
 
     //每月客户采购统计 shish 20211012
-    public static function replace($order, $date = null)
+    public static function replace($order, $amount, $date = null)
     {
         if ($date == null) {
             $time = date('Ym');
@@ -32,7 +32,6 @@ class StatKhCgMonthClass extends BaseClass
             $stat = self::add(['shopId' => $shopId, 'sjId' => $sjId, 'customId' => $customId, 'time' => $time, 'year' => $year, 'month' => $month], true);
         }
         $id = $stat->id;
-        $amount = $order->actPrice ?? 0;
         $unique = self::getLockById($id);
 
         $num = $order->itemNum ?? 0;

+ 35 - 60
console/controllers/StatKhCgController.php

@@ -3,8 +3,7 @@
 namespace console\controllers;
 
 use biz\shop\classes\ShopClass;
-use biz\stat\classes\StatKdClass;
-use biz\stat\classes\StatRefundClass;
+use biz\stat\classes\StatKhCgClass;
 use bizGhs\order\classes\OrderClass;
 use bizGhs\order\classes\OrderItemClass;
 use bizGhs\order\classes\RefundOrderClass;
@@ -20,6 +19,13 @@ class StatKhCgController extends Controller
     // ./yii stat-kh-cg/bc
     public function actionBc()
     {
+
+        ini_set('memory_limit', '2045M');
+        set_time_limit(0);
+
+        $sql = 'TRUNCATE `xhStatKhCg`;TRUNCATE `xhStatKhCgMonth`;';
+        Yii::$app->db->createCommand($sql)->execute();
+
         $query = new \yii\db\Query();
         $query->from(Order::tableName());
 
@@ -28,62 +34,20 @@ class StatKhCgController extends Controller
                 $id = $order['id'] ?? 0;
                 $orderSn = $order['orderSn'] ?? '';
                 $itemList = OrderItemClass::getAllByCondition(['orderSn' => $orderSn], null, '*', null, true);
-                if (empty($itemList)) {
-                    continue;
-                }
-                $totalNum = 0;
-                foreach ($itemList as $key => $item) {
-                    $num = $item['num'] ?? 0;
-                    $totalNum = bcadd($totalNum, $num, 2);
-                }
-                OrderClass::updateById($id, ['itemNum' => $totalNum]);
-            }
-        }
-
-        $query = new \yii\db\Query();
-        $query->from(RefundOrder::tableName());
-
-        foreach ($query->batch() as $batch) {
-            foreach ($batch as $refund) {
-                $id = $refund['id'] ?? 0;
-                $orderSn = $refund['orderSn'] ?? '';
-                $relateOrderSn = $refund['relateOrderSn'] ?? '';
-                $current = OrderClass::getByCondition(['orderSn' => $relateOrderSn], true);
-                $customId = $current->customId ?? 0;
-                $itemList = RefundOrderItemClass::getAllByCondition(['orderSn' => $orderSn], null, '*', null, true);
-                $totalNum = 0;
                 if (!empty($itemList)) {
-                    foreach ($itemList as $item) {
-                        $num = $item['itemNum'] ?? 0;
+                    $totalNum = 0;
+                    foreach ($itemList as $key => $item) {
+                        $num = $item['num'] ?? 0;
                         $totalNum = bcadd($totalNum, $num, 2);
                     }
+                    OrderClass::updateById($id, ['itemNum' => $totalNum]);
                 }
-                RefundOrderClass::updateById($id, ['itemNum' => $totalNum, 'customId' => $customId]);
-            }
-        }
 
-    }
-
-    // ./yii stat-kd/update
-    public function actionUpdate()
-    {
-        ini_set('memory_limit', '2045M');
-        set_time_limit(0);
-
-        $sql = 'TRUNCATE `xhStatKd`;TRUNCATE `xhStatKdMonth`;';
-        Yii::$app->db->createCommand($sql)->execute();
-
-        $query = new \yii\db\Query();
-        $query->from(Order::tableName());
-
-        foreach ($query->batch() as $batch) {
-
-            foreach ($batch as $order) {
                 $status = $order['status'] ?? 0;
                 if ($status == 1 || $status == 5) {
                     continue;
                 }
-                $payWay = $order['payWay'] ?? 0;
+
                 $amount = $order['actPrice'] ?? 0;
                 $refundPrice = $order['refundPrice'] ?? 0;
                 if ($refundPrice > 0) {
@@ -95,29 +59,40 @@ class StatKhCgController extends Controller
                     continue;
                 }
                 $date = date('Ymd', strtotime($order['addTime']));
-                StatKdClass::replace($shop, $amount, $payWay, $date);
+                $current = OrderClass::getById($id, true);
+                StatKhCgClass::replace($current, $amount, $date);
+
+
             }
         }
 
-        $sql = 'TRUNCATE `xhStatRefund`;TRUNCATE `xhStatRefundMonth`;';
-        Yii::$app->db->createCommand($sql)->execute();
-
         $query = new \yii\db\Query();
         $query->from(RefundOrder::tableName());
 
         foreach ($query->batch() as $batch) {
             foreach ($batch as $refund) {
+                $id = $refund['id'] ?? 0;
+                $orderSn = $refund['orderSn'] ?? '';
                 $relateOrderSn = $refund['relateOrderSn'] ?? '';
-                $order = OrderClass::getByCondition(['orderSn' => $relateOrderSn], true);
-                $payWay = $order->payWay ?? 0;
-                $shopId = $refund['shopId'] ?? 0;
-                $shop = ShopClass::getLockById($shopId);
-                $amount = $refund['refundPrice'] ?? 0;
+                $current = OrderClass::getByCondition(['orderSn' => $relateOrderSn], true);
+                $customId = $current->customId ?? 0;
+                $itemList = RefundOrderItemClass::getAllByCondition(['orderSn' => $orderSn], null, '*', null, true);
+                $totalNum = 0;
+                if (!empty($itemList)) {
+                    foreach ($itemList as $item) {
+                        $num = $item['itemNum'] ?? 0;
+                        $totalNum = bcadd($totalNum, $num, 2);
+                    }
+                }
+                RefundOrderClass::updateById($id, ['itemNum' => $totalNum, 'customId' => $customId]);
+
                 $date = date('Ymd', strtotime($refund['addTime']));
-                StatRefundClass::replace($shop, $payWay, $amount, $date);
+                $current = RefundOrderClass::getById($id, true);
+                StatKhCgClass::refundReplace($current, $date);
+
             }
         }
-    }
 
+    }
 
 }