作者 刘锟

合并分支 'akun' 到 'master'

Akun



查看合并请求 !3094
... ... @@ -5,14 +5,20 @@
* Date: 2025/10/27
* Time: 13:42
*/
namespace App\Console\Commands\Product;
use App\Console\Commands\Tdk\UpdateSeoTdk;
use App\Models\Com\NoticeLog;
use App\Models\Com\UpdateNotify;
use App\Models\Domain\DomainInfo;
use App\Models\Product\Keyword;
use App\Models\Project\DeployBuild;
use App\Models\Project\Project;
use App\Services\ProjectServer;
use Illuminate\Console\Command;
use Illuminate\Support\Arr;
use Illuminate\Support\Facades\Cache;
use Illuminate\Support\Str;
class SplicePrefix extends Command
... ... @@ -36,17 +42,36 @@ class SplicePrefix extends Command
*/
public function handle()
{
#TODO 获取当日不达标项目, 检查关键词前缀拼接
//获取当日不达标项目, 检查关键词前缀拼接
$project_ids = $this->getProject();
if (empty($project_ids))
return true;
//获取已经拼接的项目id
$key = 'splice_prefix_project_ids';
$has_splice_ids = Cache::get($key) ?? [];
foreach ($project_ids as $project_id) {
if ($project_id == 1)
continue;
if (in_array($project_id, $has_splice_ids)) {
continue;
}
$this->output('project start: ' . $project_id);
$this->bind($project_id);
//处理完后加入已拼接项目id集
array_push($has_splice_ids, $project_id);
$this->output('project end: ' . $project_id);
}
//更新已拼接项目id缓存
Cache::put($key, $has_splice_ids);
return true;
}
... ... @@ -56,7 +81,8 @@ class SplicePrefix extends Command
*/
public function bind($project_id)
{
$project = ProjectServer::useProject($project_id);
$notify_master = false;
if (ProjectServer::useProject($project_id)) {
// 客户前缀
$tdk_class = new UpdateSeoTdk();
... ... @@ -68,7 +94,7 @@ class SplicePrefix extends Command
$all_prefixes = $tdk_class->getAllPrefix(1, $project_id);
$all_prefixes = array_map('strtolower', $all_prefixes);
$keywords = Keyword::select(['id', 'title', 'seo_title'])->get();
$keywords = Keyword::select(['id', 'title', 'seo_title', 'route'])->get();
foreach ($keywords as $item) {
$this_fix_keyword = $fix_keyword;
if (empty($item->title))
... ... @@ -80,13 +106,18 @@ class SplicePrefix extends Command
if (empty($item->seo_title)) {
$prefix = $tdk_class->getPrefixKeyword($project_id, 'prefix', 2, $item->title);
$suffix = $tdk_class->getPrefixKeyword($project_id, 'suffix', 2, trim($prefix . ' ' . $item->title));
if(Str::startsWith($suffix, ', ')){
if (Str::startsWith($suffix, ', ')) {
$seo_title = $prefix . ' ' . $item->title . $suffix;
}else{
} else {
$seo_title = $prefix . ' ' . $item->title . ' ' . $suffix;
}
// $item->seo_title = trim($seo_title);
// $item->save();
$item->seo_title = trim($seo_title);
$item->save();
//存入按需更新表
UpdateNotify::addUpdateItem($project_id, 'product_keyword', $item->route);
$notify_master = true;
$this->output('new seo title: ' . $seo_title);
continue;
}
... ... @@ -114,7 +145,7 @@ class SplicePrefix extends Command
$title_words = explode(' ', strtolower($item->title));
// 关键词最后一个词是前缀的词,前后缀都不拼
if(in_array(Arr::last($title_words), $all_prefixes)) {
if (in_array(Arr::last($title_words), $all_prefixes)) {
$this->output('关键词最后一个词是前缀的词, 前后缀都不拼');
continue;
}
... ... @@ -124,7 +155,7 @@ class SplicePrefix extends Command
// 关键词本身包含了前缀,也可以再拼一个不重复的前缀, 包含两个前缀就不拼前缀了
foreach ($title_words as $title_word) {
if(in_array($title_word, $all_prefixes)){
if (in_array($title_word, $all_prefixes)) {
$ban[] = $title_word;
}
}
... ... @@ -175,10 +206,22 @@ class SplicePrefix extends Command
$need_keyword[] = $v;
$need_num--;
}
// $item->seo_title = trim(implode(' ', $need_keyword) . ' ' . trim($item->seo_title));
// $item->save();
$item->seo_title = trim(implode(' ', $need_keyword) . ' ' . trim($item->seo_title));
$item->save();
//存入按需更新表
UpdateNotify::addUpdateItem($project_id, 'product_keyword', $item->route);
$notify_master = true;
$this->output('new seo title: ' . implode(' ', $need_keyword) . ' ' . trim($item->seo_title));
}
}
if ($notify_master) {
//通知主站按需更新
$this->sendNotify($project_id, 2);
}
return true;
}
... ... @@ -188,8 +231,40 @@ class SplicePrefix extends Command
*/
public function getProject()
{
$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();
return $project_ids;
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();
}
/**
* 页面更新
* @param $project_id
* @param $route
* @author Akun
* @date 2025/10/30 14:33
*/
public function sendNotify($project_id, $route)
{
//获取当前项目的域名
$domainModel = new DomainInfo();
$domainInfo = $domainModel->read(['project_id' => $project_id]);
if ($domainInfo === false) {
//获取测试域名
$deployBuildModel = new DeployBuild();
$buildInfo = $deployBuildModel->read(['project_id' => $project_id]);
$domain = $buildInfo['test_domain'];
} else {
$domain = 'https://' . $domainInfo['domain'] . '/';
}
$url = $domain . 'api/update_page/';
$param = [
'project_id' => $project_id,
'type' => 1,
'route' => $route,
'url' => [],
'language' => [],
];
NoticeLog::createLog(NoticeLog::GENERATE_PAGE, ['c_url' => $url, 'c_params' => $param], date('Y-m-d H:i:s', time() + 300));
$this->output('更新中请稍后, 更新完成将会发送站内信通知更新结果!');
}
/**
... ...