作者 lyh

gx关键词关联关系

... ... @@ -258,4 +258,22 @@ class KeywordController extends BaseController
$this->response('success',Code::SUCCESS,['id'=>$id]);
}
/**
* @remark :删除关联关系
* @name :delRelated
* @author :lyh
* @method :post
* @time :2024/11/28 10:30
*/
public function delRelated(KeywordLogic $logic){
$this->request->validate([
'keyword_id'=>'required',
'product_id'=>'required',
],[
'keyword_id.required' => '关键词id不能为空',
'product_id.required' => '产品id不为空',
]);
$logic->delRelated($this->param['keyword'],$this->param['product_id']);
$this->response('success');
}
}
... ...
... ... @@ -42,9 +42,7 @@ class KeywordLogic extends BaseLogic
if($info !== false){
$info['url'] = $this->user['domain'] . $info['route'];
$info['related_news_info'] = News::whereIn('id', $info['related_news_ids'])->select(['id', 'name'])->get();
$product = $this->getProduct($info['id']);
$info['product_list'] = $product['product'] ?? [];
$info['product_video_list'] = $product['video_product'] ?? [];
$info['product_list'] = $this->getProduct($info['id']);
}
return $this->success($info);
}
... ... @@ -85,9 +83,6 @@ class KeywordLogic extends BaseLogic
$route = RouteMap::setRoute($this->param['title'], RouteMap::SOURCE_PRODUCT_KEYWORD, $id, $this->user['project_id']);
$this->model->edit(['route'=>$route],['id'=>$id]);
$data = ['id'=>$id];
if(isset($this->param['keyword_arr']) && isset($this->param['keyword_video_arr'])){
$this->delRelated($id,$this->param['keyword_arr'],$this->param['keyword_video_arr']);
}
}
Common::del_user_cache('product_keyword',$this->user['project_id']);
$this->addUpdateNotify(RouteMap::SOURCE_PRODUCT_KEYWORD,$route);
... ... @@ -313,27 +308,14 @@ class KeywordLogic extends BaseLogic
* @time :2024/11/28 9:26
*/
public function getProduct($keyword_id){
$data_video_type_arr = $data_type_arr = [];
$productList = [];
$keywordRelatedModel = new KeywordRelated();
$keywordRelateList = $keywordRelatedModel->list(['keyword_id'=>$keyword_id],'id',['id','product_id','type']);
if(!empty($keywordRelateList)){
foreach ($keywordRelateList as $val){
if($val['type'] == 1){
$data_type_arr[] = $val['product_id'];
}else{
$data_video_type_arr[] = $val['product_id'];
}
}
}
$productVideoList = $productList = [];
$productModel = new Product();
if(!empty($data_type_arr)){
$productList = $productModel->list(['id'=>['in',$data_type_arr]],'id',['id','title']);
}
if(!empty($data_video_type_arr)){
$productVideoList = $productModel->list(['id'=>['in',$data_video_type_arr]],'id',['id','title']);
$productIdArr = $keywordRelatedModel->selectField(['keyword_id'=>$keyword_id],'product_id');
if(!empty($productIdArr)){
$productModel = new Product();
$productList = $productModel->list(['id'=>['in',$productIdArr]],['id','title']);
}
return $this->success(['product'=>$productList,'video_product'=>$productVideoList]);
return $this->success($productList);
}
/**
... ... @@ -343,12 +325,15 @@ class KeywordLogic extends BaseLogic
* @method :post
* @time :2024/11/28 9:46
*/
public function delRelated($product_id,$keyword_arr = [],$keyword_video_arr = []){
public function delRelated($keyword_id,$product_id){
$productModel = new Product();
$keyword_str = !empty($keyword_arr) ? ','.implode(',',$keyword_arr).',' : '';
KeywordRelated::saveRelated($product_id,$keyword_arr);
KeywordRelated::saveRelated($product_id,$keyword_video_arr,2);
$keyword_video_str = !empty($keyword_video_arr) ? ','.implode(',',$keyword_arr).',' : '';
$productModel->edit(['keyword_id'=>$keyword_str,'keyword_video_id'=>$keyword_video_str],['id'=>$product_id]);
$productModel->where('id', $product_id)
->update(['keyword_id' => DB::raw("REPLACE(keyword_id, ',$keyword_id,' , ',')"),'keyword_video_id' => DB::raw("REPLACE(keyword_video_id, ',$keyword_id,' , ',')")]);
$productModel->where('id', $product_id)->where('keyword_id',',')->orWhere('keyword_video_id',',')
->update(['keyword_id' => DB::raw("REPLACE(keyword_id, ',' , '')"),'keyword_video_id' => DB::raw("REPLACE(keyword_video_id, ',' , '')")]);
$keywordRelatedModel = new KeywordRelated();
$keywordRelatedModel->del(['product_id'=>$product_id,'keyword_id'=>$keyword_id]);
return $this->success();
}
}
... ...
... ... @@ -281,6 +281,7 @@ Route::middleware(['bloginauth'])->group(function () {
Route::post('keyword/batchAdd', [\App\Http\Controllers\Bside\Product\KeywordController::class, 'batchAdd'])->name('product_keyword_batchAdd');
Route::post('keyword/batchDel', [\App\Http\Controllers\Bside\Product\KeywordController::class, 'batchDel'])->name('product_keyword_batchDel');
Route::any('keyword/delete', [\App\Http\Controllers\Bside\Product\KeywordController::class, 'delete'])->name('product_keyword_delete');
Route::any('keyword/delRelated', [\App\Http\Controllers\Bside\Product\KeywordController::class, 'delRelated'])->name('product_keyword_delRelated');
Route::any('keyword/batchUpdateKeyword', [\App\Http\Controllers\Bside\Product\KeywordController::class, 'batchUpdateKeyword'])->name('product_keyword_batchUpdateKeyword');
Route::any('keyword/batchKeywordIsVideo', [\App\Http\Controllers\Bside\Product\KeywordController::class, 'batchKeywordIsVideo'])->name('product_keyword_batchKeywordIsVideo');
Route::any('keyword/batchKeywordFiled', [\App\Http\Controllers\Bside\Product\KeywordController::class, 'batchKeywordFiled'])->name('product_keyword_batchKeywordFiled');
... ...