作者 lyh

gx关键字

... ... @@ -257,4 +257,5 @@ class KeywordController extends BaseController
$id = $keywordPageModel->addReturnId($this->param);
$this->response('success',Code::SUCCESS,['id'=>$id]);
}
}
... ...
... ... @@ -42,6 +42,9 @@ 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'] ?? [];
}
return $this->success($info);
}
... ... @@ -82,6 +85,9 @@ 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);
... ... @@ -298,4 +304,51 @@ class KeywordLogic extends BaseLogic
}
return $this->success();
}
/**
* @remark :根据关键字获取产品
* @name :getProduct
* @author :lyh
* @method :post
* @time :2024/11/28 9:26
*/
public function getProduct($keyword_id){
$data_video_type_arr = $data_type_arr = [];
$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']);
}
return $this->success(['product'=>$productList,'video_product'=>$productVideoList]);
}
/**
* @remark :对应删除关联关系
* @name :delRelated
* @author :lyh
* @method :post
* @time :2024/11/28 9:46
*/
public function delRelated($product_id,$keyword_arr = [],$keyword_video_arr = []){
$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]);
}
}
... ...
... ... @@ -296,4 +296,5 @@ class Base extends Model
$data = $this->filterRequestData($data);
return $this->formatQuery($data)->pluck($filed)->toArray();
}
}
... ...