shish 4 سال پیش
والد
کامیت
022ace3aab
1فایلهای تغییر یافته به همراه37 افزوده شده و 30 حذف شده
  1. 37 30
      console/controllers/RefundItemController.php

+ 37 - 30
console/controllers/RefundItemController.php

@@ -8,6 +8,7 @@ use bizGhs\order\classes\OrderClass;
 use bizGhs\order\classes\OrderItemClass;
 use bizGhs\order\classes\RefundOrderClass;
 use bizGhs\order\classes\RefundOrderItemClass;
+use bizGhs\order\models\Order;
 use yii\console\Controller;
 
 class RefundItemController extends Controller
@@ -46,40 +47,46 @@ class RefundItemController extends Controller
         ini_set('memory_limit', '2045M');
         set_time_limit(0);
 
-        $list = OrderClass::getAllByCondition([], null, '*', null, true);
-        echo "数量:" . count($list) . "\n";
-        if (empty($list)) {
-            return false;
-        }
-        foreach ($list as $key => $order) {
-            $status = $order->status ?? 0;
-            if (in_array($status, [1, 5])) {
-                continue;
-            }
-            $orderSn = $order->orderSn ?? '';
-            if (empty($orderSn)) {
-                continue;
-            }
-            $itemList = OrderItemClass::getAllByCondition(['orderSn' => $orderSn], null, '*', null, true);
-            if (!empty($itemList)) {
-                foreach ($itemList as $itemInfo) {
-                    $sjId = $itemInfo->sjId ?? 0;
-                    $shopId = $itemInfo->shopId ?? 0;
-                    $productId = $itemInfo->productId ?? 0;
-                    if (empty($sjId) || empty($shopId)) {
-                        $p = ProductClass::getById($productId, true);
-                        $sjId = $p->sjId ?? 0;
-                        $shopId = $p->shopId ?? 0;
-                        $itemInfo->sjId = $sjId;
-                        $itemInfo->shopId = $shopId;
-                        $itemInfo->save();
-                        echo "发现没有sjId shopId 已经补充 orderItemId:{$itemInfo->id} sjId:{$sjId} shopId:{$shopId}  如果是0表示没有补到 \n";
+        $query = new \yii\db\Query();
+        $query->from(Order::tableName());
+        $query->where(['>', 'status', 1]);
+
+        foreach ($query->batch() as $purchases) {
+
+            foreach ($purchases as $order) {
+
+                $status = $order['status'] ?? 0;
+                if (in_array($status, [1, 5])) {
+                    continue;
+                }
+                $orderSn = $order['orderSn'] ?? '';
+                if (empty($orderSn)) {
+                    continue;
+                }
+                $itemList = OrderItemClass::getAllByCondition(['orderSn' => $orderSn], null, '*', null, true);
+                if (!empty($itemList)) {
+                    foreach ($itemList as $itemInfo) {
+                        $sjId = $itemInfo->sjId ?? 0;
+                        $shopId = $itemInfo->shopId ?? 0;
+                        $productId = $itemInfo->productId ?? 0;
+                        if (empty($sjId) || empty($shopId)) {
+                            $p = ProductClass::getById($productId, true);
+                            $sjId = $p->sjId ?? 0;
+                            $shopId = $p->shopId ?? 0;
+                            $itemInfo->sjId = $sjId;
+                            $itemInfo->shopId = $shopId;
+                            $itemInfo->save();
+                            echo "发现没有sjId shopId 已经补充 orderItemId:{$itemInfo->id} sjId:{$sjId} shopId:{$shopId}  如果是0表示没有补到 \n";
+                        }
+                        $date = date('Ymd', strtotime($order['addTime']));
+                        StatItemClass::replace($itemInfo, $date);
                     }
-                    $date = date('Ymd', strtotime($order->addTime));
-                    StatItemClass::replace($itemInfo, $date);
                 }
+
             }
+
         }
+
     }
 
 }