Merge pull request 'feat: 修改仓库产品逻辑以优化代码结构' (#116) from dev into main

Reviewed-on: #116
This commit is contained in:
mkm 2024-08-08 14:01:35 +08:00
commit c20dbe164a

View File

@ -35,7 +35,7 @@ class WarehouseProductLogic extends BaseLogic
// try { // try {
$data = [ $data = [
'warehouse_id' => $params['warehouse_id'], 'warehouse_id' => $params['warehouse_id'],
'store_id' => $params['store_id']??0, 'store_id' => $params['store_id'] ?? 0,
'product_id' => $params['product_id'], 'product_id' => $params['product_id'],
'financial_pm' => $params['financial_pm'], 'financial_pm' => $params['financial_pm'],
'batch' => 0, 'batch' => 0,
@ -119,25 +119,17 @@ class WarehouseProductLogic extends BaseLogic
$find = WarehouseProduct::where('id', $id)->find(); $find = WarehouseProduct::where('id', $id)->find();
$find->status = 1; $find->status = 1;
$find->batch = WarehouseProduct::where(['product_id' => $find['product_id'], 'warehouse_id' => $find['warehouse_id'], 'financial_pm' => $financial_pm,'store_id'=>$find['store_id']])->count(); $find->batch = WarehouseProduct::where(['product_id' => $find['product_id'], 'warehouse_id' => $find['warehouse_id'], 'financial_pm' => $financial_pm, 'store_id' => $find['store_id']])->count();
$find->save(); $find->save();
$storege = WarehouseProductStorege::where('warehouse_id', $find['warehouse_id'])->where('product_id', $find['product_id'])->find(); $storege = WarehouseProductStorege::where('warehouse_id', $find['warehouse_id'])->where('product_id', $find['product_id'])->find();
// if ($financial_pm == 0) {
// StoreProduct::where('id', $find['product_id'])->dec('stock', $find['nums'])->update();
// } else {
// StoreProduct::where('id', $find['product_id'])->inc('stock', $find['nums'])->update(['purchase' => $find['purchase'], 'cost' => $find['cost'], 'price' => $find['price']]);
// StoreBranchProduct::where('product_id', $find['product_id'])->update(['purchase' => $find['purchase'], 'cost' => $find['cost'], 'price' => $find['price']]);
// }
if ($storege) { if ($storege) {
if ($financial_pm == 0) { if ($financial_pm == 0) {
$storege->nums = bcsub($storege->nums, $find['nums']); WarehouseProductStorege::where('id',$storege['id'])->dec('nums', $find['nums'])->update();
} else { } else {
WarehouseProductStorege::where('id',$storege['id'])->inc('nums', $find['nums'])->update();
$storege->nums = bcadd($storege->nums, $find['nums']);
} }
$storege->save();
} else { } else {
WarehouseProductStorege::create([ WarehouseProductStorege::create([
'warehouse_id' => $find['warehouse_id'], 'warehouse_id' => $find['warehouse_id'],
@ -157,27 +149,26 @@ class WarehouseProductLogic extends BaseLogic
*/ */
public static function delete(array $params): bool public static function delete(array $params): bool
{ {
$res=WarehouseProduct::where('id',$params['id'])->find(); $res = WarehouseProduct::where('id', $params['id'])->find();
if($res){ if ($res) {
$res->delete(); $res->delete();
if($res['financial_pm']==1){ if ($res['financial_pm'] == 1) {
WarehouseProductStorege::where('warehouse_id',$res['warehouse_id'])->dec('nums',$res['nums'])->update(); WarehouseProductStorege::where('warehouse_id', $res['warehouse_id'])->dec('nums', $res['nums'])->update();
}elseif($res['financial_pm']==0){ } elseif ($res['financial_pm'] == 0) {
$find=SystemStoreStorage::where(['outbound_id'=>$res['id']])->find(); $find = SystemStoreStorage::where(['outbound_id' => $res['id']])->find();
if($find){ if ($find) {
$stock=StoreBranchProduct::where(['store_id'=>$res['store_id'],'product_id'=>$res['product_id']])->value('stock'); $stock = StoreBranchProduct::where(['store_id' => $res['store_id'], 'product_id' => $res['product_id']])->value('stock');
if($stock<$res['nums']){ if ($stock < $res['nums']) {
self::setError('商品库存不足,无法退回'); self::setError('商品库存不足,无法退回');
return false; return false;
} }
$find->delete(); $find->delete();
StoreBranchProduct::where(['store_id'=>$res['store_id'],'product_id'=>$res['product_id']])->dec('stock',$res['nums'])->update(); StoreBranchProduct::where(['store_id' => $res['store_id'], 'product_id' => $res['product_id']])->dec('stock', $res['nums'])->update();
} }
WarehouseProductStorege::where('warehouse_id',$res['warehouse_id'])->inc('nums',$res['nums'])->update(); WarehouseProductStorege::where('warehouse_id', $res['warehouse_id'])->inc('nums', $res['nums'])->update();
} }
return true; return true;
} }
return false; return false;
} }