合并分支 'akun' 到 'master'
Akun 查看合并请求 !3094
正在显示
1 个修改的文件
包含
88 行增加
和
13 行删除
| @@ -5,14 +5,20 @@ | @@ -5,14 +5,20 @@ | ||
| 5 | * Date: 2025/10/27 | 5 | * Date: 2025/10/27 |
| 6 | * Time: 13:42 | 6 | * Time: 13:42 |
| 7 | */ | 7 | */ |
| 8 | + | ||
| 8 | namespace App\Console\Commands\Product; | 9 | namespace App\Console\Commands\Product; |
| 9 | 10 | ||
| 10 | use App\Console\Commands\Tdk\UpdateSeoTdk; | 11 | use App\Console\Commands\Tdk\UpdateSeoTdk; |
| 12 | +use App\Models\Com\NoticeLog; | ||
| 13 | +use App\Models\Com\UpdateNotify; | ||
| 14 | +use App\Models\Domain\DomainInfo; | ||
| 11 | use App\Models\Product\Keyword; | 15 | use App\Models\Product\Keyword; |
| 16 | +use App\Models\Project\DeployBuild; | ||
| 12 | use App\Models\Project\Project; | 17 | use App\Models\Project\Project; |
| 13 | use App\Services\ProjectServer; | 18 | use App\Services\ProjectServer; |
| 14 | use Illuminate\Console\Command; | 19 | use Illuminate\Console\Command; |
| 15 | use Illuminate\Support\Arr; | 20 | use Illuminate\Support\Arr; |
| 21 | +use Illuminate\Support\Facades\Cache; | ||
| 16 | use Illuminate\Support\Str; | 22 | use Illuminate\Support\Str; |
| 17 | 23 | ||
| 18 | class SplicePrefix extends Command | 24 | class SplicePrefix extends Command |
| @@ -36,17 +42,36 @@ class SplicePrefix extends Command | @@ -36,17 +42,36 @@ class SplicePrefix extends Command | ||
| 36 | */ | 42 | */ |
| 37 | public function handle() | 43 | public function handle() |
| 38 | { | 44 | { |
| 39 | - #TODO 获取当日不达标项目, 检查关键词前缀拼接 | 45 | + //获取当日不达标项目, 检查关键词前缀拼接 |
| 40 | $project_ids = $this->getProject(); | 46 | $project_ids = $this->getProject(); |
| 41 | if (empty($project_ids)) | 47 | if (empty($project_ids)) |
| 42 | return true; | 48 | return true; |
| 43 | 49 | ||
| 50 | + //获取已经拼接的项目id | ||
| 51 | + $key = 'splice_prefix_project_ids'; | ||
| 52 | + $has_splice_ids = Cache::get($key) ?? []; | ||
| 53 | + | ||
| 44 | foreach ($project_ids as $project_id) { | 54 | foreach ($project_ids as $project_id) { |
| 45 | if ($project_id == 1) | 55 | if ($project_id == 1) |
| 46 | continue; | 56 | continue; |
| 57 | + | ||
| 58 | + if (in_array($project_id, $has_splice_ids)) { | ||
| 59 | + continue; | ||
| 60 | + } | ||
| 61 | + | ||
| 47 | $this->output('project start: ' . $project_id); | 62 | $this->output('project start: ' . $project_id); |
| 63 | + | ||
| 48 | $this->bind($project_id); | 64 | $this->bind($project_id); |
| 65 | + | ||
| 66 | + //处理完后加入已拼接项目id集 | ||
| 67 | + array_push($has_splice_ids, $project_id); | ||
| 68 | + | ||
| 69 | + $this->output('project end: ' . $project_id); | ||
| 49 | } | 70 | } |
| 71 | + | ||
| 72 | + //更新已拼接项目id缓存 | ||
| 73 | + Cache::put($key, $has_splice_ids); | ||
| 74 | + | ||
| 50 | return true; | 75 | return true; |
| 51 | } | 76 | } |
| 52 | 77 | ||
| @@ -56,7 +81,8 @@ class SplicePrefix extends Command | @@ -56,7 +81,8 @@ class SplicePrefix extends Command | ||
| 56 | */ | 81 | */ |
| 57 | public function bind($project_id) | 82 | public function bind($project_id) |
| 58 | { | 83 | { |
| 59 | - $project = ProjectServer::useProject($project_id); | 84 | + $notify_master = false; |
| 85 | + if (ProjectServer::useProject($project_id)) { | ||
| 60 | 86 | ||
| 61 | // 客户前缀 | 87 | // 客户前缀 |
| 62 | $tdk_class = new UpdateSeoTdk(); | 88 | $tdk_class = new UpdateSeoTdk(); |
| @@ -68,7 +94,7 @@ class SplicePrefix extends Command | @@ -68,7 +94,7 @@ class SplicePrefix extends Command | ||
| 68 | $all_prefixes = $tdk_class->getAllPrefix(1, $project_id); | 94 | $all_prefixes = $tdk_class->getAllPrefix(1, $project_id); |
| 69 | $all_prefixes = array_map('strtolower', $all_prefixes); | 95 | $all_prefixes = array_map('strtolower', $all_prefixes); |
| 70 | 96 | ||
| 71 | - $keywords = Keyword::select(['id', 'title', 'seo_title'])->get(); | 97 | + $keywords = Keyword::select(['id', 'title', 'seo_title', 'route'])->get(); |
| 72 | foreach ($keywords as $item) { | 98 | foreach ($keywords as $item) { |
| 73 | $this_fix_keyword = $fix_keyword; | 99 | $this_fix_keyword = $fix_keyword; |
| 74 | if (empty($item->title)) | 100 | if (empty($item->title)) |
| @@ -80,13 +106,18 @@ class SplicePrefix extends Command | @@ -80,13 +106,18 @@ class SplicePrefix extends Command | ||
| 80 | if (empty($item->seo_title)) { | 106 | if (empty($item->seo_title)) { |
| 81 | $prefix = $tdk_class->getPrefixKeyword($project_id, 'prefix', 2, $item->title); | 107 | $prefix = $tdk_class->getPrefixKeyword($project_id, 'prefix', 2, $item->title); |
| 82 | $suffix = $tdk_class->getPrefixKeyword($project_id, 'suffix', 2, trim($prefix . ' ' . $item->title)); | 108 | $suffix = $tdk_class->getPrefixKeyword($project_id, 'suffix', 2, trim($prefix . ' ' . $item->title)); |
| 83 | - if(Str::startsWith($suffix, ', ')){ | 109 | + if (Str::startsWith($suffix, ', ')) { |
| 84 | $seo_title = $prefix . ' ' . $item->title . $suffix; | 110 | $seo_title = $prefix . ' ' . $item->title . $suffix; |
| 85 | - }else{ | 111 | + } else { |
| 86 | $seo_title = $prefix . ' ' . $item->title . ' ' . $suffix; | 112 | $seo_title = $prefix . ' ' . $item->title . ' ' . $suffix; |
| 87 | } | 113 | } |
| 88 | -// $item->seo_title = trim($seo_title); | ||
| 89 | -// $item->save(); | 114 | + $item->seo_title = trim($seo_title); |
| 115 | + $item->save(); | ||
| 116 | + | ||
| 117 | + //存入按需更新表 | ||
| 118 | + UpdateNotify::addUpdateItem($project_id, 'product_keyword', $item->route); | ||
| 119 | + $notify_master = true; | ||
| 120 | + | ||
| 90 | $this->output('new seo title: ' . $seo_title); | 121 | $this->output('new seo title: ' . $seo_title); |
| 91 | continue; | 122 | continue; |
| 92 | } | 123 | } |
| @@ -114,7 +145,7 @@ class SplicePrefix extends Command | @@ -114,7 +145,7 @@ class SplicePrefix extends Command | ||
| 114 | $title_words = explode(' ', strtolower($item->title)); | 145 | $title_words = explode(' ', strtolower($item->title)); |
| 115 | 146 | ||
| 116 | // 关键词最后一个词是前缀的词,前后缀都不拼 | 147 | // 关键词最后一个词是前缀的词,前后缀都不拼 |
| 117 | - if(in_array(Arr::last($title_words), $all_prefixes)) { | 148 | + if (in_array(Arr::last($title_words), $all_prefixes)) { |
| 118 | $this->output('关键词最后一个词是前缀的词, 前后缀都不拼'); | 149 | $this->output('关键词最后一个词是前缀的词, 前后缀都不拼'); |
| 119 | continue; | 150 | continue; |
| 120 | } | 151 | } |
| @@ -124,7 +155,7 @@ class SplicePrefix extends Command | @@ -124,7 +155,7 @@ class SplicePrefix extends Command | ||
| 124 | 155 | ||
| 125 | // 关键词本身包含了前缀,也可以再拼一个不重复的前缀, 包含两个前缀就不拼前缀了 | 156 | // 关键词本身包含了前缀,也可以再拼一个不重复的前缀, 包含两个前缀就不拼前缀了 |
| 126 | foreach ($title_words as $title_word) { | 157 | foreach ($title_words as $title_word) { |
| 127 | - if(in_array($title_word, $all_prefixes)){ | 158 | + if (in_array($title_word, $all_prefixes)) { |
| 128 | $ban[] = $title_word; | 159 | $ban[] = $title_word; |
| 129 | } | 160 | } |
| 130 | } | 161 | } |
| @@ -175,10 +206,22 @@ class SplicePrefix extends Command | @@ -175,10 +206,22 @@ class SplicePrefix extends Command | ||
| 175 | $need_keyword[] = $v; | 206 | $need_keyword[] = $v; |
| 176 | $need_num--; | 207 | $need_num--; |
| 177 | } | 208 | } |
| 178 | -// $item->seo_title = trim(implode(' ', $need_keyword) . ' ' . trim($item->seo_title)); | ||
| 179 | -// $item->save(); | 209 | + $item->seo_title = trim(implode(' ', $need_keyword) . ' ' . trim($item->seo_title)); |
| 210 | + $item->save(); | ||
| 211 | + | ||
| 212 | + //存入按需更新表 | ||
| 213 | + UpdateNotify::addUpdateItem($project_id, 'product_keyword', $item->route); | ||
| 214 | + $notify_master = true; | ||
| 215 | + | ||
| 180 | $this->output('new seo title: ' . implode(' ', $need_keyword) . ' ' . trim($item->seo_title)); | 216 | $this->output('new seo title: ' . implode(' ', $need_keyword) . ' ' . trim($item->seo_title)); |
| 181 | } | 217 | } |
| 218 | + } | ||
| 219 | + | ||
| 220 | + if ($notify_master) { | ||
| 221 | + //通知主站按需更新 | ||
| 222 | + $this->sendNotify($project_id, 2); | ||
| 223 | + } | ||
| 224 | + | ||
| 182 | return true; | 225 | return true; |
| 183 | } | 226 | } |
| 184 | 227 | ||
| @@ -188,8 +231,40 @@ class SplicePrefix extends Command | @@ -188,8 +231,40 @@ class SplicePrefix extends Command | ||
| 188 | */ | 231 | */ |
| 189 | public function getProject() | 232 | public function getProject() |
| 190 | { | 233 | { |
| 191 | - $project_ids = Project::where(['type' => Project::TYPE_TWO, 'project_type' => Project::TYPE_ZERO, 'delete_status' => Project::IS_DEL_FALSE, 'is_remain_today' => 0])->pluck('id')->toArray(); | ||
| 192 | - return $project_ids; | 234 | + return Project::where(['type' => Project::TYPE_TWO, 'project_type' => Project::TYPE_ZERO, 'delete_status' => Project::IS_DEL_FALSE, 'is_remain_today' => 0])->pluck('id')->toArray(); |
| 235 | + } | ||
| 236 | + | ||
| 237 | + /** | ||
| 238 | + * 页面更新 | ||
| 239 | + * @param $project_id | ||
| 240 | + * @param $route | ||
| 241 | + * @author Akun | ||
| 242 | + * @date 2025/10/30 14:33 | ||
| 243 | + */ | ||
| 244 | + public function sendNotify($project_id, $route) | ||
| 245 | + { | ||
| 246 | + //获取当前项目的域名 | ||
| 247 | + $domainModel = new DomainInfo(); | ||
| 248 | + $domainInfo = $domainModel->read(['project_id' => $project_id]); | ||
| 249 | + if ($domainInfo === false) { | ||
| 250 | + //获取测试域名 | ||
| 251 | + $deployBuildModel = new DeployBuild(); | ||
| 252 | + $buildInfo = $deployBuildModel->read(['project_id' => $project_id]); | ||
| 253 | + $domain = $buildInfo['test_domain']; | ||
| 254 | + } else { | ||
| 255 | + $domain = 'https://' . $domainInfo['domain'] . '/'; | ||
| 256 | + } | ||
| 257 | + $url = $domain . 'api/update_page/'; | ||
| 258 | + $param = [ | ||
| 259 | + 'project_id' => $project_id, | ||
| 260 | + 'type' => 1, | ||
| 261 | + 'route' => $route, | ||
| 262 | + 'url' => [], | ||
| 263 | + 'language' => [], | ||
| 264 | + ]; | ||
| 265 | + NoticeLog::createLog(NoticeLog::GENERATE_PAGE, ['c_url' => $url, 'c_params' => $param], date('Y-m-d H:i:s', time() + 300)); | ||
| 266 | + | ||
| 267 | + $this->output('更新中请稍后, 更新完成将会发送站内信通知更新结果!'); | ||
| 193 | } | 268 | } |
| 194 | 269 | ||
| 195 | /** | 270 | /** |
-
请 注册 或 登录 后发表评论