shish 3 년 전
부모
커밋
8a2db39c48
1개의 변경된 파일15개의 추가작업 그리고 3개의 파일을 삭제
  1. 15 3
      app-ghs/controllers/CheckOrderController.php

+ 15 - 3
app-ghs/controllers/CheckOrderController.php

@@ -63,9 +63,21 @@ class CheckOrderController extends BaseController
         if ($totalNum > $mother->stock) {
         if ($totalNum > $mother->stock) {
             util::fail($motherName . "不足{$totalNum}扎");
             util::fail($motherName . "不足{$totalNum}扎");
         }
         }
-        $bigNum = bcsub($mother->stock, $totalNum, 2);
-        $bigNum = floatval($bigNum);
-        $itemList[] = ['productId' => $motherId, 'bigNum' => $bigNum, 'smallNum' => 0];
+        $motherBigNum = bcsub($mother->stock, $totalNum, 2);
+        $motherBigNum = floatval($motherBigNum);
+
+        $ids = array_column($itemList, 'productId');
+        $infoList = ProductClass::getByIds($ids, null, 'id');
+        if (!empty($infoList)) {
+            foreach ($itemList as $itemKey => $itemVal) {
+                $productId = $itemVal['productId'] ?? 0;
+                $bigNum = $itemVal['bigNum'] ?? 0;
+                $addBigNum = $infoList[$productId]['stock'] ?? 0;
+                $newBigNum = bcadd($bigNum, $addBigNum, 2);
+                $itemList[$itemKey]['bigNum'] = $newBigNum;
+            }
+        }
+        $itemList[] = ['productId' => $motherId, 'bigNum' => $motherBigNum, 'smallNum' => 0];
         $newJson = json_encode($itemList);
         $newJson = json_encode($itemList);
         $post['itemInfo'] = $newJson;
         $post['itemInfo'] = $newJson;