作者 lyh

Merge branch 'zhl' of http://47.244.231.31:8099/zhl/globalso-v6 into lyh-server

@@ -51,12 +51,13 @@ class GeoQuestionRes extends Command @@ -51,12 +51,13 @@ class GeoQuestionRes extends Command
51 sleep(300); 51 sleep(300);
52 continue; 52 continue;
53 } 53 }
54 - $lock_key = "geo_task_lock:$task_id"; 54 + $lock_key = "geo_task_lock_" . $task_id;
55 if (!Redis::setnx($lock_key, 1)) { 55 if (!Redis::setnx($lock_key, 1)) {
56 $this->output("任务 $task_id 已被其他进程锁定,跳过"); 56 $this->output("任务 $task_id 已被其他进程锁定,跳过");
  57 + sleep(30); // 程序挂起, 避免最后一个任务 扫数据表和Redis
57 continue; 58 continue;
58 } 59 }
59 - Redis::expire($lock_key, 1200); // 1小时自动解锁 60 + Redis::expire($lock_key, 600); // 10自动解锁
60 $this->output('执行的任务ID:' . $task_id); 61 $this->output('执行的任务ID:' . $task_id);
61 $geoQuestionModel = new GeoQuestion(); 62 $geoQuestionModel = new GeoQuestion();
62 $taskInfo = $geoQuestionModel->read(['id'=>$task_id]); 63 $taskInfo = $geoQuestionModel->read(['id'=>$task_id]);
@@ -86,6 +87,8 @@ class GeoQuestionRes extends Command @@ -86,6 +87,8 @@ class GeoQuestionRes extends Command
86 $geoResultModel = new GeoQuestionResult(); 87 $geoResultModel = new GeoQuestionResult();
87 $geoLogModel = new GeoQuestionLog(); 88 $geoLogModel = new GeoQuestionLog();
88 foreach ($taskInfo['question'] as $question) { 89 foreach ($taskInfo['question'] as $question) {
  90 + Redis::expire($lock_key, 1200); // 一个问题执行时间可能会达到15-18分钟
  91 +
89 $en_question = Translate::tran($question, 'zh') ?? ''; 92 $en_question = Translate::tran($question, 'zh') ?? '';
90 $this->output('项目ID:' . $taskInfo['project_id'] . ', 问题 开始:' . $question); 93 $this->output('项目ID:' . $taskInfo['project_id'] . ', 问题 开始:' . $question);
91 foreach ($platformsArr as $platform) { 94 foreach ($platformsArr as $platform) {
@@ -345,19 +348,28 @@ class GeoQuestionRes extends Command @@ -345,19 +348,28 @@ class GeoQuestionRes extends Command
345 $key = 'geo_task_list'; 348 $key = 'geo_task_list';
346 $task_id = Redis::rpop($key); 349 $task_id = Redis::rpop($key);
347 if(empty($task_id)){ 350 if(empty($task_id)){
348 - $project_ids = GeoQuestion::where('status', GeoQuestion::STATUS_OPEN)->where('next_time', '<=', date('Y-m-d'))  
349 - ->orderBy('next_time', 'asc')->pluck('project_id')->unique()->values()->toArray();  
350 - if(!empty($project_ids)){  
351 - foreach ($project_ids as $project_id){  
352 - $ids = GeoQuestion::where(['project_id' => $project_id, 'status' => GeoQuestion::STATUS_OPEN])->where('next_time', '<=', date('Y-m-d'))->pluck('id');  
353 - foreach ($ids as $id) {  
354 - //检查任务是否执行过  
355 - if (!Redis::exists("geo_task_lock:$id")) {  
356 - Redis::lpush($key, $id);  
357 - }  
358 - }  
359 - $task_id = Redis::rpop($key); 351 + $lock_key = 'geo_task_generation_lock';
  352 + $lock_ttl = 60; // 锁时间大于当前 锁功能执行时间
  353 + // 尝试获取锁,非阻塞方式
  354 + $lock = Redis::set($lock_key, 1, 'EX', $lock_ttl, 'NX');
  355 + if (empty($lock))
  356 + return $task_id;
  357 +
  358 + $project_ids = GeoQuestion::where('status', GeoQuestion::STATUS_OPEN)->where('next_time', '<=', date('Y-m-d'))->pluck('project_id')->unique()->values()->toArray();
  359 + if(FALSE == empty($project_ids)){
  360 + $ids = GeoQuestion::where('status', GeoQuestion::STATUS_OPEN)
  361 + ->whereIn('project_id', $project_ids)
  362 + ->where(function ($query){
  363 + $query->where('current_time', '!=', date('Y-m-d'))
  364 + ->orWhereNull('current_time');
  365 + })
  366 + ->orderBy('project_id', 'asc')
  367 + ->pluck('id');
  368 +
  369 + foreach ($ids as $id) {
  370 + Redis::lpush($key, $id);
360 } 371 }
  372 + $task_id = Redis::rpop($key);
361 } 373 }
362 } 374 }
363 return $task_id; 375 return $task_id;
  1 +<?php
  2 +/**
  3 + * Created by PhpStorm.
  4 + * User: zhl
  5 + * Date: 2025/10/27
  6 + * Time: 13:42
  7 + */
  8 +
  9 +namespace App\Console\Commands\Product;
  10 +
  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;
  15 +use App\Models\Product\Keyword;
  16 +use App\Models\Project\DeployBuild;
  17 +use App\Models\Project\Project;
  18 +use App\Services\ProjectServer;
  19 +use Illuminate\Console\Command;
  20 +use Illuminate\Support\Arr;
  21 +use Illuminate\Support\Facades\Cache;
  22 +use Illuminate\Support\Str;
  23 +
  24 +class SplicePrefix extends Command
  25 +{
  26 + /**
  27 + * The name and signature of the console command.
  28 + *
  29 + * @var string
  30 + */
  31 + protected $signature = 'splice_prefix';
  32 +
  33 + /**
  34 + * The console command description.
  35 + *
  36 + * @var string
  37 + */
  38 + protected $description = '未达标项目,拼接关键词聚合页前缀';
  39 +
  40 + /**
  41 + * @return bool
  42 + */
  43 + public function handle()
  44 + {
  45 + //获取当日不达标项目, 检查关键词前缀拼接
  46 + $project_ids = $this->getProject();
  47 + if (empty($project_ids))
  48 + return true;
  49 +
  50 + //获取已经拼接的项目id
  51 + $key = 'splice_prefix_project_ids';
  52 + $has_splice_ids = Cache::get($key) ?? [];
  53 +
  54 + foreach ($project_ids as $project_id) {
  55 + if ($project_id == 1)
  56 + continue;
  57 +
  58 + if (in_array($project_id, $has_splice_ids)) {
  59 + continue;
  60 + }
  61 +
  62 + $this->output('project start: ' . $project_id);
  63 +
  64 + $this->bind($project_id);
  65 +
  66 + //处理完后加入已拼接项目id集
  67 + array_push($has_splice_ids, $project_id);
  68 +
  69 + $this->output('project end: ' . $project_id);
  70 + }
  71 +
  72 + //更新已拼接项目id缓存
  73 + Cache::put($key, $has_splice_ids);
  74 +
  75 + return true;
  76 + }
  77 +
  78 + /**
  79 + * @param $project_id
  80 + * @return bool
  81 + */
  82 + public function bind($project_id)
  83 + {
  84 + $notify_master = false;
  85 + if (ProjectServer::useProject($project_id)) {
  86 +
  87 + // 客户前缀
  88 + $tdk_class = new UpdateSeoTdk();
  89 + $info = $tdk_class->getDeployOptimize($project_id);
  90 + $fix_keyword = explode(",", $info['keyword_prefix']);
  91 + $fix_keyword = array_filter($fix_keyword);
  92 +
  93 + // 所有前缀
  94 + $all_prefixes = $tdk_class->getAllPrefix(1, $project_id);
  95 + $all_prefixes = array_map('strtolower', $all_prefixes);
  96 +
  97 + $keywords = Keyword::select(['id', 'title', 'seo_title', 'route'])->get();
  98 + foreach ($keywords as $item) {
  99 + $this_fix_keyword = $fix_keyword;
  100 + if (empty($item->title))
  101 + continue;
  102 +
  103 + $this->output('keyword id:' . $item->id . ' | title: ' . $item->title . ' | old seo title: ' . $item->seo_title);
  104 +
  105 + // 没有 SEO Title 直接生成
  106 + if (empty($item->seo_title)) {
  107 + $prefix = $tdk_class->getPrefixKeyword($project_id, 'prefix', 2, $item->title);
  108 + $suffix = $tdk_class->getPrefixKeyword($project_id, 'suffix', 2, trim($prefix . ' ' . $item->title));
  109 + if (Str::startsWith($suffix, ', ')) {
  110 + $seo_title = $prefix . ' ' . $item->title . $suffix;
  111 + } else {
  112 + $seo_title = $prefix . ' ' . $item->title . ' ' . $suffix;
  113 + }
  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 +
  121 + $this->output('new seo title: ' . $seo_title);
  122 + continue;
  123 + }
  124 +
  125 + // 有 SEO Title 需要分析前后缀
  126 + $start = strpos($item->seo_title, $item->title);
  127 +
  128 + // Title 和 SEO Title 不存在包含关系
  129 + if ($start === FALSE) {
  130 + $this->output('Title 和 SEO Title 不存在包含关系');
  131 + continue;
  132 + }
  133 +
  134 + $prefix = $start == 0 ? '' : trim(substr($item->seo_title, 0, $start));
  135 + $prefix_array = explode(' ', $prefix);
  136 + $prefix_array = array_filter($prefix_array);
  137 + $need_num = 2 - count($prefix_array);
  138 + // 已经有两个前缀, 不在处理
  139 + if ($need_num <= 0) {
  140 + $this->output('已经有两个前缀, 不在处理');
  141 + continue;
  142 + }
  143 +
  144 + // 关键词最后一个词是前缀的词,前后缀都不拼
  145 + $title_words = explode(' ', strtolower($item->title));
  146 +
  147 + // 关键词最后一个词是前缀的词,前后缀都不拼
  148 + if (in_array(Arr::last($title_words), $all_prefixes)) {
  149 + $this->output('关键词最后一个词是前缀的词, 前后缀都不拼');
  150 + continue;
  151 + }
  152 +
  153 + // in,for,with,to,near,from 这些介词 只拼前缀,不拼后缀
  154 + $ban = [];
  155 +
  156 + // 关键词本身包含了前缀,也可以再拼一个不重复的前缀, 包含两个前缀就不拼前缀了
  157 + foreach ($title_words as $title_word) {
  158 + if (in_array($title_word, $all_prefixes)) {
  159 + $ban[] = $title_word;
  160 + }
  161 + }
  162 + $need_num = $need_num - count($ban);
  163 +
  164 + // 关键词本身包含前缀,包含关键词大于等于需要的前缀,当前关键词不需要处理
  165 + if ($need_num <= 0) {
  166 + $this->output('关键词本身包含前缀,包含关键词大于等于需要的前缀,当前关键词不需要处理');
  167 + continue;
  168 + }
  169 +
  170 +
  171 + // services/service 结尾的词,后缀不拼manufacturer,factory
  172 + // manufacturer,factory 结尾的词,后缀不拼 services/service
  173 + // 有wholesale或cheap的词,后缀不拼 manufacturer,factory,exporter,company
  174 +
  175 + // 关键词以manufacturer,factory,exporter,company结尾, 前缀不拼wholesale或cheap的词
  176 + if (Str::endsWith(strtolower($item->title), ['manufacturer', 'manufacturers', 'factory', 'factories', 'exporter', 'exporters', 'company', 'companies', 'supplier', 'suppliers']))
  177 + $ban = array_merge($ban, ['wholesale', 'cheap', 'buy']);
  178 +
  179 +
  180 + foreach ($this_fix_keyword as $k => $keyword) {
  181 + // 被禁用的关键词
  182 + if (in_array(strtolower(Str::plural($keyword)), $ban)) {
  183 + unset($this_fix_keyword[$k]);
  184 + }
  185 + if (in_array(strtolower(Str::singular($keyword)), $ban)) {
  186 + unset($this_fix_keyword[$k]);
  187 + }
  188 + }
  189 + $this_fix_keyword = array_diff($this_fix_keyword, $prefix_array);
  190 + shuffle($this_fix_keyword);
  191 + $need_keyword = [];
  192 + foreach ($this_fix_keyword as $v) {
  193 + if ($need_num == 0)
  194 + break;
  195 +
  196 + $is_repeat = false;
  197 + foreach ($need_keyword as $keyword) {
  198 + if (Str::singular($keyword) == Str::singular($v)) {
  199 + $is_repeat = true;
  200 + break;
  201 + }
  202 + }
  203 + if ($is_repeat)
  204 + continue;
  205 +
  206 + $need_keyword[] = $v;
  207 + $need_num--;
  208 + }
  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 +
  216 + $this->output('new seo title: ' . implode(' ', $need_keyword) . ' ' . trim($item->seo_title));
  217 + }
  218 + }
  219 +
  220 + if ($notify_master) {
  221 + //通知主站按需更新
  222 + $this->sendNotify($project_id, 2);
  223 + }
  224 +
  225 + return true;
  226 + }
  227 +
  228 + /**
  229 + * 获取当日未达标项目
  230 + * @return mixed
  231 + */
  232 + public function getProject()
  233 + {
  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('更新中请稍后, 更新完成将会发送站内信通知更新结果!');
  268 + }
  269 +
  270 + /**
  271 + * 输出日志
  272 + * @param $message
  273 + * @return bool
  274 + */
  275 + public function output($message)
  276 + {
  277 + $message = now() . ' ' . $message . PHP_EOL;
  278 + file_put_contents(storage_path('logs/splice_prefix.log'), $message, FILE_APPEND);
  279 + echo $message;
  280 + return true;
  281 + }
  282 +}
@@ -171,6 +171,10 @@ class HtmlCollect extends Command @@ -171,6 +171,10 @@ class HtmlCollect extends Command
171 $html = str_replace('Broflanilide', '', $html); 171 $html = str_replace('Broflanilide', '', $html);
172 $html = str_replace('broflanilide', '', $html); 172 $html = str_replace('broflanilide', '', $html);
173 } 173 }
  174 + if ($project_id == 587) {
  175 + //437项目单词替换
  176 + $html = str_replace('Horny Goat Weed', 'Icariin', $html);
  177 + }
174 $collect_info->html = $html; 178 $collect_info->html = $html;
175 $collect_info->status = CollectTask::STATUS_COM; 179 $collect_info->status = CollectTask::STATUS_COM;
176 $collect_info->save(); 180 $collect_info->save();
@@ -138,6 +138,10 @@ class ProjectUpdate extends Command @@ -138,6 +138,10 @@ class ProjectUpdate extends Command
138 //2078项目单词替换 138 //2078项目单词替换
139 $replace = ['Broflanilide' => '', 'broflanilide' => '']; 139 $replace = ['Broflanilide' => '', 'broflanilide' => ''];
140 } 140 }
  141 + if ($project_id == 587) {
  142 + //587项目单词替换
  143 + $replace = ['Horny Goat Weed' => 'Icariin'];
  144 + }
