作者 lyh

gx

@@ -113,15 +113,22 @@ class ProductController extends BaseController @@ -113,15 +113,22 @@ class ProductController extends BaseController
113 return $this->success($data); 113 return $this->success($data);
114 } 114 }
115 115
116 - public function delete(Request $request, ProductLogic $logic) 116 + /**
  117 + * @remark :删除
  118 + * @name :delete
  119 + * @author :lyh
  120 + * @method :post
  121 + * @time :2023/8/22 13:45
  122 + */
  123 + public function delete(ProductLogic $logic)
117 { 124 {
118 - $request->validate([ 125 + $this->request->validate([
119 'ids'=>['required', new Ids()] 126 'ids'=>['required', new Ids()]
120 ],[ 127 ],[
121 'ids.required' => 'ID不能为空' 128 'ids.required' => 'ID不能为空'
122 ]); 129 ]);
123 - $data = $logic->delete($this->param['ids']);  
124 - return $this->success($data); 130 + $logic->productDelete();
  131 + $this->response('success');
125 } 132 }
126 133
127 134
@@ -89,29 +89,22 @@ class ProductLogic extends BaseLogic @@ -89,29 +89,22 @@ class ProductLogic extends BaseLogic
89 * @method :post 89 * @method :post
90 * @time :2023/8/21 17:11 90 * @time :2023/8/21 17:11
91 */ 91 */
92 - public function delete($ids, $map =[]){  
93 - $ids= array_filter(Arr::splitFilterToArray($ids), 'intval'); 92 + public function productDelete(){
94 DB::beginTransaction(); 93 DB::beginTransaction();
95 try { 94 try {
96 - foreach ($ids as $k => $id) {  
97 - $info = $this->getCacheInfo($id);  
98 - if(!$info){  
99 - unset($ids[$k]);  
100 - continue;  
101 - } 95 + foreach ($this->param['ids'] as $k => $id) {
  96 + $info = $this->model->read(['id'=>$id]);
102 if($info->status == Product::STATUS_RECYCLE){ 97 if($info->status == Product::STATUS_RECYCLE){
103 //删除路由映射 98 //删除路由映射
104 RouteMap::delRoute(RouteMap::SOURCE_PRODUCT, $id, $this->user['project_id']); 99 RouteMap::delRoute(RouteMap::SOURCE_PRODUCT, $id, $this->user['project_id']);
105 //删除当前产品模版 100 //删除当前产品模版
106 $this->delProductModule($id); 101 $this->delProductModule($id);
  102 + $this->model->del(['id'=>['in',$this->param['ids']]]);
107 }else{ 103 }else{
108 //回收站 104 //回收站
109 - parent::save(['id' => $id, 'status' => Product::STATUS_RECYCLE]);  
110 - unset($ids[$k]); 105 + $this->model->edit(['status'=>2],['id'=>$id]);
111 } 106 }
112 } 107 }
113 - parent::delete($ids);  
114 -  
115 DB::commit(); 108 DB::commit();
116 }catch (\Exception $e){ 109 }catch (\Exception $e){
117 DB::rollBack(); 110 DB::rollBack();