正在显示
1 个修改的文件
包含
31 行增加
和
7 行删除
| @@ -5,11 +5,13 @@ namespace App\Console\Commands\Tdk; | @@ -5,11 +5,13 @@ namespace App\Console\Commands\Tdk; | ||
| 5 | 5 | ||
| 6 | use App\Helper\Arr; | 6 | use App\Helper\Arr; |
| 7 | use App\Models\Product\Keyword; | 7 | use App\Models\Product\Keyword; |
| 8 | +use App\Models\Project\KeywordPrefix; | ||
| 8 | use App\Models\Project\Project; | 9 | use App\Models\Project\Project; |
| 9 | use App\Models\Project\ProjectUpdateTdk; | 10 | use App\Models\Project\ProjectUpdateTdk; |
| 10 | use App\Services\ProjectServer; | 11 | use App\Services\ProjectServer; |
| 11 | use App\Utils\LogUtils; | 12 | use App\Utils\LogUtils; |
| 12 | use Illuminate\Console\Command; | 13 | use Illuminate\Console\Command; |
| 14 | +use Illuminate\Support\Facades\Cache; | ||
| 13 | use Illuminate\Support\Facades\DB; | 15 | use Illuminate\Support\Facades\DB; |
| 14 | use Illuminate\Support\Str; | 16 | use Illuminate\Support\Str; |
| 15 | 17 | ||
| @@ -64,24 +66,36 @@ class RerunSeoTdk extends Command | @@ -64,24 +66,36 @@ class RerunSeoTdk extends Command | ||
| 64 | } | 66 | } |
| 65 | 67 | ||
| 66 | /** | 68 | /** |
| 67 | - * 判断seo_title 前缀有wholesale或cheap的词,后缀也有 manufacturer,factory,exporter,company | 69 | + * 判断seo_title 前缀有wholesale或cheap或buy的词,后缀也有 manufacturer,factory,exporter,company |
| 70 | + * 判断关键词最后一个词是前缀的词,前后缀都不拼 | ||
| 68 | * @author zbj | 71 | * @author zbj |
| 69 | * @date 2025/4/12 | 72 | * @date 2025/4/12 |
| 70 | */ | 73 | */ |
| 71 | public function judgeAnomalies($project_id){ | 74 | public function judgeAnomalies($project_id){ |
| 75 | + dump($project_id); | ||
| 76 | + $all_prefixes = $this->getAllPrefix(1, $project_id); | ||
| 77 | + $all_prefixes = array_map('strtolower', $all_prefixes); | ||
| 78 | + | ||
| 72 | //获取当前项目的所有分类 | 79 | //获取当前项目的所有分类 |
| 73 | - $seo_titles = Keyword::pluck('seo_title', 'id')->toArray(); | 80 | + $list = Keyword::select('title', 'seo_title', 'id')->get()->toArray(); |
| 74 | //新闻 seo_keyword 和 分类名一样的 | 81 | //新闻 seo_keyword 和 分类名一样的 |
| 75 | $ids = []; | 82 | $ids = []; |
| 76 | - foreach ($seo_titles as $id=>$seo_title){ | ||
| 77 | - if(!Str::startsWith(strtolower($seo_title), ['wholesale', 'cheap'])){ | 83 | + foreach ($list as $k=>$item){ |
| 84 | + $seo_title = $item['seo_title']; | ||
| 85 | + $id = $item['id']; | ||
| 86 | + $title = $item['title']; | ||
| 87 | + if(Str::startsWith(strtolower($seo_title), ['wholesale', 'cheap', 'buy']) && Str::contains(strtolower($seo_title), ['manufacturer', 'manufacturers', 'factory', 'factories', 'exporter', 'exporters', 'company', 'companies', 'supplier', 'suppliers'])){ | ||
| 88 | + $ids[] = $id; | ||
| 89 | + dump($seo_title); | ||
| 78 | continue; | 90 | continue; |
| 79 | } | 91 | } |
| 80 | - if(!Str::contains(strtolower($seo_title), ['manufacturer', 'manufacturers', 'factory', 'factories', 'exporter', 'exporters', 'company', 'companies', 'supplier', 'suppliers'])){ | 92 | + $topic_words = explode(' ', strtolower($title)); |
| 93 | + //关键词最后一个是前缀 且 有前后缀 | ||
| 94 | + if(in_array(Arr::last($topic_words), $all_prefixes) && $title != $seo_title){ | ||
| 95 | + $ids[] = $id; | ||
| 96 | + dump($seo_title); | ||
| 81 | continue; | 97 | continue; |
| 82 | } | 98 | } |
| 83 | - dump($seo_title);exit; | ||
| 84 | - $ids[] = $id; | ||
| 85 | } | 99 | } |
| 86 | 100 | ||
| 87 | $count = count($ids); | 101 | $count = count($ids); |
| @@ -147,4 +161,14 @@ class RerunSeoTdk extends Command | @@ -147,4 +161,14 @@ class RerunSeoTdk extends Command | ||
| 147 | // ProjectUpdateTdk::add_task($project_id); | 161 | // ProjectUpdateTdk::add_task($project_id); |
| 148 | // } | 162 | // } |
| 149 | // } | 163 | // } |
| 164 | + | ||
| 165 | + public function getAllPrefix($type, int $project_id = 0){ | ||
| 166 | + $cache_key = 'AllPrefix_' . $type . '_' . $project_id; | ||
| 167 | + $data = Cache::get($cache_key); | ||
| 168 | + if(!$data){ | ||
| 169 | + $data = KeywordPrefix::whereIn('project_id', [0, $project_id])->where('type', $type)->pluck('keyword')->toArray(); | ||
| 170 | + Cache::put($cache_key, $data, 600); | ||
| 171 | + } | ||
| 172 | + return $data; | ||
| 173 | + } | ||
| 150 | } | 174 | } |
-
请 注册 或 登录 后发表评论