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

@ -53,15 +53,21 @@ class SystemStoreController extends BaseAdminController
if($addList){ if($addList){
foreach ($addList as $key=>$value){ 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'); $removeList=$this->request->post('removeList');
if($removeList){ if($removeList){
foreach ($removeList as $key=>$value){ foreach ($removeList as $key=>$value){
StoreProductLogic::store_del($product_id,$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; return true;
} catch (\Exception $e) { } catch (\Exception $e) {
Db::rollback(); Db::rollback();
d($e);
self::setError($e->getMessage()); self::setError($e->getMessage());
return false; return false;
} }
@ -246,12 +245,11 @@ class StoreProductLogic extends BaseLogic
Db::startTrans(); Db::startTrans();
try { try {
StoreBranchProduct::where(['product_id' => $id, 'store_id' => $store_id])->update(['delete_time' => time()]); 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(); Db::commit();
return true; return true;
} catch (\Exception $e) { } catch (\Exception $e) {
Db::rollback(); Db::rollback();
d($e);
self::setError($e->getMessage()); self::setError($e->getMessage());
return false; return false;
} }