作者 赵彬吉

seo_tdk

@@ -375,7 +375,7 @@ class UpdateSeoTdk extends Command @@ -375,7 +375,7 @@ class UpdateSeoTdk extends Command
375 //只有推广项目 且未标记特殊前后缀 才加 前后缀 375 //只有推广项目 且未标记特殊前后缀 才加 前后缀
376 if($project->type == Project::TYPE_TWO && !in_array(8, explode(',', $project->deploy_optimize->special))) { 376 if($project->type == Project::TYPE_TWO && !in_array(8, explode(',', $project->deploy_optimize->special))) {
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, $prefix . ' ' . $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 == 'suffix') { 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);