141 145
142 //设置数据库 146 //设置数据库
143 $project = ProjectServer::useProject($project_id); 147 $project = ProjectServer::useProject($project_id);
@@ -205,4 +205,22 @@ class NoticeController extends BaseController @@ -205,4 +205,22 @@ class NoticeController extends BaseController
205 MessagePush::addInquiryMessage(0, $project->id, $country, $name, $submit); 205 MessagePush::addInquiryMessage(0, $project->id, $country, $name, $submit);
206 return $this->success(); 206 return $this->success();
207 } 207 }
  208 +
  209 + /**
  210 + * 获取6.0所有使用域名
  211 + * @return false|string
  212 + * @author Akun
  213 + * @date 2025/10/30 10:42
  214 + */
  215 + public function getAllDomain(){
  216 + $domainModel = new DomainInfo();
  217 + $lists = $domainModel->list(['status'=>DomainInfo::STATUS_ONE],'id',['domain','project_id'],'asc');
  218 +
  219 + $project_model = new Project();
  220 + foreach ($lists as &$v){
  221 + $pro_info = $project_model->read(['id'=>$v['project_id']],['company']);
  222 + $v['company'] = $pro_info ? $pro_info['company'] : '';
  223 + }
  224 + return $this->success($lists);
  225 + }
208 } 226 }
@@ -479,6 +479,14 @@ class SyncSubmitTaskService @@ -479,6 +479,14 @@ class SyncSubmitTaskService
479 ){ 479 ){
480 throw new InquiryFilterException( '全局过滤'); 480 throw new InquiryFilterException( '全局过滤');
481 } 481 }
  482 + if(
  483 + empty($data['data']['name']) &&
  484 + strlen($data['data']['message']??'') >= 8 &&
  485 + preg_match('/^[a-zA-Z]+$/', $data['data']['message']??'') &&
  486 + in_array($data['country']??'', ['荷兰', '俄罗斯'])
  487 + ){
  488 + throw new InquiryFilterException( '全局过滤');
  489 + }
