feat: 修改了商品库存编辑功能
This commit is contained in:
parent
98da00e975
commit
a5953e3170
@ -55,14 +55,15 @@ class StoreBranchProductController extends BaseAdminController
|
||||
*/
|
||||
public function edit()
|
||||
{
|
||||
d(1);
|
||||
$params = (new StoreProductValidate())->post()->goCheck('edit');
|
||||
$result = StoreProductLogic::edit($params);
|
||||
if (true === $result) {
|
||||
return $this->success('编辑成功', [], 1, 1);
|
||||
}
|
||||
$params =$this->request->post();
|
||||
foreach($params['data'] as $k=>$v){
|
||||
StoreProductLogic::stock($v);
|
||||
if(StoreProductLogic::hasError()){
|
||||
return $this->fail(StoreProductLogic::getError());
|
||||
}
|
||||
}
|
||||
return $this->success('编辑成功', [], 1, 1);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
|
@ -257,4 +257,21 @@ class StoreProductLogic extends BaseLogic
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 增加库存
|
||||
*/
|
||||
public static function stock($data){
|
||||
Db::startTrans();
|
||||
try {
|
||||
StoreBranchProduct::where(['id' => $data['id']])->inc('stock',$data['stock'])->update();
|
||||
Db::commit();
|
||||
return true;
|
||||
} catch (\Exception $e) {
|
||||
Db::rollback();
|
||||
self::setError($e->getMessage());
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user