作者 刘锟

Merge remote-tracking branch 'origin/master' into akun

@@ -67,7 +67,30 @@ class UpdateRoute extends Command @@ -67,7 +67,30 @@ class UpdateRoute extends Command
67 */ 67 */
68 public function handle() 68 public function handle()
69 { 69 {
70 - return $this->settingSeo(); 70 + return $this->getNullRoute();
  71 + }
  72 +
  73 + /**
  74 + * @remark :查询 路由为空的关键词项目id
  75 + * @name :getNullRoute
  76 + * @author :lyh
  77 + * @method :post
  78 + * @time :2025/4/21 11:52
  79 + */
  80 + public function getNullRoute(){
  81 + $projectModel = new Project();
  82 + $lists = $projectModel->list(['delete_status' => 0,'extend_type'=>0,'type'=>['in',[1,2,3,4]]], 'id', ['id']);
  83 + foreach ($lists as $val) {
  84 + echo date('Y-m-d H:i:s') . '开始--项目的id:'. $val['id'] . PHP_EOL;
  85 + ProjectServer::useProject($val['id']);
  86 + $keywordModel = new Keyword();
  87 + $info = $keywordModel->read(['route'=>'']);
  88 + if($info !== false){
  89 + echo '存在路由为空--项目id:'.$val['id'].PHP_EOL;
  90 + }
  91 + DB::disconnect('custom_mysql');
  92 + }
  93 + return true;
71 } 94 }
72 95
73 public function keyword_actions(){ 96 public function keyword_actions(){
@@ -68,6 +68,7 @@ class RecommendedSuppliers extends Command @@ -68,6 +68,7 @@ class RecommendedSuppliers extends Command
68 if(!empty($title)){ 68 if(!empty($title)){
69 $this->savePurchaser($v['project_id'],$title); 69 $this->savePurchaser($v['project_id'],$title);
70 }else{ 70 }else{
  71 + $this->deployBuildModel->edit(['is_supplier'=>0],['project_id'=>$v['project_id']]);
71 echo '关键词已取完'.PHP_EOL; 72 echo '关键词已取完'.PHP_EOL;
72 } 73 }
73 DB::disconnect('custom_mysql'); 74 DB::disconnect('custom_mysql');
@@ -152,7 +153,7 @@ class RecommendedSuppliers extends Command @@ -152,7 +153,7 @@ class RecommendedSuppliers extends Command
152 ]; 153 ];
153 ksort($data); 154 ksort($data);
154 $token = 'company_list+'.date('Y-m-d').'+'.http_build_query($data); 155 $token = 'company_list+'.date('Y-m-d').'+'.http_build_query($data);
155 -// echo date('Y-m-d H:i:s') . '加密token:'.md5($token) . PHP_EOL; 156 + $keyword = rtrim($keyword, "\r");
156 $param = [ 157 $param = [
157 'prod_desc'=>$keyword, 158 'prod_desc'=>$keyword,
158 'token'=>md5($token), 159 'token'=>md5($token),
@@ -161,7 +162,7 @@ class RecommendedSuppliers extends Command @@ -161,7 +162,7 @@ class RecommendedSuppliers extends Command
161 $res = http_post($url,json_encode($param)); 162 $res = http_post($url,json_encode($param));
162 echo '请求返回状态'. ($res['code']?? '').PHP_EOL; 163 echo '请求返回状态'. ($res['code']?? '').PHP_EOL;
163 // echo date('Y-m-d H:i:s') . json_encode($res) . PHP_EOL; 164 // echo date('Y-m-d H:i:s') . json_encode($res) . PHP_EOL;
164 - if(!empty($res) && isset($res['code']) && $res['code'] == 200 && !empty($res['data'])){ 165 + if(isset($res['code']) && $res['code'] == 200){
165 //保存多条数据 166 //保存多条数据
166 $saveData = [ 167 $saveData = [
167 'project_id'=>$project_id, 168 'project_id'=>$project_id,
@@ -170,10 +171,11 @@ class RecommendedSuppliers extends Command @@ -170,10 +171,11 @@ class RecommendedSuppliers extends Command
170 ]; 171 ];
171 $purchaserModel = new Purchaser(); 172 $purchaserModel = new Purchaser();
172 $purchaserModel->add($saveData); 173 $purchaserModel->add($saveData);
173 - $this->savePurchaserInfo($project_id,$keyword,$res['data']); 174 + if(!empty($res['data'])){
  175 + $this->savePurchaserInfo($project_id,$keyword,$res['data']);
  176 + }
174 }else{ 177 }else{
175 - $title = $this->getKeywords($project_id);  
176 - $this->savePurchaser($project_id,$title); 178 + echo '未正常返回数据,跳过项目'.PHP_EOL;
177 } 179 }
178 return true; 180 return true;
179 } 181 }
@@ -188,11 +190,11 @@ class RecommendedSuppliers extends Command @@ -188,11 +190,11 @@ class RecommendedSuppliers extends Command
188 public function getKeywords($project_id){ 190 public function getKeywords($project_id){
189 $keywordModel = new Keyword(); 191 $keywordModel = new Keyword();
190 $keyword_array = $this->getPurchaserList($project_id); 192 $keyword_array = $this->getPurchaserList($project_id);
191 - $info = $keywordModel->read(['title'=>['not in',$keyword_array]],'title');  
192 - if($info === false){ 193 + $title = $keywordModel->where('title', 'not in', $keyword_array)->orderRaw('RAND()')->limit(1)->value('title'); // 只返回 title 字段
  194 + if(empty($title)){
193 return ''; 195 return '';
194 } 196 }
195 - return $info['title'] ?? ''; 197 + return $title;
196 } 198 }
197 199
198 /** 200 /**
@@ -5,10 +5,13 @@ namespace App\Console\Commands\Tdk; @@ -5,10 +5,13 @@ namespace App\Console\Commands\Tdk;
5 5
6 use App\Helper\Arr; 6 use App\Helper\Arr;
7 use App\Models\Product\Keyword; 7 use App\Models\Product\Keyword;
  8 +use App\Models\Project\KeywordPrefix;
8 use App\Models\Project\Project; 9 use App\Models\Project\Project;
9 use App\Models\Project\ProjectUpdateTdk; 10 use App\Models\Project\ProjectUpdateTdk;
10 use App\Services\ProjectServer; 11 use App\Services\ProjectServer;
  12 +use App\Utils\LogUtils;
11 use Illuminate\Console\Command; 13 use Illuminate\Console\Command;
  14 +use Illuminate\Support\Facades\Cache;
12 use Illuminate\Support\Facades\DB; 15 use Illuminate\Support\Facades\DB;
13 use Illuminate\Support\Str; 16 use Illuminate\Support\Str;
14 17
@@ -63,38 +66,80 @@ class RerunSeoTdk extends Command @@ -63,38 +66,80 @@ class RerunSeoTdk extends Command
63 } 66 }
64 67
65 /** 68 /**
66 - * 判断seo_title后缀重复 69 + * 判断seo_title 前缀有wholesale或cheap或buy的词,后缀也有 manufacturer,factory,exporter,company
  70 + * 判断关键词最后一个词是前缀的词,前后缀都不拼
67 * @author zbj 71 * @author zbj
68 * @date 2025/4/12 72 * @date 2025/4/12
69 */ 73 */
70 public function judgeAnomalies($project_id){ 74 public function judgeAnomalies($project_id){
  75 + dump($project_id);
  76 + $all_prefixes = $this->getAllPrefix(1, $project_id);
  77 + $all_prefixes = array_map('strtolower', $all_prefixes);
  78 +
71 //获取当前项目的所有分类 79 //获取当前项目的所有分类
72 - $seo_titles = Keyword::pluck('seo_title', 'id')->toArray(); 80 + $list = Keyword::select('title', 'seo_title', 'id')->get()->toArray();
73 //新闻 seo_keyword 和 分类名一样的 81 //新闻 seo_keyword 和 分类名一样的
74 $ids = []; 82 $ids = [];
75 - //Suppliers, Manufacturer  
76 - foreach ($seo_titles as $id=>$seo_title){  
77 - if(!Str::contains($seo_title, ', ')){ 83 + foreach ($list as $k=>$item){
  84 + $seo_title = $item['seo_title'];
  85 + $id = $item['id'];
  86 + $title = $item['title'];
  87 + if(Str::startsWith(strtolower($seo_title), ['wholesale', 'cheap', 'buy']) && Str::contains(strtolower($seo_title), ['manufacturer', 'manufacturers', 'factory', 'factories', 'exporter', 'exporters', 'company', 'companies', 'supplier', 'suppliers'])){
  88 + $ids[] = $id;
  89 + dump($seo_title);
78 continue; 90 continue;
79 } 91 }
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)){ 92 + $topic_words = explode(' ', strtolower($title));
  93 + //关键词最后一个是前缀 且 有前后缀
  94 + if(in_array(Arr::last($topic_words), $all_prefixes) && $title != $seo_title){
85 $ids[] = $id; 95 $ids[] = $id;
  96 + dump($seo_title);
  97 + continue;
86 } 98 }
87 } 99 }
88 100
89 $count = count($ids); 101 $count = count($ids);
90 if($count){ 102 if($count){
91 echo "项目{$project_id},共{$count}条需要重跑"; 103 echo "项目{$project_id},共{$count}条需要重跑";
  104 + LogUtils::info("RerunSeoTdk: 项目{$project_id},共{$count}条需要重跑");
92 Keyword::whereIn('id', $ids)->update(['seo_title' => '']); 105 Keyword::whereIn('id', $ids)->update(['seo_title' => '']);
93 ProjectUpdateTdk::add_task($project_id); 106 ProjectUpdateTdk::add_task($project_id);
94 } 107 }
95 } 108 }
96 109
97 // /** 110 // /**
  111 +// * 判断seo_title后缀重复
  112 +// * @author zbj
  113 +// * @date 2025/4/12
  114 +// */
  115 +// public function judgeAnomalies($project_id){
  116 +// //获取当前项目的所有分类
  117 +// $seo_titles = Keyword::pluck('seo_title', 'id')->toArray();
  118 +// //新闻 seo_keyword 和 分类名一样的
  119 +// $ids = [];
  120 +// //Suppliers, Manufacturer
  121 +// foreach ($seo_titles as $id=>$seo_title){
  122 +// if(!Str::contains($seo_title, ', ')){
  123 +// continue;
  124 +// }
  125 +// $arr = explode(', ', $seo_title);
  126 +// $suffix1 = $arr[1];
  127 +// $arr = explode(' ', $arr[0]);
  128 +// $suffix2 = Arr::last($arr);
  129 +// if(Str::singular($suffix1) == Str::singular($suffix2)){
  130 +// $ids[] = $id;
  131 +// }
  132 +// }
  133 +//
  134 +// $count = count($ids);
  135 +// if($count){
  136 +// echo "项目{$project_id},共{$count}条需要重跑";
  137 +// Keyword::whereIn('id', $ids)->update(['seo_title' => '']);
  138 +// ProjectUpdateTdk::add_task($project_id);
  139 +// }
  140 +// }
  141 +
  142 +// /**
