作者 赵彬吉

update

@@ -3,14 +3,14 @@ @@ -3,14 +3,14 @@
3 namespace App\Console\Commands\Tdk; 3 namespace App\Console\Commands\Tdk;
4 4
5 5
6 -use App\Http\Controllers\Bside\News\NewsController;  
7 -use App\Models\News\News;  
8 -use App\Models\News\NewsCategory; 6 +use App\Helper\Arr;
  7 +use App\Models\Product\Keyword;
9 use App\Models\Project\Project; 8 use App\Models\Project\Project;
10 use App\Models\Project\ProjectUpdateTdk; 9 use App\Models\Project\ProjectUpdateTdk;
11 use App\Services\ProjectServer; 10 use App\Services\ProjectServer;
12 use Illuminate\Console\Command; 11 use Illuminate\Console\Command;
13 use Illuminate\Support\Facades\DB; 12 use Illuminate\Support\Facades\DB;
  13 +use Illuminate\Support\Str;
14 14
15 /** 15 /**
16 * 重跑异常tdk 16 * 重跑异常tdk
@@ -63,25 +63,57 @@ class RerunSeoTdk extends Command @@ -63,25 +63,57 @@ class RerunSeoTdk extends Command
63 } 63 }
64 64
65 /** 65 /**
66 - * 判断异常 66 + * 判断seo_title后缀重复
67 * @author zbj 67 * @author zbj
68 * @date 2025/4/12 68 * @date 2025/4/12
69 */ 69 */
70 public function judgeAnomalies($project_id){ 70 public function judgeAnomalies($project_id){
71 //获取当前项目的所有分类 71 //获取当前项目的所有分类
72 - $categories = NewsCategory::pluck('name', 'id')->toArray(); 72 + $seo_titles = Keyword::pluck('seo_title', 'id')->toArray();
73 //新闻 seo_keyword 和 分类名一样的 73 //新闻 seo_keyword 和 分类名一样的
74 - $news_ids = [];  
75 - foreach ($categories as $category){  
76 - $ids = News::WhereRaw("FIND_IN_SET('{$category}', `seo_keywords`)")->pluck('id')->toArray();  
77 - $news_ids = array_unique(array_merge($news_ids, $ids)); 74 + $ids = [];
  75 + //Suppliers, Manufacturer
  76 + foreach ($seo_titles as $id=>$seo_title){
  77 + if(!Str::contains($seo_title, ', ')){
  78 + continue;
  79 + }
  80 + $arr = explode(', ', $seo_title);
  81 + $suffix1 = $arr[1];
  82 + $arr = explode(' ', $arr[0]);
  83 + $suffix2 = Arr::last($arr);
  84 + if(Str::singular($suffix1) == Str::singular($suffix2)){
  85 + $ids[] = $id;
  86 + }
78 } 87 }
79 88
80 - $count = count($news_ids); 89 + $count = count($ids);
81 if($count){ 90 if($count){
82 echo "项目{$project_id},共{$count}条需要重跑"; 91 echo "项目{$project_id},共{$count}条需要重跑";
83 - News::whereIn('id', $news_ids)->update(['seo_keywords' => '']); 92 + Keyword::whereIn('id', $ids)->update(['seo_title' => '']);
84 ProjectUpdateTdk::add_task($project_id); 93 ProjectUpdateTdk::add_task($project_id);
85 } 94 }
86 } 95 }
  96 +
  97 +// /**
  98 +// * 判断异常
  99 +// * @author zbj
  100 +// * @date 2025/4/12
  101 +// */
  102 +// public function judgeAnomalies($project_id){
  103 +// //获取当前项目的所有分类
  104 +// $categories = NewsCategory::pluck('name', 'id')->toArray();
  105 +// //新闻 seo_keyword 和 分类名一样的
  106 +// $news_ids = [];
  107 +// foreach ($categories as $category){
  108 +// $ids = News::WhereRaw("FIND_IN_SET('{$category}', `seo_keywords`)")->pluck('id')->toArray();
  109 +// $news_ids = array_unique(array_merge($news_ids, $ids));
  110 +// }
  111 +//
  112 +// $count = count($news_ids);
  113 +// if($count){
  114 +// echo "项目{$project_id},共{$count}条需要重跑";
  115 +// News::whereIn('id', $news_ids)->update(['seo_keywords' => '']);
  116 +// ProjectUpdateTdk::add_task($project_id);
  117 +// }
  118 +// }
87 } 119 }