作者 lyh

gx

@@ -86,7 +86,7 @@ class CategoryController extends BaseController @@ -86,7 +86,7 @@ class CategoryController extends BaseController
86 } 86 }
87 87
88 /** 88 /**
89 - * @name :(添加/编辑时获取顶级分类)topList 89 + * @name :(添加/编辑时获取分类)topList
90 * @author :lyh 90 * @author :lyh
91 * @method :post 91 * @method :post
92 * @time :2023/6/13 9:03 92 * @time :2023/6/13 9:03
@@ -115,16 +115,12 @@ class CategoryLogic extends BaseLogic @@ -115,16 +115,12 @@ class CategoryLogic extends BaseLogic
115 if(isset($this->param['id']) && !empty($this->param['id'])){ 115 if(isset($this->param['id']) && !empty($this->param['id'])){
116 $this->param['route'] = RouteMap::setRoute($this->param['route'], RouteMap::SOURCE_PRODUCT_CATE, $this->param['id'], $this->user['project_id']); 116 $this->param['route'] = RouteMap::setRoute($this->param['route'], RouteMap::SOURCE_PRODUCT_CATE, $this->param['id'], $this->user['project_id']);
117 $route = $this->param['route']; 117 $route = $this->param['route'];
118 - //处理子集  
119 - $this->editHandleCategory($this->param['id'],$this->param['pid']);  
120 $this->model->edit($this->param,['id'=>$this->param['id']]); 118 $this->model->edit($this->param,['id'=>$this->param['id']]);
121 }else{ 119 }else{
122 $this->param['project_id'] = $this->user['project_id']; 120 $this->param['project_id'] = $this->user['project_id'];
123 $id = $this->model->addReturnId($this->param); 121 $id = $this->model->addReturnId($this->param);
124 $route = RouteMap::setRoute($this->param['route'], RouteMap::SOURCE_PRODUCT_CATE, $id, $this->user['project_id']); 122 $route = RouteMap::setRoute($this->param['route'], RouteMap::SOURCE_PRODUCT_CATE, $id, $this->user['project_id']);
125 $this->edit(['route'=>$route],['id'=>$id]); 123 $this->edit(['route'=>$route],['id'=>$id]);
126 - //处理子集  
127 - $this->addProcessingSon($id);  
128 } 124 }
129 //清除缓存 125 //清除缓存
130 Common::del_user_cache('product_category',$this->user['project_id']); 126 Common::del_user_cache('product_category',$this->user['project_id']);
@@ -139,90 +135,6 @@ class CategoryLogic extends BaseLogic @@ -139,90 +135,6 @@ class CategoryLogic extends BaseLogic
139 } 135 }
140 136
141 /** 137 /**
142 - * @param $cate_id  
143 - * @name :(处理子集)addProcessingSon  
144 - * @author :lyh  
145 - * @method :post  
146 - * @time :2023/6/13 11:59  
147 - */  
148 - public function addProcessingSon($cate_id){  
149 - if(!isset($this->param['pid'])){  
150 - $this->param['pid'] = 0;  
151 - }  
152 - //判断为子分类时  
153 - if($this->param['pid'] != 0){  
154 - //查看当前上级分类下是否有其他子分类  
155 - $cate_info = $this->model->read(['pid' => $this->param['pid'], 'id' => ['!=', $cate_id]]);  
156 - if ($cate_info === false) {  
157 - $productModel = new Product();  
158 - $blog_count = $productModel->where('category_id','like', '%,' . $this->param['pid'] . ',%')->count();  
159 - if ($blog_count > 0) {  
160 - $replacement = ',' . $cate_id . ',';  
161 - $old = ',' . $this->param['pid'] . ',';  
162 - //更新所有商品到当前分类  
163 - $productModel->where('category_id', 'like', '%' . $old . '%')  
164 - ->update(['category_id' => DB::raw("REPLACE(category_id, '$old', '$replacement')")]);  
165 - //同步更新关联表  
166 - $categoryRelatedModel = new CategoryRelated();  
167 - $categoryRelatedModel->edit(['category_id'=>$cate_id],['category_id'=>$this->param['pid']]);  
168 - }  
169 - }  
170 - }  
171 - return $this->success();  
172 - }  
173 -  
174 - /**  
175 - * @remark :编辑分类,处理博客数据  
176 - * @name :editCategory  
177 - * @author :lyh  
178 - * @method :post  
179 - * @time :2023/10/20 9:32  
180 - */  
181 - public function editHandleCategory($id,$pid){  
182 - $info = $this->model->read(['id'=>$id],['id','pid']);  
183 - if($info['pid'] != $pid){  
184 - //修改勒上级,先查看上级是否拥有博客  
185 - $productModel = new Product();  
186 - $blogCount = $productModel->formatQuery(['category_id'=>['like','%,'.$pid.',%']])->count();  
187 - if($blogCount > 0){  
188 - //随机获取最后一级id  
189 - $replacement = $this->getLastId($id);  
190 - //存在博客时,移动所有博客到当前分类最后一级  
191 - $productModel->where('category_id', 'like', '%,' . $pid . ',%')->where('category_id', 'like', '%,' . $replacement . ',%')  
192 - ->update(['category_id' => DB::raw("REPLACE(category_id, ',$pid,', ',')")]);  
193 - $productModel->where('category_id', 'like', '%,' . $pid . ',%')  
194 - ->update(['category_id' => DB::raw("REPLACE(category_id, ',$pid,', ',$replacement,')")]);  
195 - //同步更新关联表  
196 - $categoryRelatedModel = new CategoryRelated();  
197 - $cateRelateList = $categoryRelatedModel->list(['category_id'=>$pid]);  
198 - if(!empty($cateRelateList)){  
199 - foreach ($cateRelateList as $v){  
200 - $categoryRelatedModel->del(['category_id'=>$replacement,'product_id'=>$v['product_id']]);  
201 - }  
202 - }  
203 - $categoryRelatedModel->edit(['category_id'=>$replacement],['category_id'=>$pid]);  
204 - }  
205 - }  
206 - return $this->success();  
207 - }  
208 -  
209 - /**  
210 - * @remark :随机获取当前id下最后一级的id  
211 - * @name :getLastId  
212 - * @author :lyh  
213 - * @method :post  
214 - * @time :2023/10/20 9:45  
215 - */  
216 - public function getLastId($id){  
217 - $info = $this->model->read(['pid'=>$id],['id']);  
218 - if($info !== false){  
219 - return $this->getLastId($info['id']);  
220 - }else{  
221 - return $id;  
222 - }  
223 - }  
224 -  
225 - /**  
226 * @remark :删除 138 * @remark :删除
227 * @name :delete 139 * @name :delete
228 * @author :lyh 140 * @author :lyh
@@ -309,13 +221,10 @@ class CategoryLogic extends BaseLogic @@ -309,13 +221,10 @@ class CategoryLogic extends BaseLogic
309 $str = ''; 221 $str = '';
310 if(isset($category) && !empty($category)){ 222 if(isset($category) && !empty($category)){
311 foreach ($category as $v){ 223 foreach ($category as $v){
312 - $info = $this->model->read(['pid'=>$v]);  
313 - if($info === false){  
314 - $str .= $v.',';  
315 - } 224 + $str .= $v.',';
316 } 225 }
317 } 226 }
318 - return ','.$str; 227 + return !empty($str) ? ','.$str : '';
319 } 228 }
320 229
321 /** 230 /**
@@ -263,6 +263,7 @@ Route::middleware(['aloginauth'])->group(function () { @@ -263,6 +263,7 @@ Route::middleware(['aloginauth'])->group(function () {
263 Route::prefix('create_keyword')->group(function () { 263 Route::prefix('create_keyword')->group(function () {
264 Route::any('/', [Aside\Optimize\CreateKeywordController::class, 'lists'])->name('admin.create_keywords_lists');//创建关键字获取语种+前后缀 264 Route::any('/', [Aside\Optimize\CreateKeywordController::class, 'lists'])->name('admin.create_keywords_lists');//创建关键字获取语种+前后缀
265 Route::any('/save', [Aside\Optimize\CreateKeywordController::class, 'save'])->name('admin.create_keywords_save');//保存关键字获取语种+前后缀 265 Route::any('/save', [Aside\Optimize\CreateKeywordController::class, 'save'])->name('admin.create_keywords_save');//保存关键字获取语种+前后缀
  266 + Route::any('/createKeyword', [Aside\Optimize\CreateKeywordController::class, 'createKeyword'])->name('admin.create_keywords_createKeyword');//保存关键字获取语种+前后缀
266 }); 267 });
267 268
268 269