shish 2 лет назад
Родитель
Сommit
468d6f6719
2 измененных файлов с 16 добавлено и 12 удалено
  1. 12 0
      app-ghs/controllers/StatBookController.php
  2. 4 12
      biz-ghs/book/classes/BookItemClass.php

+ 12 - 0
app-ghs/controllers/StatBookController.php

@@ -69,6 +69,18 @@ class StatBookController extends BaseController
         }
         $where['bookSn'] = $bookSn;
         $list = BookItemClass::getAllByCondition($where, 'addTime DESC', '*');
+        if (!empty($list)) {
+            $ids = array_column($list, 'itemId');
+            $productList = ProductClass::getAllByCondition(['id' => ['in', $ids]], null, '*', 'id', true);
+            foreach ($list as $key => $val) {
+                $productId = $val['itemId'] ?? 0;
+                $onNum = $val['onNum'] ?? 0;
+                $currentProduct = $productList[$productId] ?? [];
+                $stock = $currentProduct->stock ?? 0;
+                $remainNum = $stock > $onNum ? bcsub($stock, $onNum) : 0;
+                $list[$key]['remainStockNum'] = $remainNum;
+            }
+        }
         $shop = $this->shop;
         util::success(['list' => $list, 'shop' => $shop]);
     }

+ 4 - 12
biz-ghs/book/classes/BookItemClass.php

@@ -255,18 +255,10 @@ class BookItemClass extends BaseClass
             $unique = self::getLockById($id);
 
             $currentStock = $product->stock;
-            $remainStock = 0;
-            if ($currentStock > 0) {
-                //未上架数量
-                $unOnNum = bcsub($unique->bookNum, $unique->onNum);
-                //待采购数量
-                $unCgNum = bcsub($unOnNum, $unique->roadNum);
-                if ($currentStock > $unCgNum) {
-                    $remainStock = bcsub($currentStock, $unCgNum);
-                }
-            }
-            //新增待采数量 = 预订数量 - 剩余库存
-            $needCgNumValue = bcsub($num, $remainStock);
+            $hasNum = bcadd($currentStock, $unique->roadNum);
+            $overNum = $unique->bookNum > $hasNum ? 0 : bcsub($hasNum, $unique->bookNum);
+            //新增待采数量 = 预订数量 - 超出库存
+            $needCgNumValue = bcsub($num, $overNum);
             $addNeedCgNum = $needCgNumValue < 0 ? 0 : $needCgNumValue;
             $key = 'add_need_cg_num_' . $itemId;
             $lock = util::lock($key);