98 // * 判断异常 143 // * 判断异常
99 // * @author zbj 144 // * @author zbj
100 // * @date 2025/4/12 145 // * @date 2025/4/12
@@ -116,4 +161,14 @@ class RerunSeoTdk extends Command @@ -116,4 +161,14 @@ class RerunSeoTdk extends Command
116 // ProjectUpdateTdk::add_task($project_id); 161 // ProjectUpdateTdk::add_task($project_id);
117 // } 162 // }
118 // } 163 // }
  164 +
  165 + public function getAllPrefix($type, int $project_id = 0){
  166 + $cache_key = 'AllPrefix_' . $type . '_' . $project_id;
  167 + $data = Cache::get($cache_key);
  168 + if(!$data){
  169 + $data = KeywordPrefix::whereIn('project_id', [0, $project_id])->where('type', $type)->pluck('keyword')->toArray();
  170 + Cache::put($cache_key, $data, 600);
  171 + }
  172 + return $data;
  173 + }
119 } 174 }
@@ -372,10 +372,10 @@ class UpdateSeoTdk extends Command @@ -372,10 +372,10 @@ class UpdateSeoTdk extends Command
372 } else if ($table == 'gl_product_keyword' && $field == 'seo_title') { 372 } else if ($table == 'gl_product_keyword' && $field == 'seo_title') {
373 # TODO 聚合页seo title 特殊处理 前缀_1 . 关键词 . 后缀_2 373 # TODO 聚合页seo title 特殊处理 前缀_1 . 关键词 . 后缀_2
374 $seo_title = $v[$this->topic_fields[$table]];; 374 $seo_title = $v[$this->topic_fields[$table]];;
375 - //只有推广项目 且未标记特殊前后缀 才加 前后缀  
376 - if($project->type == Project::TYPE_TWO && !in_array(8, explode(',', $project->deploy_optimize->special))) { 375 + //只有推广项目 才加 前后缀
  376 + if($project->type == Project::TYPE_TWO) {
377 $prefix = $this->getPrefixKeyword($project_id, 'prefix', 1, $seo_title); 377 $prefix = $this->getPrefixKeyword($project_id, 'prefix', 1, $seo_title);
378 - $suffix = $this->getPrefixKeyword($project_id, 'suffix', 2, $seo_title); 378 + $suffix = $this->getPrefixKeyword($project_id, 'suffix', 2, trim($prefix . ' ' . $seo_title));
379 if(Str::startsWith($suffix, ', ')){ 379 if(Str::startsWith($suffix, ', ')){
380 $seo_title = $prefix . ' ' . $seo_title . $suffix; 380 $seo_title = $prefix . ' ' . $seo_title . $suffix;
381 }else{ 381 }else{
@@ -567,18 +567,31 @@ class UpdateSeoTdk extends Command @@ -567,18 +567,31 @@ class UpdateSeoTdk extends Command
567 } 567 }
568 568
569 //前后缀(包括自定义前后缀)如果已经存在,就不在拼接当前类型 后缀只包含了一个,要再拼一个(需去重) 569 //前后缀(包括自定义前后缀)如果已经存在,就不在拼接当前类型 后缀只包含了一个,要再拼一个(需去重)
570 - $all_prefixes = $this->getAllPrefix($type == 'prefix' ? 1 : 2, $project_id); 570 + $all_prefixes = $this->getAllPrefix(1, $project_id);
571 $all_prefixes = array_map('strtolower', $all_prefixes); 571 $all_prefixes = array_map('strtolower', $all_prefixes);
572 572
  573 + $all_suffixes = $this->getAllPrefix(2, $project_id);
  574 + $all_suffixes = array_map('strtolower', $all_suffixes);
  575 +
573 //in,for,with,to,near,from 这些介词 只拼前缀,不拼后缀 576 //in,for,with,to,near,from 这些介词 只拼前缀,不拼后缀
574 $preposition = ['in', 'for', 'with', 'to', 'near','from']; 577 $preposition = ['in', 'for', 'with', 'to', 'near','from'];
575 578
576 //标题拆成词 579 //标题拆成词
577 $topic_words = explode(' ', strtolower($topic)); 580 $topic_words = explode(' ', strtolower($topic));
  581 +
  582 + //关键词最后一个词是前缀的词,前后缀都不拼
  583 + if(in_array(Arr::last($topic_words), $all_prefixes)){
  584 + return $str;
  585 + }
  586 +
578 $i= 0; 587 $i= 0;
579 foreach ($topic_words as $topic_word){ 588 foreach ($topic_words as $topic_word){
580 - //包含了前后缀  
581 - if(in_array($topic_word, $all_prefixes)){ 589 + //关键词本身包含了前缀就不拼前缀,只拼后缀
  590 + if(in_array($topic_word, $all_prefixes) && $type == 'prefix'){
  591 + return $str;
  592 + }
  593 + //关键词本身包含了后缀,可拼前缀,也可以再拼一个不重复的后缀,包含两个后缀就不拼后缀了
  594 + if(in_array($topic_word, $all_suffixes) && $type == 'suffix'){
582 //前缀包含一个就不拼了 后缀包含两个才不再拼 595 //前缀包含一个就不拼了 后缀包含两个才不再拼
583 if($i == $num - 1){ 596 if($i == $num - 1){
584 return $str; 597 return $str;
@@ -591,7 +604,6 @@ class UpdateSeoTdk extends Command @@ -591,7 +604,6 @@ class UpdateSeoTdk extends Command
591 if(in_array($topic_word, $preposition) && $type == 'suffix'){ 604 if(in_array($topic_word, $preposition) && $type == 'suffix'){
592 return $str; 605 return $str;
593 } 606 }
594 -  
595 } 607 }
596 608
597 //services/service 结尾的词,后缀不拼manufacturer,factory 609 //services/service 结尾的词,后缀不拼manufacturer,factory
@@ -603,13 +615,13 @@ class UpdateSeoTdk extends Command @@ -603,13 +615,13 @@ class UpdateSeoTdk extends Command
603 $ban = array_merge($ban, ['services', 'service']); 615 $ban = array_merge($ban, ['services', 'service']);
604 } 616 }
605 617
606 - //前缀有wholesale或cheap的词,后缀不拼 manufacturer,factory,exporter,company  
607 - if (Str::startsWith(strtolower($topic), ['wholesale', 'cheap']) && $type == 'prefix') { 618 + //有wholesale或cheap的词,后缀不拼 manufacturer,factory,exporter,company
  619 + if (Str::contains(strtolower($topic), ['wholesale', 'cheap', 'buy']) && $type == 'suffix') {
608 $ban = array_merge($ban, ['manufacturer', 'manufacturers', 'factory', 'factories', 'exporter', 'exporters', 'company', 'companies', 'supplier', 'suppliers']); 620 $ban = array_merge($ban, ['manufacturer', 'manufacturers', 'factory', 'factories', 'exporter', 'exporters', 'company', 'companies', 'supplier', 'suppliers']);
609 } 621 }
610 //关键词以manufacturer,factory,exporter,company结尾, 前缀不拼wholesale或cheap的词 622 //关键词以manufacturer,factory,exporter,company结尾, 前缀不拼wholesale或cheap的词
611 if (Str::endsWith(strtolower($topic), ['manufacturer', 'manufacturers', 'factory', 'factories', 'exporter', 'exporters', 'company', 'companies', 'supplier', 'suppliers']) && $type == 'prefix') { 623 if (Str::endsWith(strtolower($topic), ['manufacturer', 'manufacturers', 'factory', 'factories', 'exporter', 'exporters', 'company', 'companies', 'supplier', 'suppliers']) && $type == 'prefix') {
612 - $ban = array_merge($ban, ['wholesale', 'cheap']); 624 + $ban = array_merge($ban, ['wholesale', 'cheap', 'buy']);
613 } 625 }
614 626
615 //关键词是否包含 品牌词 627 //关键词是否包含 品牌词
@@ -660,7 +672,7 @@ class UpdateSeoTdk extends Command @@ -660,7 +672,7 @@ class UpdateSeoTdk extends Command
660 $keywords[] = $v; 672 $keywords[] = $v;
661 $num--; 673 $num--;
662 } 674 }
663 - if ($type == 'suffix' && count($keywords) == 1 && in_array(Arr::last($topic_words), $all_prefixes)) { 675 + if ($type == 'suffix' && count($keywords) == 1 && in_array(Arr::last($topic_words), $all_suffixes)) {
664 return ', ' . $keywords[0]; 676 return ', ' . $keywords[0];
665 } 677 }
666 return implode(', ', $keywords); 678 return implode(', ', $keywords);
@@ -37,6 +37,7 @@ class CheckListController extends BaseController @@ -37,6 +37,7 @@ class CheckListController extends BaseController
37 * @time :2025/4/17 9:31 37 * @time :2025/4/17 9:31
38 */ 38 */
39 public function lists(){ 39 public function lists(){
  40 + $this->map['status'] = 1;
40 $field = ['id','status','sort','text','created_at']; 41 $field = ['id','status','sort','text','created_at'];
41 $data = $this->model->lists($this->map,$this->page,$this->row,'id',$field); 42 $data = $this->model->lists($this->map,$this->page,$this->row,'id',$field);
42 $this->response('success',Code::SUCCESS,$data); 43 $this->response('success',Code::SUCCESS,$data);
@@ -496,7 +496,7 @@ class RankDataLogic extends BaseLogic @@ -496,7 +496,7 @@ class RankDataLogic extends BaseLogic
496 $without_project_ids = []; //不用处理排名的项目 496 $without_project_ids = []; //不用处理排名的项目
497 $without_extension_project_ids = [658]; //是否达标只统计主词的 497 $without_extension_project_ids = [658]; //是否达标只统计主词的
498 $extension_project_ids = [354]; //扩展词也到达标的 498 $extension_project_ids = [354]; //扩展词也到达标的
499 - $compliance_project_ids = [2163,257,823]; //直接达标处理的 499 + $compliance_project_ids = [2163,257,823,1750]; //直接达标处理的
500 $ceaseProjectId = [47, 354, 378, 649, 1226, 1283, 1703, 1893, 2066, 2250];//暂停的项目 500 $ceaseProjectId = [47, 354, 378, 649, 1226, 1283, 1703, 1893, 2066, 2250];//暂停的项目
501 $uptimeProjectId = [1434,1812,276,2414,2974];//按上线时间统计的项目 501 $uptimeProjectId = [1434,1812,276,2414,2974];//按上线时间统计的项目
502 //一个项目多个api_no 502 //一个项目多个api_no
@@ -45,8 +45,8 @@ class OptimizeCheckLog extends Base @@ -45,8 +45,8 @@ class OptimizeCheckLog extends Base
45 if(isset($param['images'])){ 45 if(isset($param['images'])){
46 $param['images'] = Arr::a2s($param['images'] ?? []); 46 $param['images'] = Arr::a2s($param['images'] ?? []);
47 } 47 }
48 - $this->param['operator_id'] = $manage_id;  
49 - $this->param['date'] = date('Y-m-d hH:i:s'); 48 + $param['operator_id'] = $manage_id;
  49 + $param['date'] = date('Y-m-d H:i:s');
50 return $param; 50 return $param;
51 } 51 }
52 } 52 }