作者 赵彬吉

tdk

... ... @@ -374,10 +374,14 @@ class UpdateSeoTdk extends Command
$seo_title = $v[$this->topic_fields[$table]];;
//只有推广项目 且未标记特殊前后缀 才加 前后缀
if($project->type == Project::TYPE_TWO && !in_array(8, explode(',', $project->deploy_optimize->special))) {
$prefix = $this->getPrefixKeyword($project_id, 'prefix', 1, $project->main_lang_id, $seo_title);
$suffix = $this->getPrefixKeyword($project_id, 'suffix', 2, $project->main_lang_id, $seo_title);
$prefix = $this->getPrefixKeyword($project_id, 'prefix', 1, $seo_title);
$suffix = $this->getPrefixKeyword($project_id, 'suffix', 2, $seo_title);
if(Str::startsWith($suffix, ', ')){
$seo_title = $prefix . ' ' . $seo_title . $suffix;
}else{
$seo_title = $prefix . ' ' . $seo_title . ' ' . $suffix;
}
}
$data[$field] = trim($seo_title);
$update[$table]['title']++;
... ... @@ -547,11 +551,10 @@ class UpdateSeoTdk extends Command
* @param $project_id
* @param $type
* @param $num
* @param int $main_lang_id
* @param string $topic
* @return string
*/
public function getPrefixKeyword($project_id, $type, $num, $main_lang_id = 0, $topic='')
public function getPrefixKeyword($project_id, $type, $num, $topic='')
{
$str = '';
$ban = []; //被禁用的前后缀
... ... @@ -563,11 +566,8 @@ class UpdateSeoTdk extends Command
return $str;
}
//前后缀(小语种包括自定义前后缀)如果已经存在,就不在拼接当前类型 后缀只包含了一个,要再拼一个(需去重)
$all_prefixes = $this->getAllPrefix($type == 'prefix' ? 1 : 2, $main_lang_id == 1 ? 0 : $project_id);
//加上选中的自定义前后缀
$all_prefixes = array_merge($all_prefixes, explode(",", $info['keyword_' . $type]));
$all_prefixes = array_filter($all_prefixes);
//前后缀(包括自定义前后缀)如果已经存在,就不在拼接当前类型 后缀只包含了一个,要再拼一个(需去重)
$all_prefixes = $this->getAllPrefix($type == 'prefix' ? 1 : 2, $project_id);
$all_prefixes = array_map('strtolower', $all_prefixes);
//in,for,with,to,near,from 这些介词 只拼前缀,不拼后缀
... ... @@ -598,10 +598,19 @@ class UpdateSeoTdk extends Command
if (Str::endsWith(strtolower($topic), ['services', 'service']) && $type == 'suffix') {
$ban = array_merge($ban, ['manufacturer', 'manufacturers', 'factory', 'factories']);
}
//manufacturer,factory 结尾的词,后缀不拼 services/service
if (Str::endsWith(strtolower($topic), ['manufacturer', 'manufacturers', 'factory', 'factories']) && $type == 'suffix') {
$ban = array_merge($ban, ['services', 'service']);
}
//前缀有wholesale或cheap的词,后缀不拼 manufacturer,factory,exporter,company
if (Str::startsWith(strtolower($topic), ['wholesale', 'cheap']) && $type == 'prefix') {
$ban = array_merge($ban, ['manufacturer', 'manufacturers', 'factory', 'factories', 'exporter', 'exporters', 'company', 'companies', 'supplier', 'suppliers']);
}
//关键词以manufacturer,factory,exporter,company结尾, 前缀不拼wholesale或cheap的词
if (Str::endsWith(strtolower($topic), ['manufacturer', 'manufacturers', 'factory', 'factories', 'exporter', 'exporters', 'company', 'companies', 'supplier', 'suppliers']) && $type == 'prefix') {
$ban = array_merge($ban, ['wholesale', 'cheap']);
}
//关键词是否包含 品牌词
$brand_keywords = explode("\r\n", $info['brand_keyword']);
... ... @@ -651,6 +660,9 @@ class UpdateSeoTdk extends Command
$keywords[] = $v;
$num--;
}
if ($type == 'suffix' && count($keywords) == 1 && in_array(Arr::last($topic_words), $all_prefixes)) {
return ', ' . $keywords[0];
}
return implode(', ', $keywords);
}
... ...