shish 3 vuotta sitten
vanhempi
commit
8a2db39c48
1 muutettua tiedostoa jossa 15 lisäystä ja 3 poistoa
  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) {
             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);
         $post['itemInfo'] = $newJson;