482 //全局过滤 ip 荷兰 有name、phone、email字段,但都是空 490 //全局过滤 ip 荷兰 有name、phone、email字段,但都是空
483 if( 491 if(
484 in_array($data['country']??'', ['荷兰', '俄罗斯']) && 492 in_array($data['country']??'', ['荷兰', '俄罗斯']) &&
@@ -74,6 +74,9 @@ Route::post('selfSiteSsl', [\App\Http\Controllers\Api\SelfSiteController::class, @@ -74,6 +74,9 @@ Route::post('selfSiteSsl', [\App\Http\Controllers\Api\SelfSiteController::class,
74 //创建301跳转任务 74 //创建301跳转任务
75 Route::any('/addRedirect',[\App\Http\Controllers\Api\NoticeController::class,'addRedirect']); 75 Route::any('/addRedirect',[\App\Http\Controllers\Api\NoticeController::class,'addRedirect']);
76 76
  77 +//获取所有有效域名
  78 +Route::any('/getAllDomain',[\App\Http\Controllers\Api\NoticeController::class,'getAllDomain']);
  79 +
77 //关联域名 80 //关联域名
78 Route::post('/inquiry_relate_domain', [\App\Http\Controllers\Api\PrivateController::class, 'inquiry_relate_domain']); 81 Route::post('/inquiry_relate_domain', [\App\Http\Controllers\Api\PrivateController::class, 'inquiry_relate_domain']);
79 // 通过域名获取项目人员配置 82 // 通过域名获取项目人员配置