feat: 修改仓库产品控制器与逻辑,增强错误处理与库存检查
This commit is contained in:
parent
d7f03993bf
commit
308595da3c
@ -41,10 +41,11 @@ class WarehouseProductController extends BaseAdminController
|
||||
$params = (new WarehouseProductValidate())->post()->goCheck('add');
|
||||
$params['admin_id']=$this->adminId;
|
||||
$result = WarehouseProductLogic::add($params);
|
||||
if (true === $result) {
|
||||
if (WarehouseProductLogic::hasError()) {
|
||||
return $this->fail(WarehouseProductLogic::getError());
|
||||
}else{
|
||||
return $this->success('添加成功', [], 1, 1);
|
||||
}
|
||||
return $this->fail(WarehouseProductLogic::getError());
|
||||
}
|
||||
|
||||
|
||||
@ -59,10 +60,11 @@ class WarehouseProductController extends BaseAdminController
|
||||
$params = (new WarehouseProductValidate())->post()->goCheck('edit');
|
||||
$params['admin_id']=$this->adminId;
|
||||
$result = WarehouseProductLogic::edit($params);
|
||||
if (true === $result) {
|
||||
if (WarehouseProductLogic::hasError()) {
|
||||
return $this->fail(WarehouseProductLogic::getError());
|
||||
}else{
|
||||
return $this->success('编辑成功', [], 1, 1);
|
||||
}
|
||||
return $this->fail(WarehouseProductLogic::getError());
|
||||
}
|
||||
|
||||
|
||||
@ -76,8 +78,12 @@ class WarehouseProductController extends BaseAdminController
|
||||
{
|
||||
$params = (new WarehouseProductValidate())->post()->goCheck('delete');
|
||||
WarehouseProductLogic::delete($params);
|
||||
if (WarehouseProductLogic::hasError()) {
|
||||
return $this->fail(WarehouseProductLogic::getError());
|
||||
}else{
|
||||
return $this->success('删除成功', [], 1, 1);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
|
@ -163,8 +163,17 @@ class WarehouseProductLogic extends BaseLogic
|
||||
if($res['financial_pm']==1){
|
||||
WarehouseProductStorege::where('warehouse_id',$res['warehouse_id'])->dec('nums',$res['nums'])->update();
|
||||
}elseif($res['financial_pm']==0){
|
||||
$find=SystemStoreStorage::where(['outbound_id'=>$res['id']])->find();
|
||||
if($find){
|
||||
$stock=StoreBranchProduct::where(['store_id'=>$res['store_id'],'product_id'=>$res['product_id']])->value('stock');
|
||||
if($stock<$res['nums']){
|
||||
self::setError('商品库存不足,无法退回');
|
||||
return false;
|
||||
}
|
||||
$find->delete();
|
||||
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();
|
||||
SystemStoreStorage::where(['outbound_id'=>$res['id']])->delete();
|
||||
}
|
||||
|
||||
return true;
|
||||
|
Loading…
x
Reference in New Issue
Block a user