RerunSeoTdk.php
4.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
<?php
namespace App\Console\Commands\Tdk;
use App\Helper\Arr;
use App\Models\Product\Keyword;
use App\Models\Project\Project;
use App\Models\Project\ProjectUpdateTdk;
use App\Services\ProjectServer;
use App\Utils\LogUtils;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Str;
/**
* 重跑异常tdk
* Class RerunSeoTdk
* @package App\Console\Commands\Tdk
* @author zbj
* @date 2025/4/12
*/
class RerunSeoTdk extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'rerun_seo_tdk';
/**
* The console command description.
*
* @var string
*/
protected $description = '重跑项目sdk';
/**
* Create a new command instance.
*
* @return void
*/
public function __construct()
{
parent::__construct();
}
/**
* @return bool
*/
public function handle()
{
$project_ids = Project::where('type', Project::TYPE_TWO)->pluck('id')->toArray();
foreach ($project_ids as $project_id){
try {
ProjectServer::useProject($project_id);
$this->judgeAnomalies($project_id);
DB::disconnect('custom_mysql');
}catch (\Exception $e){
dump($e->getMessage());
}
}
}
/**
* 判断seo_title 前缀有wholesale或cheap的词,后缀也有 manufacturer,factory,exporter,company
* @author zbj
* @date 2025/4/12
*/
public function judgeAnomalies($project_id){
//获取当前项目的所有分类
$seo_titles = Keyword::pluck('seo_title', 'id')->toArray();
//新闻 seo_keyword 和 分类名一样的
$ids = [];
foreach ($seo_titles as $id=>$seo_title){
if(!Str::startsWith(strtolower($seo_title), ['wholesale', 'cheap'])){
continue;
}
if(!Str::contains(strtolower($seo_title), ['manufacturer', 'manufacturers', 'factory', 'factories', 'exporter', 'exporters', 'company', 'companies', 'supplier', 'suppliers'])){
continue;
}
dump($seo_title);exit;
$ids[] = $id;
}
$count = count($ids);
if($count){
echo "项目{$project_id},共{$count}条需要重跑";
LogUtils::info("RerunSeoTdk: 项目{$project_id},共{$count}条需要重跑");
Keyword::whereIn('id', $ids)->update(['seo_title' => '']);
ProjectUpdateTdk::add_task($project_id);
}
}
// /**
// * 判断seo_title后缀重复
// * @author zbj
// * @date 2025/4/12
// */
// public function judgeAnomalies($project_id){
// //获取当前项目的所有分类
// $seo_titles = Keyword::pluck('seo_title', 'id')->toArray();
// //新闻 seo_keyword 和 分类名一样的
// $ids = [];
// //Suppliers, Manufacturer
// foreach ($seo_titles as $id=>$seo_title){
// if(!Str::contains($seo_title, ', ')){
// continue;
// }
// $arr = explode(', ', $seo_title);
// $suffix1 = $arr[1];
// $arr = explode(' ', $arr[0]);
// $suffix2 = Arr::last($arr);
// if(Str::singular($suffix1) == Str::singular($suffix2)){
// $ids[] = $id;
// }
// }
//
// $count = count($ids);
// if($count){
// echo "项目{$project_id},共{$count}条需要重跑";
// Keyword::whereIn('id', $ids)->update(['seo_title' => '']);
// ProjectUpdateTdk::add_task($project_id);
// }
// }
// /**
// * 判断异常
// * @author zbj
// * @date 2025/4/12
// */
// public function judgeAnomalies($project_id){
// //获取当前项目的所有分类
// $categories = NewsCategory::pluck('name', 'id')->toArray();
// //新闻 seo_keyword 和 分类名一样的
// $news_ids = [];
// foreach ($categories as $category){
// $ids = News::WhereRaw("FIND_IN_SET('{$category}', `seo_keywords`)")->pluck('id')->toArray();
// $news_ids = array_unique(array_merge($news_ids, $ids));
// }
//
// $count = count($news_ids);
// if($count){
// echo "项目{$project_id},共{$count}条需要重跑";
// News::whereIn('id', $news_ids)->update(['seo_keywords' => '']);
// ProjectUpdateTdk::add_task($project_id);
// }
// }
}