cqpCow 1 rok temu
rodzic
commit
324ba363c8
1 zmienionych plików z 10 dodań i 2 usunięć
  1. 10 2
      app/Service/ProductInventoryService.php

+ 10 - 2
app/Service/ProductInventoryService.php

@@ -153,6 +153,11 @@ class ProductInventoryService extends Service
             $stock[$key] = $value;
         }
 
+        //仓库
+        $store_map = Storehouse::whereIn('id',array_unique(array_column($array,'storehouse_id')))
+            ->pluck('title','id')
+            ->toArray();
+
         //产品字典
         $pro = Product::whereIn('id',$product_id)
             ->pluck('title','id')
@@ -161,10 +166,13 @@ class ProductInventoryService extends Service
             $tmp = explode(',',$key);
             //产品ID
             $product_id = $tmp[0];
+            //仓库id
+            $storehouse_id = $tmp[1];
+            $storehouse_title = $store_map[$storehouse_id] ?? "";
             //产品名称
             $pro_title = $pro[$product_id] ?? '';
             if(! $pro_title) return [false,'异常产品数据'];
-            if(! isset($stock[$key])) return [false,'产品:'. $pro_title .'暂无库存'];
+            if(! isset($stock[$key])) return [false,'当前仓库' . $storehouse_title .' 的产品:'. $pro_title .'暂无库存'];
             //产品库存
             $stock_product = $stock[$key];
 
@@ -172,7 +180,7 @@ class ProductInventoryService extends Service
             $save_data = $product_save[$key] ?? 0;//已保存数量
             $tmp_lock = ($stock_product['lock_number'] > 0 ? $stock_product['lock_number'] : 0) - $save_data;
             $number = $stock_product['number'] - ($tmp_lock > 0 ? $tmp_lock : 0);
-            if($value > $number) return [false, $pro_title. '数量不足,当前有效库存数量:' . $number];
+            if($value > $number) return [false, $pro_title. '数量不足,当前仓库:'. $storehouse_title . '的有效库存数量:' . $number];
         }
 
         return [true,''];