feat(StoreProductLogic, StoreStorageSend): 修改商品存储逻辑,重构库存计算与存储方式
This commit is contained in:
parent
e7ad3655c3
commit
49d7b67ea9
@ -72,10 +72,16 @@ class StoreProductLogic extends BaseLogic
|
|||||||
|
|
||||||
if ($params['is_store_all'] == 1) {
|
if ($params['is_store_all'] == 1) {
|
||||||
$store_arr = SystemStore::where('is_show', 1)->column('id');
|
$store_arr = SystemStore::where('is_show', 1)->column('id');
|
||||||
Redis::send('copy-product', ['product_id' => $res['id'], 'store_arr' => $store_arr]);
|
foreach($store_arr as $store_id){
|
||||||
|
Redis::send('store-storage', ['product_arr' => ['id'=>$res['id'],'stock'=>0], 'store_id' => $store_id, 'admin_id' => Request()->adminId]);
|
||||||
|
}
|
||||||
|
// Redis::send('copy-product', ['product_id' => $res['id'], 'store_arr' => $store_arr]);
|
||||||
} else {
|
} else {
|
||||||
if (is_array($params['store_arr']) && count($params['store_arr']) > 0) {
|
if (is_array($params['store_arr']) && count($params['store_arr']) > 0) {
|
||||||
Redis::send('copy-product', ['product_id' => $res['id'], 'store_arr' => $params['store_arr']]);
|
foreach($params['store_arr'] as $key =>$store_id){
|
||||||
|
Redis::send('store-storage', ['product_arr' => ['id'=>$res['id'],'stock'=>0], 'store_id' => $store_id, 'admin_id' => Request()->adminId]);
|
||||||
|
}
|
||||||
|
// Redis::send('copy-product', ['product_id' => $res['id'], 'store_arr' => $params['store_arr']]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -51,7 +51,7 @@ class StoreStorageSend implements Consumer
|
|||||||
'sales' => 0,
|
'sales' => 0,
|
||||||
'stock' => 0,
|
'stock' => 0,
|
||||||
];
|
];
|
||||||
$branch=StoreBranchProduct::create($product);
|
$branch = StoreBranchProduct::create($product);
|
||||||
$arr = [
|
$arr = [
|
||||||
'product_id' => $product_arr['id'],
|
'product_id' => $product_arr['id'],
|
||||||
'store_id' => $store_id,
|
'store_id' => $store_id,
|
||||||
@ -61,23 +61,27 @@ class StoreStorageSend implements Consumer
|
|||||||
'bar_code' => $attr_value['bar_code']
|
'bar_code' => $attr_value['bar_code']
|
||||||
];
|
];
|
||||||
StoreBranchProductAttrValue::create($arr);
|
StoreBranchProductAttrValue::create($arr);
|
||||||
$this->storage($find, $store_id, $admin_id, $product_arr);
|
if ($product_arr['stock'] > 0) {
|
||||||
|
$this->storage($find, $store_id, $admin_id, $product_arr);
|
||||||
|
}
|
||||||
Db::commit();
|
Db::commit();
|
||||||
return true;
|
return true;
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
Db::rollback();
|
Db::rollback();
|
||||||
Log::error('store-storage队列消费失败: ' . $e->getMessage().',line:'.$e->getLine().',file:'.$e->getFile());
|
Log::error('store-storage队列消费失败: ' . $e->getMessage() . ',line:' . $e->getLine() . ',file:' . $e->getFile());
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
Db::startTrans();
|
Db::startTrans();
|
||||||
try {
|
try {
|
||||||
$this->storage($find, $store_id, $admin_id, $product_arr);
|
if ($product_arr['stock'] > 0) {
|
||||||
Db::commit();
|
$this->storage($find, $store_id, $admin_id, $product_arr);
|
||||||
return true;
|
}
|
||||||
|
Db::commit();
|
||||||
|
return true;
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
Db::rollback();
|
Db::rollback();
|
||||||
Log::error('store-storage队列消费失败: ' . $e->getMessage().',line:'.$e->getLine().',file:'.$e->getFile());
|
Log::error('store-storage队列消费失败: ' . $e->getMessage() . ',line:' . $e->getLine() . ',file:' . $e->getFile());
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -95,9 +99,9 @@ class StoreStorageSend implements Consumer
|
|||||||
$storage['status'] = -1;
|
$storage['status'] = -1;
|
||||||
$storage['mark'] = '库存不足,主库存为:' . $find['stock'];
|
$storage['mark'] = '库存不足,主库存为:' . $find['stock'];
|
||||||
SystemStoreStorage::create($storage);
|
SystemStoreStorage::create($storage);
|
||||||
}else{
|
} else {
|
||||||
SystemStoreStorage::create($storage);
|
SystemStoreStorage::create($storage);
|
||||||
StoreProduct::where('id', $product_arr['id'])->dec('stock',$product_arr['stock'])->update();
|
StoreProduct::where('id', $product_arr['id'])->dec('stock', $product_arr['stock'])->update();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user