feat: 修改系统商店控制器与产品逻辑,增加异常处理与错误返回功能

This commit is contained in:
mkm 2024-06-03 18:11:07 +08:00
parent 61a274ed4e
commit b103582188
2 changed files with 9 additions and 5 deletions

View File

@ -52,16 +52,22 @@ class SystemStoreController extends BaseAdminController
$product_id=$this->request->post('product_id');
if($addList){
foreach ($addList as $key=>$value){
StoreProductLogic::copy($product_id,$value);
StoreProductLogic::copy($product_id,$value);
if(StoreProductLogic::hasError()){
return $this->fail(StoreProductLogic::getError());
}
}
}
$removeList=$this->request->post('removeList');
if($removeList){
foreach ($removeList as $key=>$value){
StoreProductLogic::store_del($product_id,$value);
if(StoreProductLogic::hasError()){
return $this->fail(StoreProductLogic::getError());
}
}
}
return $this->dataLists(new SystemStoreSourceLists());
return $this->success('设置成功', [], 1, 1);
}
/**

View File

@ -230,7 +230,6 @@ class StoreProductLogic extends BaseLogic
return true;
} catch (\Exception $e) {
Db::rollback();
d($e);
self::setError($e->getMessage());
return false;
}
@ -246,12 +245,11 @@ class StoreProductLogic extends BaseLogic
Db::startTrans();
try {
StoreBranchProduct::where(['product_id' => $id, 'store_id' => $store_id])->update(['delete_time' => time()]);
StoreProductAttrValue::where(['product_id' => $id, 'store_id' => $store_id])->update(['delete_time' => time()]);
StoreBranchProductAttrValue::where(['product_id' => $id, 'store_id' => $store_id])->update(['delete_time' => time()]);
Db::commit();
return true;
} catch (\Exception $e) {
Db::rollback();
d($e);
self::setError($e->getMessage());
return false;
}