feat(StoreProductController): 根据库存状态调整商品添加逻辑

This commit is contained in:
mkm 2024-08-14 09:59:34 +08:00
parent dd676bdc0c
commit e87d906917
2 changed files with 24 additions and 14 deletions

View File

@ -115,20 +115,23 @@ class StoreProductController extends BaseAdminController
if ($count == 1) {
$store_id = $store_arr[0];
foreach ($product_arr as $key => $arr) {
// $find = StoreProduct::where('id', $arr['id'])->findOrEmpty()->toArray();
$data=[
'warehouse_id'=>$warehouse_id,
$data = [
'warehouse_id' => $warehouse_id,
'product_id' => $arr['id'],
'store_id' => $store_id,
'financial_pm' => 0,
'batch' => 1,
'nums' => $arr['stock'],
'status' =>1,
'admin_id' =>$this->adminId,
'status' => 1,
'admin_id' => $this->adminId,
];
WarehouseProductLogic::add($data);
StoreBranchProduct::where('product_id', $arr['id'])->where('store_id', $store_id)->inc('stock',$arr['stock'])->update();
if ($arr['stock'] == 0) {
$find = StoreProduct::where('id', $arr['id'])->findOrEmpty()->toArray();
StoreProductLogic::ordinary($arr, $store_id, $this->adminId, $find, $warehouse_id);
} else {
WarehouseProductLogic::add($data);
StoreBranchProduct::where('product_id', $arr['id'])->where('store_id', $store_id)->inc('stock', $arr['stock'])->update();
}
// StoreProductLogic::ordinary($arr, $store_id, $this->adminId, $find, $warehouse_id);
// Redis::send('store-storage', ['product_arr' => $arr, 'store_id' => $store_id, 'stock_type' => $stock_type, 'admin_id' => $this->adminId, 'warehouse_id' => $warehouse_id]);
@ -136,18 +139,24 @@ class StoreProductController extends BaseAdminController
} else {
foreach ($product_arr as $key => $arr) {
foreach ($store_arr as $k => $store_id) {
$data=[
'warehouse_id'=>$warehouse_id,
$data = [
'warehouse_id' => $warehouse_id,
'product_id' => $arr['id'],
'store_id' => $store_id,
'financial_pm' => 0,
'batch' => 1,
'nums' => $arr['stock'],
'status' =>1,
'admin_id' =>$this->adminId,
'status' => 1,
'admin_id' => $this->adminId,
];
WarehouseProductLogic::add($data);
StoreBranchProduct::where('product_id', $arr['id'])->where('store_id', $store_id)->inc('stock',$arr['stock'])->update();
if ($arr['stock'] == 0) {
$find = StoreProduct::where('id', $arr['id'])->findOrEmpty()->toArray();
StoreProductLogic::ordinary($arr, $store_id, $this->adminId, $find, $warehouse_id);
} else {
WarehouseProductLogic::add($data);
StoreBranchProduct::where('product_id', $arr['id'])->where('store_id', $store_id)->inc('stock', $arr['stock'])->update();
}
// $find = StoreProduct::where('id', $arr['id'])->findOrEmpty()->toArray();
// StoreProductLogic::ordinary($arr, $store_id, $this->adminId, $find, $warehouse_id);
// Redis::send('store-storage', ['product_arr' => $arr, 'store_id' => $store_id, 'stock_type' => $stock_type, 'admin_id' => $this->adminId, 'warehouse_id' => $warehouse_id]);

View File

@ -222,6 +222,7 @@ class StoreProductLogic extends BaseLogic
'bar_code'=> $params['bar_code'],
'purchase'=> $params['purchase'],
'rose'=> $params['rose']??0,
'image' => $params['image'],
]);
Db::commit();