作者 刘锟

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

... ... @@ -67,7 +67,30 @@ class UpdateRoute extends Command
*/
public function handle()
{
return $this->settingSeo();
return $this->getNullRoute();
}
/**
* @remark :查询 路由为空的关键词项目id
* @name :getNullRoute
* @author :lyh
* @method :post
* @time :2025/4/21 11:52
*/
public function getNullRoute(){
$projectModel = new Project();
$lists = $projectModel->list(['delete_status' => 0,'extend_type'=>0,'type'=>['in',[1,2,3,4]]], 'id', ['id']);
foreach ($lists as $val) {
echo date('Y-m-d H:i:s') . '开始--项目的id:'. $val['id'] . PHP_EOL;
ProjectServer::useProject($val['id']);
$keywordModel = new Keyword();
$info = $keywordModel->read(['route'=>'']);
if($info !== false){
echo '存在路由为空--项目id:'.$val['id'].PHP_EOL;
}
DB::disconnect('custom_mysql');
}
return true;
}
public function keyword_actions(){
... ...
... ... @@ -68,6 +68,7 @@ class RecommendedSuppliers extends Command
if(!empty($title)){
$this->savePurchaser($v['project_id'],$title);
}else{
$this->deployBuildModel->edit(['is_supplier'=>0],['project_id'=>$v['project_id']]);
echo '关键词已取完'.PHP_EOL;
}
DB::disconnect('custom_mysql');
... ... @@ -152,7 +153,7 @@ class RecommendedSuppliers extends Command
];
ksort($data);
$token = 'company_list+'.date('Y-m-d').'+'.http_build_query($data);
// echo date('Y-m-d H:i:s') . '加密token:'.md5($token) . PHP_EOL;
$keyword = rtrim($keyword, "\r");
$param = [
'prod_desc'=>$keyword,
'token'=>md5($token),
... ... @@ -161,7 +162,7 @@ class RecommendedSuppliers extends Command
$res = http_post($url,json_encode($param));
echo '请求返回状态'. ($res['code']?? '').PHP_EOL;
// echo date('Y-m-d H:i:s') . json_encode($res) . PHP_EOL;
if(!empty($res) && isset($res['code']) && $res['code'] == 200 && !empty($res['data'])){
if(isset($res['code']) && $res['code'] == 200){
//保存多条数据
$saveData = [
'project_id'=>$project_id,
... ... @@ -170,10 +171,11 @@ class RecommendedSuppliers extends Command
];
$purchaserModel = new Purchaser();
$purchaserModel->add($saveData);
$this->savePurchaserInfo($project_id,$keyword,$res['data']);
if(!empty($res['data'])){
$this->savePurchaserInfo($project_id,$keyword,$res['data']);
}
}else{
$title = $this->getKeywords($project_id);
$this->savePurchaser($project_id,$title);
echo '未正常返回数据,跳过项目'.PHP_EOL;
}
return true;
}
... ... @@ -188,11 +190,11 @@ class RecommendedSuppliers extends Command
public function getKeywords($project_id){
$keywordModel = new Keyword();
$keyword_array = $this->getPurchaserList($project_id);
$info = $keywordModel->read(['title'=>['not in',$keyword_array]],'title');
if($info === false){
$title = $keywordModel->where('title', 'not in', $keyword_array)->orderRaw('RAND()')->limit(1)->value('title'); // 只返回 title 字段
if(empty($title)){
return '';
}
return $info['title'] ?? '';
return $title;
}
/**
... ...
... ... @@ -5,10 +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;
... ... @@ -63,38 +66,80 @@ class RerunSeoTdk extends Command
}
/**
* 判断seo_title后缀重复
* 判断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 = [];
//Suppliers, Manufacturer
foreach ($seo_titles as $id=>$seo_title){
if(!Str::contains($seo_title, ', ')){
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;
}
$arr = explode(', ', $seo_title);
$suffix1 = $arr[1];
$arr = explode(' ', $arr[0]);
$suffix2 = Arr::last($arr);
if(Str::singular($suffix1) == Str::singular($suffix2)){
$topic_words = explode(' ', strtolower($title));
//关键词最后一个是前缀 且 有前后缀
if(in_array(Arr::last($topic_words), $all_prefixes) && $title != $seo_title){
$ids[] = $id;
dump($seo_title);
continue;
}
}
$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
... ... @@ -116,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, $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 == 'prefix') {
//有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);
... ...
... ... @@ -37,6 +37,7 @@ class CheckListController extends BaseController
* @time :2025/4/17 9:31
*/
public function lists(){
$this->map['status'] = 1;
$field = ['id','status','sort','text','created_at'];
$data = $this->model->lists($this->map,$this->page,$this->row,'id',$field);
$this->response('success',Code::SUCCESS,$data);
... ...
... ... @@ -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
... ...
... ... @@ -45,8 +45,8 @@ class OptimizeCheckLog extends Base
if(isset($param['images'])){
$param['images'] = Arr::a2s($param['images'] ?? []);
}
$this->param['operator_id'] = $manage_id;
$this->param['date'] = date('Y-m-d hH:i:s');
$param['operator_id'] = $manage_id;
$param['date'] = date('Y-m-d H:i:s');
return $param;
}
}
... ...