feat: 修改了商品库存编辑功能

This commit is contained in:
mkm 2024-06-05 09:09:57 +08:00
parent 98da00e975
commit a5953e3170
2 changed files with 24 additions and 6 deletions

View File

@ -55,13 +55,14 @@ class StoreBranchProductController extends BaseAdminController
*/ */
public function edit() public function edit()
{ {
d(1); $params =$this->request->post();
$params = (new StoreProductValidate())->post()->goCheck('edit'); foreach($params['data'] as $k=>$v){
$result = StoreProductLogic::edit($params); StoreProductLogic::stock($v);
if (true === $result) { if(StoreProductLogic::hasError()){
return $this->success('编辑成功', [], 1, 1); return $this->fail(StoreProductLogic::getError());
}
} }
return $this->fail(StoreProductLogic::getError()); return $this->success('编辑成功', [], 1, 1);
} }

View File

@ -257,4 +257,21 @@ class StoreProductLogic extends BaseLogic
return false; 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;
}
}
} }