作者 lyh

gx关键词关联关系

@@ -258,4 +258,22 @@ class KeywordController extends BaseController @@ -258,4 +258,22 @@ class KeywordController extends BaseController
258 $this->response('success',Code::SUCCESS,['id'=>$id]); 258 $this->response('success',Code::SUCCESS,['id'=>$id]);
259 } 259 }
260 260
  261 + /**
  262 + * @remark :删除关联关系
  263 + * @name :delRelated
  264 + * @author :lyh
  265 + * @method :post
  266 + * @time :2024/11/28 10:30
  267 + */
  268 + public function delRelated(KeywordLogic $logic){
  269 + $this->request->validate([
  270 + 'keyword_id'=>'required',
  271 + 'product_id'=>'required',
  272 + ],[
  273 + 'keyword_id.required' => '关键词id不能为空',
  274 + 'product_id.required' => '产品id不为空',
  275 + ]);
  276 + $logic->delRelated($this->param['keyword'],$this->param['product_id']);
  277 + $this->response('success');
  278 + }
261 } 279 }
@@ -42,9 +42,7 @@ class KeywordLogic extends BaseLogic @@ -42,9 +42,7 @@ class KeywordLogic extends BaseLogic
42 if($info !== false){ 42 if($info !== false){
43 $info['url'] = $this->user['domain'] . $info['route']; 43 $info['url'] = $this->user['domain'] . $info['route'];
44 $info['related_news_info'] = News::whereIn('id', $info['related_news_ids'])->select(['id', 'name'])->get(); 44 $info['related_news_info'] = News::whereIn('id', $info['related_news_ids'])->select(['id', 'name'])->get();
45 - $product = $this->getProduct($info['id']);  
46 - $info['product_list'] = $product['product'] ?? [];  
47 - $info['product_video_list'] = $product['video_product'] ?? []; 45 + $info['product_list'] = $this->getProduct($info['id']);
48 } 46 }
49 return $this->success($info); 47 return $this->success($info);
50 } 48 }
@@ -85,9 +83,6 @@ class KeywordLogic extends BaseLogic @@ -85,9 +83,6 @@ class KeywordLogic extends BaseLogic
85 $route = RouteMap::setRoute($this->param['title'], RouteMap::SOURCE_PRODUCT_KEYWORD, $id, $this->user['project_id']); 83 $route = RouteMap::setRoute($this->param['title'], RouteMap::SOURCE_PRODUCT_KEYWORD, $id, $this->user['project_id']);
86 $this->model->edit(['route'=>$route],['id'=>$id]); 84 $this->model->edit(['route'=>$route],['id'=>$id]);
87 $data = ['id'=>$id]; 85 $data = ['id'=>$id];
88 - if(isset($this->param['keyword_arr']) && isset($this->param['keyword_video_arr'])){  
89 - $this->delRelated($id,$this->param['keyword_arr'],$this->param['keyword_video_arr']);  
90 - }  
91 } 86 }
92 Common::del_user_cache('product_keyword',$this->user['project_id']); 87 Common::del_user_cache('product_keyword',$this->user['project_id']);
93 $this->addUpdateNotify(RouteMap::SOURCE_PRODUCT_KEYWORD,$route); 88 $this->addUpdateNotify(RouteMap::SOURCE_PRODUCT_KEYWORD,$route);
@@ -313,27 +308,14 @@ class KeywordLogic extends BaseLogic @@ -313,27 +308,14 @@ class KeywordLogic extends BaseLogic
313 * @time :2024/11/28 9:26 308 * @time :2024/11/28 9:26
314 */ 309 */
315 public function getProduct($keyword_id){ 310 public function getProduct($keyword_id){
316 - $data_video_type_arr = $data_type_arr = []; 311 + $productList = [];
317 $keywordRelatedModel = new KeywordRelated(); 312 $keywordRelatedModel = new KeywordRelated();
318 - $keywordRelateList = $keywordRelatedModel->list(['keyword_id'=>$keyword_id],'id',['id','product_id','type']);  
319 - if(!empty($keywordRelateList)){  
320 - foreach ($keywordRelateList as $val){  
321 - if($val['type'] == 1){  
322 - $data_type_arr[] = $val['product_id'];  
323 - }else{  
324 - $data_video_type_arr[] = $val['product_id'];  
325 - }  
326 - }  
327 - }  
328 - $productVideoList = $productList = []; 313 + $productIdArr = $keywordRelatedModel->selectField(['keyword_id'=>$keyword_id],'product_id');
  314 + if(!empty($productIdArr)){
329 $productModel = new Product(); 315 $productModel = new Product();
330 - if(!empty($data_type_arr)){  
331 - $productList = $productModel->list(['id'=>['in',$data_type_arr]],'id',['id','title']); 316 + $productList = $productModel->list(['id'=>['in',$productIdArr]],['id','title']);
332 } 317 }
333 - if(!empty($data_video_type_arr)){  
334 - $productVideoList = $productModel->list(['id'=>['in',$data_video_type_arr]],'id',['id','title']);  
335 - }  
336 - return $this->success(['product'=>$productList,'video_product'=>$productVideoList]); 318 + return $this->success($productList);
337 } 319 }
338 320
339 /** 321 /**
@@ -343,12 +325,15 @@ class KeywordLogic extends BaseLogic @@ -343,12 +325,15 @@ class KeywordLogic extends BaseLogic
343 * @method :post 325 * @method :post
344 * @time :2024/11/28 9:46 326 * @time :2024/11/28 9:46
345 */ 327 */
346 - public function delRelated($product_id,$keyword_arr = [],$keyword_video_arr = []){ 328 + public function delRelated($keyword_id,$product_id){
347 $productModel = new Product(); 329 $productModel = new Product();
348 - $keyword_str = !empty($keyword_arr) ? ','.implode(',',$keyword_arr).',' : '';  
349 - KeywordRelated::saveRelated($product_id,$keyword_arr);  
350 - KeywordRelated::saveRelated($product_id,$keyword_video_arr,2);  
351 - $keyword_video_str = !empty($keyword_video_arr) ? ','.implode(',',$keyword_arr).',' : '';  
352 - $productModel->edit(['keyword_id'=>$keyword_str,'keyword_video_id'=>$keyword_video_str],['id'=>$product_id]); 330 + $productModel->where('id', $product_id)
  331 + ->update(['keyword_id' => DB::raw("REPLACE(keyword_id, ',$keyword_id,' , ',')"),'keyword_video_id' => DB::raw("REPLACE(keyword_video_id, ',$keyword_id,' , ',')")]);
  332 + $productModel->where('id', $product_id)->where('keyword_id',',')->orWhere('keyword_video_id',',')
  333 + ->update(['keyword_id' => DB::raw("REPLACE(keyword_id, ',' , '')"),'keyword_video_id' => DB::raw("REPLACE(keyword_video_id, ',' , '')")]);
  334 + $keywordRelatedModel = new KeywordRelated();
  335 + $keywordRelatedModel->del(['product_id'=>$product_id,'keyword_id'=>$keyword_id]);
  336 + return $this->success();
353 } 337 }
  338 +
