作者 赵彬吉

重跑seo

... ... @@ -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;
}
}
... ...