作者 lyh

gx

@@ -127,7 +127,7 @@ class CategoryController extends BaseController @@ -127,7 +127,7 @@ class CategoryController extends BaseController
127 'ids.required' => 'ID不能为空' 127 'ids.required' => 'ID不能为空'
128 ]); 128 ]);
129 129
130 - $data = $logic->delete($this->param['ids']); 130 + $data = $logic->categoryDelete();
131 return $this->success($data); 131 return $this->success($data);
132 } 132 }
133 } 133 }
@@ -72,6 +72,13 @@ class KeywordController extends BaseController @@ -72,6 +72,13 @@ class KeywordController extends BaseController
72 return $this->success($data); 72 return $this->success($data);
73 } 73 }
74 74
  75 + /**
  76 + * @remark :删除数据
  77 + * @name :delete
  78 + * @author :lyh
  79 + * @method :post
  80 + * @time :2023/8/23 17:44
  81 + */
75 public function delete(Request $request, KeywordLogic $logic) 82 public function delete(Request $request, KeywordLogic $logic)
76 { 83 {
77 $request->validate([ 84 $request->validate([
@@ -79,8 +86,7 @@ class KeywordController extends BaseController @@ -79,8 +86,7 @@ class KeywordController extends BaseController
79 ],[ 86 ],[
80 'ids.required' => 'ID不能为空' 87 'ids.required' => 'ID不能为空'
81 ]); 88 ]);
82 -  
83 - $data = $logic->delete($this->param['ids']); 89 + $data = $logic->keywordDelete();
84 return $this->success($data); 90 return $this->success($data);
85 } 91 }
86 92
@@ -119,26 +119,22 @@ class CategoryLogic extends BaseLogic @@ -119,26 +119,22 @@ class CategoryLogic extends BaseLogic
119 * @method :post 119 * @method :post
120 * @time :2023/8/21 17:23 120 * @time :2023/8/21 17:23
121 */ 121 */
122 - public function delete($ids, $map = []){  
123 - $ids= array_filter(Arr::splitFilterToArray($ids), 'intval');  
124 - 122 + public function categoryDelete(){
  123 + $ids = $this->param['ids'];
125 DB::beginTransaction(); 124 DB::beginTransaction();
126 try { 125 try {
  126 + $productModel = new Product();
127 foreach ($ids as $id){ 127 foreach ($ids as $id){
128 - $info = $this->getCacheInfo($id);  
129 - if(!$info){  
130 - continue; 128 + $product_info = $productModel->read(['category_id'=>['like','%,'.$id.',%']]);
  129 + if($product_info !== false){
  130 + $this->fail('当前分类拥有产品不允许删除');
131 } 131 }
132 //删除路由映射 132 //删除路由映射
133 RouteMap::delRoute(RouteMap::SOURCE_PRODUCT_CATE, $id, $this->user['project_id']); 133 RouteMap::delRoute(RouteMap::SOURCE_PRODUCT_CATE, $id, $this->user['project_id']);
134 } 134 }
135 - parent::delete($ids);  
136 - 135 + $this->model->del(['id'=>['in',$ids]]);
137 DB::commit(); 136 DB::commit();
138 - } catch (BsideGlobalException $e){  
139 - DB::rollBack();  
140 - $this->fail($e->getMessage());  
141 - } catch (\Exception $e){ 137 + }catch (\Exception $e){
142 DB::rollBack(); 138 DB::rollBack();
143 $this->fail('删除失败'); 139 $this->fail('删除失败');
144 } 140 }
@@ -71,24 +71,20 @@ class KeywordLogic extends BaseLogic @@ -71,24 +71,20 @@ class KeywordLogic extends BaseLogic
71 return $this->success(); 71 return $this->success();
72 } 72 }
73 73
74 - public function delete($ids, $map = []){  
75 - $ids= array_filter(Arr::splitFilterToArray($ids), 'intval');  
76 - 74 + public function keywordDelete(){
  75 + $ids = $this->param['ids'];
77 DB::beginTransaction(); 76 DB::beginTransaction();
78 try { 77 try {
  78 + $productModel = new Product();
79 foreach ($ids as $id){ 79 foreach ($ids as $id){
80 - $info = $this->getCacheInfo($id);  
81 - if(!$info){  
82 - continue; 80 + $product_info = $productModel->read(['category_id'=>['like','%,'.$id.',%']]);
  81 + if($product_info !== false){
  82 + $this->fail('当前关键词拥有产品不允许删除');
83 } 83 }
84 - //删除路由映射  
85 RouteMap::delRoute(RouteMap::SOURCE_PRODUCT_KEYWORD, $id, $this->user['project_id']); 84 RouteMap::delRoute(RouteMap::SOURCE_PRODUCT_KEYWORD, $id, $this->user['project_id']);
86 } 85 }
87 - parent::delete($ids); 86 + $this->model->del(['id'=>['in',$ids]]);
88 DB::commit(); 87 DB::commit();
89 - } catch (BsideGlobalException $e){  
90 - DB::rollBack();  
91 - $this->fail($e->getMessage());  
92 }catch (\Exception $e){ 88 }catch (\Exception $e){
93 DB::rollBack(); 89 DB::rollBack();
94 $this->fail('删除失败'); 90 $this->fail('删除失败');