作者 赵彬吉
... ... @@ -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,7 @@ 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,21 +347,30 @@ 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');
$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) {
//检查任务是否执行过
if (!Redis::exists("geo_task_lock:$id")) {
Redis::lpush($key, $id);
}
}
$task_id = Redis::rpop($key);
}
}
}
return $task_id;
}
... ...
... ... @@ -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('更新中请稍后, 更新完成将会发送站内信通知更新结果!');
}
/**
... ...
... ... @@ -326,16 +326,6 @@ class ProjectUpdate extends Command
//分类
$category_id = '';
$category_arr = [];
if ($project_id == 596 && empty($item['category'])) {
//596项目,产品没有分类,默认属于Featured分类
$item['category'] = [
[
'id' => 623,
'name' => 'Featured',
'pid' => 0
]
];
}
if ($item['category'] ?? []) {
if ($project_id == 4075 && count($item['category']) == 1 && $item['category'][0]['name'] == 'Featured') {
//4075项目特殊处理:不采集Featured分类下的产品
... ...
... ... @@ -39,6 +39,11 @@ class GeoWritingTaskController extends BaseController
* @time :2025/10/25 15:12
*/
public function lists(){
$this->request->validate([
'project_id'=>'required',
],[
'project_id.required' => 'project_id不能为空',
]);
$data = $this->logic->listWritingTask($this->map,$this->page,$this->row,$this->order);
$this->response('success',Code::SUCCESS,$data);
}
... ...
... ... @@ -39,6 +39,11 @@ class GeoWritingsController extends BaseController
* @time :2025/10/25 15:53
*/
public function lists(){
$this->request->validate([
'project_id'=>'required',
],[
'project_id.required' => 'project_id不能为空',
]);
$data = $this->logic->listWriting($this->map,$this->page,$this->row,$this->order);
$this->response('success',Code::SUCCESS,$data);
}
... ...
... ... @@ -251,7 +251,6 @@ class InquiryController extends BaseController
$data = $data['list'] ?? [];
foreach ($data as &$item){
//非正常登录的
if(($this->user['login_source']??0) != 2 && ($this->user['login_source']??0) != 3){
if(!empty($item['email']) && (strpos($item['email'], '@') !== false)){
$item['email'] = email_desensitize($item['email']);
... ... @@ -259,9 +258,7 @@ class InquiryController extends BaseController
//脱敏
!empty($item['phone']) && $item['phone'] = substr($item['phone'], 0, -4) . '****';
}
$item['ip_address'] = "{$item['country']}({$item['ip']})";
if(!empty($this->param['form_id'])){
$item = array_merge($item, $item['data']);
}
... ...
... ... @@ -69,9 +69,11 @@ class GeoConfirmLogic extends BaseLogic
{
$data = $this->model->read($this->param);
if($data === false){
$this->fail('当前数据不存在或者已被删除');
return $this->success();
}
if(empty($data['confirm'])){
$data['confirm'] = $data['content'];
}
return $this->success($data);
}
... ...
... ... @@ -112,6 +112,9 @@ class GeoLogic extends BaseLogic
{
//获取问题数量
$geo_question_count = GeoQuestion::selectRaw('SUM(JSON_LENGTH(question)) as total_count')->where('project_id',$this->param['project_id'])->value('total_count');
if(empty($geo_question_count)){
$geo_question_count = 0;
}
$geo_pr_count = GeoLink::where('project_id',$this->param['project_id'])->count();
$geo_writings_count = GeoWritings::where('project_id',$this->param['project_id'])->count();
return $this->success(['geo_writings_count'=>$geo_writings_count,'geo_pr_count'=>$geo_pr_count,'geo_question_count'=>$geo_question_count]);
... ...
... ... @@ -111,10 +111,20 @@ class DomainSettingLogic extends BaseLogic
if (count($domain_array) == 1) {
$this->fail('请填写正确的主域名');
} elseif (count($domain_array) == 2) {
if ($this->user['project_id'] == 5113) {
//5113项目二级域名使用news
array_unshift($domain_array, 'news');
} else {
array_unshift($domain_array, 'blog');
}
} else {
if ($this->user['project_id'] == 5113) {
//5113项目二级域名使用news
$domain_array[0] = 'news';
} else {
$domain_array[0] = 'blog';
}
}
$blog_domain = implode('.', $domain_array);
//判断blog二级域名是否已经解析
... ... @@ -145,7 +155,7 @@ class DomainSettingLogic extends BaseLogic
//变更ip使用数量
$server_ip_model->edit(['total' => $record_info['total'] + 1], ['id' => $record_info['id']]);
$server_model->where(['id'=>$record_info['servers_id']])->increment('being_number',1);
$server_model->where(['id' => $record_info['servers_id']])->increment('being_number', 1);
//创建建站任务
$domain_create_model = new DomainCreateTask();
... ... @@ -204,7 +214,7 @@ class DomainSettingLogic extends BaseLogic
//变更ip使用数量
$server_ip_model->edit(['total' => $record_info['total'] + 1], ['id' => $record_info['id']]);
$server_model->where(['id'=>$record_info['servers_id']])->increment('being_number',1);
$server_model->where(['id' => $record_info['servers_id']])->increment('being_number', 1);
}
DB::commit();
... ...
... ... @@ -8,6 +8,8 @@
namespace App\Models\Geo;
use App\Models\Base;
use App\Models\Project\DeployBuild;
use App\Models\Project\Project;
use App\Models\Workchat\MessagePush;
/**
... ... @@ -42,8 +44,23 @@ class GeoConfirm extends Base
public static function typeMapping()
{
return [
self::TYPE_TITLE => '确认标题',
self::TYPE_KEYWORD => '确认关键词'
self::TYPE_TITLE => '核心关键词问题已整理,请查看并确认',
self::TYPE_KEYWORD => '文章标题已整理,请查看并确认'
];
}
/**
* @remark :确认返回数据
* @name :typeDesc
* @author :lyh
* @method :post
* @time :2025/10/31 10:10
*/
public static function typeDesc()
{
return [
self::TYPE_TITLE => '需选择确认10个文章标题,后续根据您确认的文章标题整理文章内容;如有补充展会、资质证书等资料,可一并提供。',
self::TYPE_KEYWORD => '需选择确认10个核心关键词问题,后续根据您确认的核心关键词问题整理文章标题;建议提供展会、资质证书等资料。'
];
}
... ... @@ -98,9 +115,14 @@ class GeoConfirm extends Base
$type = MessagePush::TYPE_GEO_CONFIRM;
$token = uniqid().$friend_id;
$created_at = $updated_at = now();
$projectModel = new Project();
$company = $projectModel->getValue(['id'=>$project_id],'company');
$deployModel = new DeployBuild();
$seo_plan = $deployModel->getValue(['project_id'=>$project_id],'seo_plan');
$seo_plan_name = ($projectModel::seoMap()[$seo_plan]) ?? '无选择';
$content_array = [
'title' => self::typeMapping()[$data->type],
'desc' => self::typeMapping()[$data->type],
'title' => "【{$company} {$seo_plan_name}】".self::typeMapping()[$data->type],
'desc' => self::typeDesc()[$data->type],
'size' => 0,
'thumbSize' => 0,
'thumbUrl' => 'https://hub.globalso.com/logocm.png',
... ...
... ... @@ -8,6 +8,8 @@
namespace App\Models\Geo;
use App\Models\Base;
use App\Models\Project\DeployBuild;
use App\Models\Project\Project;
use App\Models\ProjectAssociation\ProjectAssociation;
use App\Models\Workchat\MessagePush;
use Illuminate\Support\Facades\Crypt;
... ... @@ -90,10 +92,15 @@ class GeoWritings extends Base
'project_id' => $project_id,
'send_at' => time()
];
$projectModel = new Project();
$company = $projectModel->getValue(['id'=>$project_id],'company');
$deployModel = new DeployBuild();
$seo_plan = $deployModel->getValue(['project_id'=>$project_id],'seo_plan');
$seo_plan_name = ($projectModel::seoMap()[$seo_plan]) ?? '无选择';
$token = Crypt::encrypt($param);
$content_array = [
'title' => "确认核心文章",
'desc' => '确认核心文章',
'title' => "【{$company} {$seo_plan_name}】核心文章已整理,请查看并确认",
'desc' => '需选择确认10篇文章,后续根据您确认的文章进行外链发布。',
'size' => 0,
'thumbSize' => 0,
'thumbUrl' => 'https://hub.globalso.com/logocm.png',
... ...