Parcourir la source

fix bug: 一个订单对应的花材可能是多个的,所以要用getAllByCondition获取花材列表

shizhongqi il y a 1 an
Parent
commit
49fd2a18cd
1 fichiers modifiés avec 35 ajouts et 33 suppressions
  1. 35 33
      biz-hd/order/classes/OrderClass.php

+ 35 - 33
biz-hd/order/classes/OrderClass.php

@@ -551,40 +551,42 @@ class OrderClass extends BaseClass
         $order->save();
         $order->save();
 
 
         // 重新占用库存(与取消订单时的库存回滚相反)
         // 重新占用库存(与取消订单时的库存回滚相反)
-        $item = OrderItemClass::getByCondition(['orderSn' => $order->orderSn], true);
-        if (empty($item)) {
-            return true;
-        }
-        $ptItemId = $item->ptItemId ?? 0;
-        $sjId = $item->sjId ?? 0;
-        $shopId = $item->shopId ?? 0;
-        $mainId = $item->mainId ?? 0;
-        $ratio = $item->ratio ?? 20;
-        $unitType = $item->unitType ?? 0;
-        if ($unitType == 0) {
-            $bigNum = $item->num;
-            $smallNum = 0;
-        } else {
-            $bigNum = 0;
-            $smallNum = $item->num;
-        }
-        $itemId = $item->itemId ?? 0;
-
-        // 重新扣减库存(占用库存)
-        $stockInfo = ProductClass::decreaseStock($itemId, $bigNum, $smallNum, true);
-        $recordData = [];
-        $recordData['sjId'] = $sjId;
-        $recordData['shopId'] = $shopId;
-        $recordData['mainId'] = $mainId;
-        $recordData['itemId'] = $ptItemId;
-        $recordData['itemNum'] = ProductClass::mergeItemNum($bigNum, $smallNum, $ratio);
-        $recordData['oldStock'] = $stockInfo['oldStock'];
-        $recordData['newStock'] = $stockInfo['newStock'];
-        $recordData['productId'] = $itemId;
-        $recordData['orderSn'] = $order->orderSn;
-        $recordData['relateName'] = '恢复取消的订单';
-        StockRecordClass::hdKdAddRecord($recordData);
+        $orderSn = $order->orderSn ?? '';
+        $itemList = OrderItemClass::getAllByCondition(['orderSn' => $orderSn], null, '*', null, true);
+        if (!empty($itemList)) {
+            foreach ($itemList as $item) {
+                $ptItemId = $item->ptItemId ?? 0;
+                $sjId = $item->sjId ?? 0;
+                $shopId = $item->shopId ?? 0;
+                $mainId = $item->mainId ?? 0;
+                $ratio = $item->ratio ?? 20;
+                $unitType = $item->unitType ?? 0;
+                if ($unitType == 0) {
+                    $bigNum = $item->num;
+                    $smallNum = 0;
+                } else {
+                    $bigNum = 0;
+                    $smallNum = $item->num;
+                }
+                $itemId = $item->itemId ?? 0;
 
 
+                // 重新扣减库存(占用库存)
+                $stockInfo = ProductClass::decreaseStock($itemId, $bigNum, $smallNum, true);
+                $recordData = [];
+                $recordData['sjId'] = $sjId;
+                $recordData['shopId'] = $shopId;
+                $recordData['mainId'] = $mainId;
+                $recordData['itemId'] = $ptItemId;
+                $recordData['itemNum'] = ProductClass::mergeItemNum($bigNum, $smallNum, $ratio);
+                $recordData['oldStock'] = $stockInfo['oldStock'];
+                $recordData['newStock'] = $stockInfo['newStock'];
+                $recordData['productId'] = $itemId;
+                $recordData['orderSn'] = $order->orderSn;
+                $recordData['relateName'] = '恢复取消的订单';
+                StockRecordClass::hdKdAddRecord($recordData);
+            }
+        }
+        return true;
     }
     }
 
 
     // 扣库存
     // 扣库存