作者 lyh

gx

@@ -103,11 +103,6 @@ class BlogLogic extends BaseLogic @@ -103,11 +103,6 @@ class BlogLogic extends BaseLogic
103 $this->fail('error'); 103 $this->fail('error');
104 } 104 }
105 $info['category_id'] = explode(',',trim($info['category_id'],',')); 105 $info['category_id'] = explode(',',trim($info['category_id'],','));
106 -// $str = [];  
107 -// foreach ($category as $v){  
108 -// $this->getAllFather($v,$str);  
109 -// }  
110 -// $info['category_id'] = array_values(array_unique($str));  
111 //获取标签名称 106 //获取标签名称
112 $blogLabelLogic = new BlogLabelLogic(); 107 $blogLabelLogic = new BlogLabelLogic();
113 $info['label_name'] = $blogLabelLogic->getLabelName($info['label_id']); 108 $info['label_name'] = $blogLabelLogic->getLabelName($info['label_id']);
@@ -115,21 +110,6 @@ class BlogLogic extends BaseLogic @@ -115,21 +110,6 @@ class BlogLogic extends BaseLogic
115 return $this->success($info); 110 return $this->success($info);
116 } 111 }
117 112
118 -// /**  
119 -// * @remark :获取分类的所有上级  
120 -// * @name :getAllFather  
121 -// * @author :lyh  
122 -// * @method :post  
123 -// * @time :2023/10/20 9:08  
124 -// */  
125 -// public function getAllFather($id,&$str = []){  
126 -// $cateModel = new BlogCategoryModel();  
127 -// $info = $cateModel->read(['id'=>$id],['id','pid']);  
128 -// if($info !== false){  
129 -// $str[] = (int)$id;  
130 -// $this->getAllFather($info['pid'],$str);  
131 -// }  
132 -// }  
133 113
134 /** 114 /**
135 * @name :修改状态 115 * @name :修改状态
@@ -153,32 +153,11 @@ class NewsLogic extends BaseLogic @@ -153,32 +153,11 @@ class NewsLogic extends BaseLogic
153 $this->fail('error'); 153 $this->fail('error');
154 } 154 }
155 $info['category_id'] = explode(',',trim($info['category_id'],',')); 155 $info['category_id'] = explode(',',trim($info['category_id'],','));
156 -// $str = [];  
157 -// foreach ($category as $v){  
158 -// $this->getAllFather($v,$str);  
159 -// }  
160 -// $info['category_id'] = array_values(array_unique($str));  
161 $info['image_link'] = getImageUrl($info['image']); 156 $info['image_link'] = getImageUrl($info['image']);
162 return $this->success($info); 157 return $this->success($info);
163 } 158 }
164 159
165 /** 160 /**
166 - * @remark :获取分类的所有上级  
167 - * @name :getAllFather  
168 - * @author :lyh  
169 - * @method :post  
170 - * @time :2023/10/20 9:08  
171 - */  
172 - public function getAllFather($id,&$str = []){  
173 - $cateModel = new NewsCategoryModel();  
174 - $info = $cateModel->read(['id'=>$id],['id','pid']);  
175 - if($info !== false){  
176 - $str[] = (int)$id;  
177 - $this->getAllFather($info['pid'],$str);  
178 - }  
179 - }  
180 -  
181 - /**  
182 * @name :逻辑删除 161 * @name :逻辑删除
183 * @return void 162 * @return void
184 * @author :liyuhang 163 * @author :liyuhang
@@ -99,8 +99,6 @@ class CategoryLogic extends BaseLogic @@ -99,8 +99,6 @@ class CategoryLogic extends BaseLogic
99 $info = $this->model->read(['id'=>$id]); 99 $info = $this->model->read(['id'=>$id]);
100 $info['url'] = $info['route']; 100 $info['url'] = $info['route'];
101 $info['image_link'] = getImageUrl($info['image']); 101 $info['image_link'] = getImageUrl($info['image']);
102 - //获取当前分类子集  
103 - $info['sub'] = $this->model->read(['pid'=>$info['id']]);  
104 return $this->success($info); 102 return $this->success($info);
105 } 103 }
106 104
@@ -112,18 +110,18 @@ class CategoryLogic extends BaseLogic @@ -112,18 +110,18 @@ class CategoryLogic extends BaseLogic
112 * @time :2023/8/21 17:14 110 * @time :2023/8/21 17:14
113 */ 111 */
114 public function categorySave(){ 112 public function categorySave(){
115 - if(isset($this->param['id']) && !empty($this->param['id'])) {  
116 - $this->handleEditParam($this->param);  
117 - }  
118 DB::beginTransaction(); 113 DB::beginTransaction();
119 try { 114 try {
120 if(isset($this->param['id']) && !empty($this->param['id'])){ 115 if(isset($this->param['id']) && !empty($this->param['id'])){
121 //是否编辑路由 116 //是否编辑路由
122 $id = $this->editCategoryRoute($this->param['id'],$this->param['route']); 117 $id = $this->editCategoryRoute($this->param['id'],$this->param['route']);
  118 + $this->editHandleCategory($this->param['id'],$this->param['pid']);
123 $this->model->edit($this->param,['id'=>$this->param['id']]); 119 $this->model->edit($this->param,['id'=>$this->param['id']]);
124 }else{ 120 }else{
125 $this->param['project_id'] = $this->user['project_id']; 121 $this->param['project_id'] = $this->user['project_id'];
126 $id = $this->model->addReturnId($this->param); 122 $id = $this->model->addReturnId($this->param);
  123 + //处理子集
  124 + $this->addProcessingSon($id);
127 } 125 }
128 //路由映射 126 //路由映射
129 $route = RouteMap::setRoute($this->param['route'], RouteMap::SOURCE_PRODUCT_CATE, $id, $this->user['project_id']); 127 $route = RouteMap::setRoute($this->param['route'], RouteMap::SOURCE_PRODUCT_CATE, $id, $this->user['project_id']);
@@ -142,6 +140,63 @@ class CategoryLogic extends BaseLogic @@ -142,6 +140,63 @@ class CategoryLogic extends BaseLogic
142 } 140 }
143 141
144 /** 142 /**
  143 + * @param $cate_id
  144 + * @name :(处理子集)addProcessingSon
  145 + * @author :lyh
  146 + * @method :post
  147 + * @time :2023/6/13 11:59
  148 + */
  149 + public function addProcessingSon($cate_id){
  150 + if(!isset($this->param['pid'])){
  151 + $this->param['pid'] = 0;
  152 + }
  153 + //判断为子分类时
  154 + if($this->param['pid'] != 0){
  155 + //查看当前上级分类下是否有其他子分类
  156 + $cate_info = $this->model->read(['pid' => $this->param['pid'], 'id' => ['!=', $cate_id]]);
  157 + if ($cate_info === false) {
  158 + //查看当前上一级分类下是否有新闻
  159 + $productModel = new Product();
  160 + $blog_count = $productModel->where('category_id','like', '%,' . $this->param['pid'] . ',%')->count();
  161 + if ($blog_count > 0) {
  162 + $replacement = ',' . $cate_id . ',';
  163 + $old = ',' . $this->param['pid'] . ',';
  164 + //更新所有商品到当前分类
  165 + $productModel->where('category_id', 'like', '%' . $old . '%')
  166 + ->update(['category_id' => DB::raw("REPLACE(category_id, '$old', '$replacement')")]);
  167 + }
  168 + }
  169 + }
  170 + return $this->success();
  171 + }
  172 +
  173 + /**
  174 + * @remark :编辑分类,处理博客数据
  175 + * @name :editCategory
  176 + * @author :lyh
  177 + * @method :post
  178 + * @time :2023/10/20 9:32
  179 + */
  180 + public function editHandleCategory($id,$pid){
  181 + $info = $this->model->read(['id'=>$id],['id','pid']);
  182 + if($info['pid'] != $pid){
  183 + //修改勒上级,先查看上级是否拥有博客
  184 + $productModel = new Product();
  185 + $blogCount = $productModel->formatQuery(['category_id'=>['like','%,'.$pid.',%']])->count();
  186 + if($blogCount > 0){
  187 + //随机获取最后一级id
  188 + $replacement = $this->getLastId($id);
  189 + //存在博客时,移动所有博客到当前分类最后一级
  190 + $productModel->where('category_id', 'like', '%,' . $pid . ',%')->where('category_id', 'like', '%,' . $replacement . ',%')
  191 + ->update(['category_id' => DB::raw("REPLACE(category_id, ',$pid,', ',')")]);
  192 + $productModel->where('category_id', 'like', '%,' . $pid . ',%')
  193 + ->update(['category_id' => DB::raw("REPLACE(category_id, ',$pid,', ',$replacement,')")]);
  194 + }
  195 + }
  196 + return $this->success();
  197 + }
  198 +
  199 + /**
145 * @remark :编辑路由时生成路由记录 200 * @remark :编辑路由时生成路由记录
146 * @name :editCategoryRoute 201 * @name :editCategoryRoute
147 * @author :lyh 202 * @author :lyh
@@ -162,27 +217,6 @@ class CategoryLogic extends BaseLogic @@ -162,27 +217,6 @@ class CategoryLogic extends BaseLogic
162 } 217 }
163 218
164 /** 219 /**
165 - * @remark :验证编辑时是否可修改pid  
166 - * @name :handleEditParam  
167 - * @author :lyh  
168 - * @method :post  
169 - * @time :2023/8/21 17:43  
170 - */  
171 - public function handleEditParam(&$param){  
172 - $category_ids = Category::getChildIdsArr($param['id'] ?? 0);  
173 - if(in_array($param['pid'], $category_ids)){  
174 - $this->fail('上级分类不能是本分类或子分类');  
175 - }  
176 - $productModel = new Product();  
177 - $rs = $productModel->read(['category_id'=>['like','%,'.$param['id'].',%']],['id']);  
178 - if($rs !== false){  
179 - $this->fail('当前分类拥有产品,不允许修改级别');  
180 - }  
181 - return $this->success();  
182 - }  
183 -  
184 -  
185 - /**  
186 * @remark :删除 220 * @remark :删除
187 * @name :delete 221 * @name :delete
188 * @author :lyh 222 * @author :lyh