作者 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
sleep(300);
continue;
}
$lock_key = "geo_task_lock:$task_id";
$lock_key = "geo_task_lock_" . $task_id;
if (!Redis::setnx($lock_key, 1)) {
$this->output("任务 $task_id 已被其他进程锁定,跳过");
sleep(30); // 程序挂起, 避免最后一个任务 扫数据表和Redis
continue;
}
Redis::expire($lock_key, 1200); // 1小时自动解锁
Redis::expire($lock_key, 600); // 10自动解锁
$this->output('执行的任务ID:' . $task_id);
$geoQuestionModel = new GeoQuestion();
$taskInfo = $geoQuestionModel->read(['id'=>$task_id]);
... ... @@ -86,6 +87,8 @@ class GeoQuestionRes extends Command
$geoResultModel = new GeoQuestionResult();
$geoLogModel = new GeoQuestionLog();
foreach ($taskInfo['question'] as $question) {
Redis::expire($lock_key, 1200); // 一个问题执行时间可能会达到15-18分钟
$en_question = Translate::tran($question, 'zh') ?? '';
$this->output('项目ID:' . $taskInfo['project_id'] . ', 问题 开始:' . $question);
foreach ($platformsArr as $platform) {
... ... @@ -345,19 +348,28 @@ class GeoQuestionRes extends Command
$key = 'geo_task_list';
$task_id = Redis::rpop($key);
if(empty($task_id)){
$project_ids = GeoQuestion::where('status', GeoQuestion::STATUS_OPEN)->where('next_time', '<=', date('Y-m-d'))
->orderBy('next_time', 'asc')->pluck('project_id')->unique()->values()->toArray();
if(!empty($project_ids)){
foreach ($project_ids as $project_id){
$ids = GeoQuestion::where(['project_id' => $project_id, 'status' => GeoQuestion::STATUS_OPEN])->where('next_time', '<=', date('Y-m-d'))->pluck('id');
foreach ($ids as $id) {
//检查任务是否执行过
if (!Redis::exists("geo_task_lock:$id")) {
Redis::lpush($key, $id);
}
}
$task_id = Redis::rpop($key);
$lock_key = 'geo_task_generation_lock';
$lock_ttl = 60; // 锁时间大于当前 锁功能执行时间
// 尝试获取锁,非阻塞方式
$lock = Redis::set($lock_key, 1, 'EX', $lock_ttl, 'NX');
if (empty($lock))
return $task_id;
$project_ids = GeoQuestion::where('status', GeoQuestion::STATUS_OPEN)->where('next_time', '<=', date('Y-m-d'))->pluck('project_id')->unique()->values()->toArray();
if(FALSE == empty($project_ids)){
$ids = GeoQuestion::where('status', GeoQuestion::STATUS_OPEN)
->whereIn('project_id', $project_ids)
->where(function ($query){
$query->where('current_time', '!=', date('Y-m-d'))
->orWhereNull('current_time');
})
->orderBy('project_id', 'asc')
->pluck('id');
foreach ($ids as $id) {
Redis::lpush($key, $id);
}
$task_id = Redis::rpop($key);
}
}
return $task_id;
... ...
<?php
/**
* Created by PhpStorm.
* User: zhl
* 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
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'splice_prefix';
/**
* The console command description.
*
* @var string
*/
protected $description = '未达标项目,拼接关键词聚合页前缀';
/**
* @return bool
*/
public function handle()
{
//获取当日不达标项目, 检查关键词前缀拼接
$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;
}
/**
* @param $project_id
* @return bool
*/
public function bind($project_id)
{
$notify_master = false;
if (ProjectServer::useProject($project_id)) {
// 客户前缀
$tdk_class = new UpdateSeoTdk();
$info = $tdk_class->getDeployOptimize($project_id);
$fix_keyword = explode(",", $info['keyword_prefix']);
$fix_keyword = array_filter($fix_keyword);
// 所有前缀
$all_prefixes = $tdk_class->getAllPrefix(1, $project_id);
$all_prefixes = array_map('strtolower', $all_prefixes);
$keywords = Keyword::select(['id', 'title', 'seo_title', 'route'])->get();
foreach ($keywords as $item) {
$this_fix_keyword = $fix_keyword;
if (empty($item->title))
continue;
$this->output('keyword id:' . $item->id . ' | title: ' . $item->title . ' | old seo title: ' . $item->seo_title);
// 没有 SEO Title 直接生成
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, ', ')) {
$seo_title = $prefix . ' ' . $item->title . $suffix;
} else {
$seo_title = $prefix . ' ' . $item->title . ' ' . $suffix;
}
$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;
}
// 有 SEO Title 需要分析前后缀
$start = strpos($item->seo_title, $item->title);
// Title 和 SEO Title 不存在包含关系
if ($start === FALSE) {
$this->output('Title 和 SEO Title 不存在包含关系');
continue;
}
$prefix = $start == 0 ? '' : trim(substr($item->seo_title, 0, $start));
$prefix_array = explode(' ', $prefix);
$prefix_array = array_filter($prefix_array);
$need_num = 2 - count($prefix_array);
// 已经有两个前缀, 不在处理
if ($need_num <= 0) {
$this->output('已经有两个前缀, 不在处理');
continue;
}
// 关键词最后一个词是前缀的词,前后缀都不拼
$title_words = explode(' ', strtolower($item->title));
// 关键词最后一个词是前缀的词,前后缀都不拼
if (in_array(Arr::last($title_words), $all_prefixes)) {
$this->output('关键词最后一个词是前缀的词, 前后缀都不拼');
continue;
}
// in,for,with,to,near,from 这些介词 只拼前缀,不拼后缀
$ban = [];
// 关键词本身包含了前缀,也可以再拼一个不重复的前缀, 包含两个前缀就不拼前缀了
foreach ($title_words as $title_word) {
if (in_array($title_word, $all_prefixes)) {
$ban[] = $title_word;
}
}
$need_num = $need_num - count($ban);
// 关键词本身包含前缀,包含关键词大于等于需要的前缀,当前关键词不需要处理
if ($need_num <= 0) {
$this->output('关键词本身包含前缀,包含关键词大于等于需要的前缀,当前关键词不需要处理');
continue;
}
// services/service 结尾的词,后缀不拼manufacturer,factory
// manufacturer,factory 结尾的词,后缀不拼 services/service
// 有wholesale或cheap的词,后缀不拼 manufacturer,factory,exporter,company
// 关键词以manufacturer,factory,exporter,company结尾, 前缀不拼wholesale或cheap的词
if (Str::endsWith(strtolower($item->title), ['manufacturer', 'manufacturers', 'factory', 'factories', 'exporter', 'exporters', 'company', 'companies', 'supplier', 'suppliers']))
$ban = array_merge($ban, ['wholesale', 'cheap', 'buy']);
foreach ($this_fix_keyword as $k => $keyword) {
// 被禁用的关键词
if (in_array(strtolower(Str::plural($keyword)), $ban)) {
unset($this_fix_keyword[$k]);
}
if (in_array(strtolower(Str::singular($keyword)), $ban)) {
unset($this_fix_keyword[$k]);
}
}
$this_fix_keyword = array_diff($this_fix_keyword, $prefix_array);
shuffle($this_fix_keyword);
$need_keyword = [];
foreach ($this_fix_keyword as $v) {
if ($need_num == 0)
break;
$is_repeat = false;
foreach ($need_keyword as $keyword) {
if (Str::singular($keyword) == Str::singular($v)) {
$is_repeat = true;
break;
}
}
if ($is_repeat)
continue;
$need_keyword[] = $v;
$need_num--;
}
$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;
}
/**
* 获取当日未达标项目
* @return mixed
*/
public function getProject()
{
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('更新中请稍后, 更新完成将会发送站内信通知更新结果!');
}
/**
* 输出日志
* @param $message
* @return bool
*/
public function output($message)
{
$message = now() . ' ' . $message . PHP_EOL;
file_put_contents(storage_path('logs/splice_prefix.log'), $message, FILE_APPEND);
echo $message;
return true;
}
}
... ...
... ... @@ -171,6 +171,10 @@ class HtmlCollect extends Command
$html = str_replace('Broflanilide', '', $html);
$html = str_replace('broflanilide', '', $html);
}
if ($project_id == 587) {
//437项目单词替换
$html = str_replace('Horny Goat Weed', 'Icariin', $html);
}
$collect_info->html = $html;
$collect_info->status = CollectTask::STATUS_COM;
$collect_info->save();
... ...
... ... @@ -138,6 +138,10 @@ class ProjectUpdate extends Command
//2078项目单词替换
$replace = ['Broflanilide' => '', 'broflanilide' => ''];
}
if ($project_id == 587) {
//587项目单词替换
$replace = ['Horny Goat Weed' => 'Icariin'];
}
//设置数据库
$project = ProjectServer::useProject($project_id);
... ...
... ... @@ -205,4 +205,22 @@ class NoticeController extends BaseController
MessagePush::addInquiryMessage(0, $project->id, $country, $name, $submit);
return $this->success();
}
/**
* 获取6.0所有使用域名
* @return false|string
* @author Akun
* @date 2025/10/30 10:42
*/
public function getAllDomain(){
$domainModel = new DomainInfo();
$lists = $domainModel->list(['status'=>DomainInfo::STATUS_ONE],'id',['domain','project_id'],'asc');
$project_model = new Project();
foreach ($lists as &$v){
$pro_info = $project_model->read(['id'=>$v['project_id']],['company']);
$v['company'] = $pro_info ? $pro_info['company'] : '';
}
return $this->success($lists);
}
}
... ...
... ... @@ -479,6 +479,14 @@ class SyncSubmitTaskService
){
throw new InquiryFilterException( '全局过滤');
}
if(
empty($data['data']['name']) &&
strlen($data['data']['message']??'') >= 8 &&
preg_match('/^[a-zA-Z]+$/', $data['data']['message']??'') &&
in_array($data['country']??'', ['荷兰', '俄罗斯'])
){
throw new InquiryFilterException( '全局过滤');
}
//全局过滤 ip 荷兰 有name、phone、email字段,但都是空
if(
in_array($data['country']??'', ['荷兰', '俄罗斯']) &&
... ...
... ... @@ -74,6 +74,9 @@ Route::post('selfSiteSsl', [\App\Http\Controllers\Api\SelfSiteController::class,
//创建301跳转任务
Route::any('/addRedirect',[\App\Http\Controllers\Api\NoticeController::class,'addRedirect']);
//获取所有有效域名
Route::any('/getAllDomain',[\App\Http\Controllers\Api\NoticeController::class,'getAllDomain']);
//关联域名
Route::post('/inquiry_relate_domain', [\App\Http\Controllers\Api\PrivateController::class, 'inquiry_relate_domain']);
// 通过域名获取项目人员配置
... ...