354 } 339 }
@@ -281,6 +281,7 @@ Route::middleware(['bloginauth'])->group(function () { @@ -281,6 +281,7 @@ Route::middleware(['bloginauth'])->group(function () {
281 Route::post('keyword/batchAdd', [\App\Http\Controllers\Bside\Product\KeywordController::class, 'batchAdd'])->name('product_keyword_batchAdd'); 281 Route::post('keyword/batchAdd', [\App\Http\Controllers\Bside\Product\KeywordController::class, 'batchAdd'])->name('product_keyword_batchAdd');
282 Route::post('keyword/batchDel', [\App\Http\Controllers\Bside\Product\KeywordController::class, 'batchDel'])->name('product_keyword_batchDel'); 282 Route::post('keyword/batchDel', [\App\Http\Controllers\Bside\Product\KeywordController::class, 'batchDel'])->name('product_keyword_batchDel');
283 Route::any('keyword/delete', [\App\Http\Controllers\Bside\Product\KeywordController::class, 'delete'])->name('product_keyword_delete'); 283 Route::any('keyword/delete', [\App\Http\Controllers\Bside\Product\KeywordController::class, 'delete'])->name('product_keyword_delete');
  284 + Route::any('keyword/delRelated', [\App\Http\Controllers\Bside\Product\KeywordController::class, 'delRelated'])->name('product_keyword_delRelated');
284 Route::any('keyword/batchUpdateKeyword', [\App\Http\Controllers\Bside\Product\KeywordController::class, 'batchUpdateKeyword'])->name('product_keyword_batchUpdateKeyword'); 285 Route::any('keyword/batchUpdateKeyword', [\App\Http\Controllers\Bside\Product\KeywordController::class, 'batchUpdateKeyword'])->name('product_keyword_batchUpdateKeyword');
285 Route::any('keyword/batchKeywordIsVideo', [\App\Http\Controllers\Bside\Product\KeywordController::class, 'batchKeywordIsVideo'])->name('product_keyword_batchKeywordIsVideo'); 286 Route::any('keyword/batchKeywordIsVideo', [\App\Http\Controllers\Bside\Product\KeywordController::class, 'batchKeywordIsVideo'])->name('product_keyword_batchKeywordIsVideo');
286 Route::any('keyword/batchKeywordFiled', [\App\Http\Controllers\Bside\Product\KeywordController::class, 'batchKeywordFiled'])->name('product_keyword_batchKeywordFiled'); 287 Route::any('keyword/batchKeywordFiled', [\App\Http\Controllers\Bside\Product\KeywordController::class, 'batchKeywordFiled'])->name('product_keyword_batchKeywordFiled');