作者 李宇航

合并分支 'master-server' 到 'master'

Master server



查看合并请求 !913
@@ -257,4 +257,23 @@ class KeywordController extends BaseController @@ -257,4 +257,23 @@ class KeywordController extends BaseController
257 $id = $keywordPageModel->addReturnId($this->param); 257 $id = $keywordPageModel->addReturnId($this->param);
258 $this->response('success',Code::SUCCESS,['id'=>$id]); 258 $this->response('success',Code::SUCCESS,['id'=>$id]);
259 } 259 }
  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 + }
260 } 279 }
@@ -42,6 +42,7 @@ class KeywordLogic extends BaseLogic @@ -42,6 +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 + $info['product_list'] = $this->getProduct($info['id']);
45 } 46 }
46 return $this->success($info); 47 return $this->success($info);
47 } 48 }
@@ -298,4 +299,41 @@ class KeywordLogic extends BaseLogic @@ -298,4 +299,41 @@ class KeywordLogic extends BaseLogic
298 } 299 }
299 return $this->success(); 300 return $this->success();
300 } 301 }
  302 +
  303 + /**
  304 + * @remark :根据关键字获取产品
  305 + * @name :getProduct
  306 + * @author :lyh
  307 + * @method :post
  308 + * @time :2024/11/28 9:26
  309 + */
  310 + public function getProduct($keyword_id){
  311 + $productList = [];
  312 + $keywordRelatedModel = new KeywordRelated();
  313 + $productIdArr = $keywordRelatedModel->selectField(['keyword_id'=>$keyword_id],'product_id');
  314 + if(!empty($productIdArr)){
  315 + $productModel = new Product();
  316 + $productList = $productModel->list(['id'=>['in',$productIdArr]],['id','title']);
  317 + }
  318 + return $this->success($productList);
  319 + }
  320 +
  321 + /**
  322 + * @remark :对应删除关联关系
  323 + * @name :delRelated
  324 + * @author :lyh
  325 + * @method :post
  326 + * @time :2024/11/28 9:46
  327 + */
  328 + public function delRelated($keyword_id,$product_id){
  329 + $productModel = new Product();
  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();
  337 + }
  338 +
301 } 339 }
@@ -43,6 +43,7 @@ class ProductLogic extends BaseLogic @@ -43,6 +43,7 @@ class ProductLogic extends BaseLogic
43 $extend = $this->handleExtent(); 43 $extend = $this->handleExtent();
44 //单独处理分类 44 //单独处理分类
45 $category_ids = $this->handleCategory(); 45 $category_ids = $this->handleCategory();
  46 + $keyword_arr = $this->param['keyword_id'] ?? [];
46 //处理其他字段 47 //处理其他字段
47 $this->param = $this->handleSaveParam($this->param); 48 $this->param = $this->handleSaveParam($this->param);
48 try { 49 try {
@@ -66,7 +67,7 @@ class ProductLogic extends BaseLogic @@ -66,7 +67,7 @@ class ProductLogic extends BaseLogic
66 } 67 }
67 //产品分类关联 68 //产品分类关联
68 CategoryRelated::saveRelated($id, $category_ids); 69 CategoryRelated::saveRelated($id, $category_ids);
69 - KeywordRelated::saveRelated($id,$category_ids); 70 + KeywordRelated::saveRelated($id,$keyword_arr);
70 //更新产品新描述 71 //更新产品新描述
71 $detailLogic = new DetailLogic(); 72 $detailLogic = new DetailLogic();
72 $detailLogic->saveDetail($id,$this->param['data'] ?? []); 73 $detailLogic->saveDetail($id,$this->param['data'] ?? []);
@@ -296,4 +296,5 @@ class Base extends Model @@ -296,4 +296,5 @@ class Base extends Model
296 $data = $this->filterRequestData($data); 296 $data = $this->filterRequestData($data);
297 return $this->formatQuery($data)->pluck($filed)->toArray(); 297 return $this->formatQuery($data)->pluck($filed)->toArray();
298 } 298 }
  299 +
299 } 300 }
@@ -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');