作者 lyh

Merge branch 'master' of http://47.244.231.31:8099/zhl/globalso-v6 into lyh-server

... ... @@ -5,11 +5,13 @@ namespace App\Console\Commands\Tdk;
use App\Helper\Arr;
use App\Models\Product\Keyword;
use App\Models\Project\KeywordPrefix;
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\Cache;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Str;
... ... @@ -64,24 +66,36 @@ class RerunSeoTdk extends Command
}
/**
* 判断seo_title 前缀有wholesale或cheap的词,后缀也有 manufacturer,factory,exporter,company
* 判断seo_title 前缀有wholesale或cheap或buy的词,后缀也有 manufacturer,factory,exporter,company
* 判断关键词最后一个词是前缀的词,前后缀都不拼
* @author zbj
* @date 2025/4/12
*/
public function judgeAnomalies($project_id){
dump($project_id);
$all_prefixes = $this->getAllPrefix(1, $project_id);
$all_prefixes = array_map('strtolower', $all_prefixes);
//获取当前项目的所有分类
$seo_titles = Keyword::pluck('seo_title', 'id')->toArray();
$list = Keyword::select('title', 'seo_title', 'id')->get()->toArray();
//新闻 seo_keyword 和 分类名一样的
$ids = [];
foreach ($seo_titles as $id=>$seo_title){
if(!Str::startsWith(strtolower($seo_title), ['wholesale', 'cheap'])){
foreach ($list as $k=>$item){
$seo_title = $item['seo_title'];
$id = $item['id'];
$title = $item['title'];
if(Str::startsWith(strtolower($seo_title), ['wholesale', 'cheap', 'buy']) && Str::contains(strtolower($seo_title), ['manufacturer', 'manufacturers', 'factory', 'factories', 'exporter', 'exporters', 'company', 'companies', 'supplier', 'suppliers'])){
$ids[] = $id;
dump($seo_title);
continue;
}
if(!Str::contains(strtolower($seo_title), ['manufacturer', 'manufacturers', 'factory', 'factories', 'exporter', 'exporters', 'company', 'companies', 'supplier', 'suppliers'])){
$topic_words = explode(' ', strtolower($title));
//关键词最后一个是前缀 且 有前后缀
if(in_array(Arr::last($topic_words), $all_prefixes) && $title != $seo_title){
$ids[] = $id;
dump($seo_title);
continue;
}
dump($seo_title);exit;
$ids[] = $id;
}
$count = count($ids);
... ... @@ -147,4 +161,14 @@ class RerunSeoTdk extends Command
// ProjectUpdateTdk::add_task($project_id);
// }
// }
public function getAllPrefix($type, int $project_id = 0){
$cache_key = 'AllPrefix_' . $type . '_' . $project_id;
$data = Cache::get($cache_key);
if(!$data){
$data = KeywordPrefix::whereIn('project_id', [0, $project_id])->where('type', $type)->pluck('keyword')->toArray();
Cache::put($cache_key, $data, 600);
}
return $data;
}
}
... ...
... ... @@ -372,10 +372,10 @@ class UpdateSeoTdk extends Command
} else if ($table == 'gl_product_keyword' && $field == 'seo_title') {
# TODO 聚合页seo title 特殊处理 前缀_1 . 关键词 . 后缀_2
$seo_title = $v[$this->topic_fields[$table]];;
//只有推广项目 且未标记特殊前后缀 才加 前后缀
if($project->type == Project::TYPE_TWO && !in_array(8, explode(',', $project->deploy_optimize->special))) {
//只有推广项目 才加 前后缀
if($project->type == Project::TYPE_TWO) {
$prefix = $this->getPrefixKeyword($project_id, 'prefix', 1, $seo_title);
$suffix = $this->getPrefixKeyword($project_id, 'suffix', 2, $prefix . ' ' . $seo_title);
$suffix = $this->getPrefixKeyword($project_id, 'suffix', 2, trim($prefix . ' ' . $seo_title));
if(Str::startsWith($suffix, ', ')){
$seo_title = $prefix . ' ' . $seo_title . $suffix;
}else{
... ... @@ -567,18 +567,31 @@ class UpdateSeoTdk extends Command
}
//前后缀(包括自定义前后缀)如果已经存在,就不在拼接当前类型 后缀只包含了一个,要再拼一个(需去重)
$all_prefixes = $this->getAllPrefix($type == 'prefix' ? 1 : 2, $project_id);
$all_prefixes = $this->getAllPrefix(1, $project_id);
$all_prefixes = array_map('strtolower', $all_prefixes);
$all_suffixes = $this->getAllPrefix(2, $project_id);
$all_suffixes = array_map('strtolower', $all_suffixes);
//in,for,with,to,near,from 这些介词 只拼前缀,不拼后缀
$preposition = ['in', 'for', 'with', 'to', 'near','from'];
//标题拆成词
$topic_words = explode(' ', strtolower($topic));
//关键词最后一个词是前缀的词,前后缀都不拼
if(in_array(Arr::last($topic_words), $all_prefixes)){
return $str;
}
$i= 0;
foreach ($topic_words as $topic_word){
//包含了前后缀
if(in_array($topic_word, $all_prefixes)){
//关键词本身包含了前缀就不拼前缀,只拼后缀
if(in_array($topic_word, $all_prefixes) && $type == 'prefix'){
return $str;
}
//关键词本身包含了后缀,可拼前缀,也可以再拼一个不重复的后缀,包含两个后缀就不拼后缀了
if(in_array($topic_word, $all_suffixes) && $type == 'suffix'){
//前缀包含一个就不拼了 后缀包含两个才不再拼
if($i == $num - 1){
return $str;
... ... @@ -591,7 +604,6 @@ class UpdateSeoTdk extends Command
if(in_array($topic_word, $preposition) && $type == 'suffix'){
return $str;
}
}
//services/service 结尾的词,后缀不拼manufacturer,factory
... ... @@ -603,13 +615,13 @@ class UpdateSeoTdk extends Command
$ban = array_merge($ban, ['services', 'service']);
}
//前缀有wholesale或cheap的词,后缀不拼 manufacturer,factory,exporter,company
if (Str::startsWith(strtolower($topic), ['wholesale', 'cheap']) && $type == 'suffix') {
//有wholesale或cheap的词,后缀不拼 manufacturer,factory,exporter,company
if (Str::contains(strtolower($topic), ['wholesale', 'cheap', 'buy']) && $type == 'suffix') {
$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']);
$ban = array_merge($ban, ['wholesale', 'cheap', 'buy']);
}
//关键词是否包含 品牌词
... ... @@ -660,7 +672,7 @@ class UpdateSeoTdk extends Command
$keywords[] = $v;
$num--;
}
if ($type == 'suffix' && count($keywords) == 1 && in_array(Arr::last($topic_words), $all_prefixes)) {
if ($type == 'suffix' && count($keywords) == 1 && in_array(Arr::last($topic_words), $all_suffixes)) {
return ', ' . $keywords[0];
}
return implode(', ', $keywords);
... ...
... ... @@ -39,17 +39,64 @@ class Temp extends Command
*/
protected $description = '临时脚本(akun)';
public function handle()
public function handle(){
}
/**
* www.docareco.com批量设置301跳转
* @author Akun
* @date 2025/04/21 16:12
*/
public function setDomain301()
{
$domain_extend_config = DomainInfo::where('domain', 'www.docareco.com')->value('extend_config');
$domain_origin_list = $domain_extend_config ? array_column($domain_extend_config, 'origin') : [];
//读取csv文件
$file = 'C:\Users\Akun\Desktop\有排名网页-还未做301-4.21.csv';
$line_of_text = [];
try {
$file_handle = fopen($file, 'r');
while (!feof($file_handle)) {
$line_of_text[] = fgetcsv($file_handle, 0, ',');
}
fclose($file_handle);
} catch (\Exception $e) {
$this->output($e->getMessage());
}
if (count($line_of_text) > 1) {
foreach ($line_of_text as $k => $v) {
if ($k > 0 && $v) {
$origin = str_replace('https://www.docareco.com', '', $v[0]);
$target = str_replace('https://www.docareco.com', '', $v[1]);
if (!in_array($origin, $domain_origin_list)) {
$domain_extend_config[] = [
'origin' => $origin,
'target' => $target
];
}
}
}
}
DomainInfo::where('domain', 'www.docareco.com')->update(['extend_config' => Arr::a2s($domain_extend_config)]);
$this->output('success');
}
/**
* 未被标注 特殊前后缀 && 未达标项目 && 优化开始时间 > 2025-01-01 00:00:00 ,开启自动添加聚合页关键词的前后缀关键词配置
* @author Akun
* @date 2025/04/02 14:00
*/
public function changeIsAutoKeywords(){
public function changeIsAutoKeywords()
{
$project_list = DeployOptimize::where('special', 'not like', '%,8,%')->where('start_date', '>', '2025-01-01 00:00:00')->get();
foreach ($project_list as $project) {
... ...
... ... @@ -195,17 +195,36 @@ class DomainInfoLogic extends BaseLogic
}
}
//如果要开通amp站点,判断m域名是否已经解析
$domain_array = parse_url($info['domain']);
$host = $domain_array['host'] ?? $domain_array['path'];
$host_array = explode('.',$host);
if($this->param['type'] == 3){
//需要申请通配符证书,判断_acme-challenge是否已经解析
$host_array_ssl = $host_array;
if (count($host_array_ssl) <= 2) {
array_unshift($host_array_ssl, '_acme-challenge');
} else {
$host_array_ssl[0] = '_acme-challenge';
}
$ssl_domain = implode('.',$host_array_ssl);
$ssl_records = dns_get_record($ssl_domain,DNS_CNAME);
$ssl_target = $ssl_records[0]['target']??'';
if($ssl_target != '_acme-challenge.globalsosslcheck.com'){
$this->fail('域名' . $ssl_domain . '未解析至目标服务器');
}
}
if(isset($this->param['amp_status']) && $this->param['amp_status'] == 1){
$domain_array = parse_url($info['domain']);
$host = $domain_array['host'] ?? $domain_array['path'];
$host_array = explode('.',$host);
if (count($host_array) <= 2) {
array_unshift($host_array, 'm');
//需要开通amp站点,判断m域名是否已经解析
$host_array_amp = $host_array;
if (count($host_array_amp) <= 2) {
array_unshift($host_array_amp, 'm');
} else {
$host_array[0] = 'm';
$host_array_amp[0] = 'm';
}
$amp_domain = implode('.',$host_array);
$amp_domain = implode('.',$host_array_amp);
if(!check_domain_record($amp_domain, $serversIpInfo)){
$this->fail('AMP站点域名' . $amp_domain . '未解析至目标服务器');
}
... ...
... ... @@ -496,7 +496,7 @@ class RankDataLogic extends BaseLogic
$without_project_ids = []; //不用处理排名的项目
$without_extension_project_ids = [658]; //是否达标只统计主词的
$extension_project_ids = [354]; //扩展词也到达标的
$compliance_project_ids = [2163,257,823]; //直接达标处理的
$compliance_project_ids = [2163,257,823,1750]; //直接达标处理的
$ceaseProjectId = [47, 354, 378, 649, 1226, 1283, 1703, 1893, 2066, 2250];//暂停的项目
$uptimeProjectId = [1434,1812,276,2414,2974];//按上线时间统计的项目
//一个项目多个api_no
... ...