作者 Your Name
@@ -10,6 +10,7 @@ @@ -10,6 +10,7 @@
10 namespace App\Console\Commands\Domain; 10 namespace App\Console\Commands\Domain;
11 11
12 use App\Models\Devops\ServerConfig; 12 use App\Models\Devops\ServerConfig;
  13 +use App\Models\Devops\ServersIp;
13 use App\Models\Project\CountryCustom; 14 use App\Models\Project\CountryCustom;
14 use App\Models\Project\Project; 15 use App\Models\Project\Project;
15 use Illuminate\Console\Command; 16 use Illuminate\Console\Command;
@@ -98,7 +99,10 @@ class DomainInfo extends Command @@ -98,7 +99,10 @@ class DomainInfo extends Command
98 $ssl['to'] && $data['certificate_end_time'] = $ssl['to']; 99 $ssl['to'] && $data['certificate_end_time'] = $ssl['to'];
99 100
100 $project_info = $projectModel->read(['id' => $v['project_id']], ['serve_id']); 101 $project_info = $projectModel->read(['id' => $v['project_id']], ['serve_id']);
101 - if ($v['type'] == 1 && $ssl['to'] < $end_day && $project_info && $project_info['serve_id'] != ServerConfig::SELF_SITE_ID) { 102 + if ($v['type'] == 1 && $ssl['to'] < $end_day && $project_info) {
  103 + $serverIpModel = new ServersIp();
  104 + $servers_ip_info = $serverIpModel->read(['id' => $project_info['serve_id']], ['servers_id']);
  105 + if ($servers_ip_info && $servers_ip_info['servers_id'] != ServerConfig::SELF_SITE_ID) {
102 //非自建站项目,申请免费证书 106 //非自建站项目,申请免费证书
103 $this->updatePrivate($v); 107 $this->updatePrivate($v);
104 108
@@ -107,6 +111,8 @@ class DomainInfo extends Command @@ -107,6 +111,8 @@ class DomainInfo extends Command
107 $ssl_new['to'] && $data['certificate_end_time'] = $ssl_new['to']; 111 $ssl_new['to'] && $data['certificate_end_time'] = $ssl_new['to'];
108 } 112 }
109 113
  114 + }
  115 +
110 $domainModel->edit($data, ['id' => $v['id']]); 116 $domainModel->edit($data, ['id' => $v['id']]);
111 } 117 }
112 } 118 }
@@ -142,7 +148,10 @@ class DomainInfo extends Command @@ -142,7 +148,10 @@ class DomainInfo extends Command
142 $ssl['to'] && $data['amp_certificate_end_time'] = $ssl['to']; 148 $ssl['to'] && $data['amp_certificate_end_time'] = $ssl['to'];
143 149
144 $project_info = $projectModel->read(['id' => $v['project_id']], ['serve_id']); 150 $project_info = $projectModel->read(['id' => $v['project_id']], ['serve_id']);
145 - if ($v['amp_type'] == 1 && $ssl['to'] < $end_day && $project_info && $project_info['serve_id'] != ServerConfig::SELF_SITE_ID) { 151 + if ($v['amp_type'] == 1 && $ssl['to'] < $end_day && $project_info) {
  152 + $serverIpModel = new ServersIp();
  153 + $servers_ip_info = $serverIpModel->read(['id' => $project_info['serve_id']], ['servers_id']);
  154 + if ($servers_ip_info && $servers_ip_info['servers_id'] != ServerConfig::SELF_SITE_ID) {
146 //非自建站项目,申请免费证书 155 //非自建站项目,申请免费证书
147 $this->updateAmpPrivate($v['domain']); 156 $this->updateAmpPrivate($v['domain']);
148 157
@@ -150,6 +159,7 @@ class DomainInfo extends Command @@ -150,6 +159,7 @@ class DomainInfo extends Command
150 $ssl_new['from'] && $data['certificate_start_time'] = $ssl_new['from']; 159 $ssl_new['from'] && $data['certificate_start_time'] = $ssl_new['from'];
151 $ssl_new['to'] && $data['certificate_end_time'] = $ssl_new['to']; 160 $ssl_new['to'] && $data['certificate_end_time'] = $ssl_new['to'];
152 } 161 }
  162 + }
153 163
154 $domainModel->edit($data, ['id' => $v['id']]); 164 $domainModel->edit($data, ['id' => $v['id']]);
155 } 165 }
  1 +<?php
  2 +/**
  3 + * @remark :
  4 + * @name :UpdateKeyword.php
  5 + * @author :lyh
  6 + * @method :post
  7 + * @time :2024/7/3 9:23
  8 + */
  9 +
  10 +namespace App\Console\Commands\Update;
  11 +
  12 +use App\Models\Domain\DomainInfo;
  13 +use App\Models\Product\Keyword;
  14 +use App\Models\Product\KeywordPage;
  15 +use App\Services\ProjectServer;
  16 +use Illuminate\Console\Command;
  17 +use Illuminate\Support\Facades\DB;
  18 +
  19 +class UpdateKeyword extends Command
  20 +{
  21 + /**
  22 + * The name and signature of the console command.
  23 + *
  24 + * @var string
  25 + */
  26 + protected $signature = 'update_keyword';
  27 +
  28 + /**
  29 + * The console command description.
  30 + *
  31 + * @var string
  32 + */
  33 + protected $description = '批量更新关键词内容';
  34 +
  35 +
  36 + public function handle(){
  37 + while (true){
  38 + $keywordPageModel = new KeywordPage();
  39 + $lists = $keywordPageModel->list(['status'=>0]);
  40 + if(empty($lists)){
  41 + sleep(100);
  42 + continue;
  43 + }
  44 + $domainModel = new DomainInfo();
  45 + foreach ($lists as $v){
  46 + ProjectServer::useProject($v['project_id']);
  47 + $this->saveKeywordContent($v);
  48 + DB::disconnect('custom_mysql');
  49 + //获取当前项目的域名
  50 + $domainInfo = $domainModel->read(['project_id'=>$v['project_id']]);
  51 + if($domainInfo !== false){
  52 + $this->curlDelRoute($domainInfo['domain'],$v['project_id']);
  53 + }
  54 + }
  55 + sleep(10);
  56 + }
  57 +
  58 + }
  59 +
  60 + /**
  61 + * @remark :更新关键词内容
  62 + * @name :saveKeywordContent
  63 + * @author :lyh
  64 + * @method :post
  65 + * @time :2024/7/3 10:25
  66 + */
  67 + public function saveKeywordContent($info){
  68 + $keywordModel = new Keyword();
  69 + $updateObject = json_decode($info['update_object'],true);
  70 + $text = json_decode($info['text'],true);
  71 + if(empty($text)){
  72 + return false;
  73 + }
  74 + $number = count($info['text']);
  75 + $randomNumber = rand(0, $number - 1);
  76 + if($updateObject['type'] == 0){//更新所有关键字
  77 + $keywordModel->edit(['keyword_content'=>$text[$randomNumber]],['status'=>1]);
  78 + }else{
  79 + //按传递的关键字更新
  80 + if(!empty($updateObject['keyword'])){
  81 + $updateObject['keyword'] = (array)$updateObject['keyword'];
  82 + $keywordModel->edit(['keyword_content'=>$text[$randomNumber]],['title'=>['in',$updateObject['keyword']]]);
  83 + }
  84 + //按给定的数量更新
  85 + if(!empty($updateObject['number']) && ($updateObject['number'] != 0)){
  86 + $keywordIdArr = $keywordModel->where("status",1)->inRandomOrder()->take($updateObject['number'])->pluck('id')->toArray();
  87 + $keywordModel->edit(['keyword_content'=>$text[$randomNumber]],['id'=>['in',$keywordIdArr]]);
  88 + }
  89 + }
  90 + return true;
  91 + }
  92 +
  93 + /**
  94 + * @remark :删除路由通知C端
  95 + * @name :curlDelRoute
  96 + * @author :lyh
  97 + * @method :post
  98 + * @time :2023/11/30 14:43
  99 + */
  100 + public function curlDelRoute($domain,$project_id){
  101 + if (strpos($domain, 'https://') === false) {
  102 + $domain = 'https://' . $domain . '/';
  103 + }
  104 + $url = $domain.'api/update_page/?project_id='.$project_id.'&route=4';
  105 + shell_exec('curl -k "'.$url.'"');
  106 + return true;
  107 + }
  108 +}
@@ -49,6 +49,8 @@ class Kernel extends ConsoleKernel @@ -49,6 +49,8 @@ class Kernel extends ConsoleKernel
49 $schedule->command('update_keyword_route')->dailyAt('01:00')->withoutOverlapping(1); //升级项目--清除路由相同的关键字 49 $schedule->command('update_keyword_route')->dailyAt('01:00')->withoutOverlapping(1); //升级项目--清除路由相同的关键字
50 $schedule->command('recommended_suppliers')->dailyAt('03:00')->withoutOverlapping(1); //每天凌晨1点执行一次生成推荐商 50 $schedule->command('recommended_suppliers')->dailyAt('03:00')->withoutOverlapping(1); //每天凌晨1点执行一次生成推荐商
51 // 每日推送视频任务 51 // 每日推送视频任务
  52 + $schedule->command('update_keyword')->hourly()->withoutOverlapping(1);
  53 + // 每日推送视频任务
52 $schedule->command('video_task')->hourly()->withoutOverlapping(1); 54 $schedule->command('video_task')->hourly()->withoutOverlapping(1);
53 // 每日推送已完成视频任务项目生成对应界面 55 // 每日推送已完成视频任务项目生成对应界面
54 $schedule->command('notice_c')->dailyAt('04:00')->withoutOverlapping(1); 56 $schedule->command('notice_c')->dailyAt('04:00')->withoutOverlapping(1);
@@ -256,6 +256,7 @@ class KeywordController extends BaseController @@ -256,6 +256,7 @@ class KeywordController extends BaseController
256 $keywordPageModel = new KeywordPage(); 256 $keywordPageModel = new KeywordPage();
257 $this->param['text'] = json_encode($this->param['text']); 257 $this->param['text'] = json_encode($this->param['text']);
258 $this->param['update_object'] = json_encode($this->param['update_object']); 258 $this->param['update_object'] = json_encode($this->param['update_object']);
  259 + $this->param['project_id'] = $this->user['project_id'];
259 $id = $keywordPageModel->addReturnId($this->param); 260 $id = $keywordPageModel->addReturnId($this->param);
260 $this->response('success',Code::SUCCESS,['id'=>$id]); 261 $this->response('success',Code::SUCCESS,['id'=>$id]);
261 } 262 }
@@ -268,10 +268,10 @@ class DomainInfoLogic extends BaseLogic @@ -268,10 +268,10 @@ class DomainInfoLogic extends BaseLogic
268 $serverModel = new Servers(); 268 $serverModel = new Servers();
269 $serverInfo = $serverModel->read(['id'=>$serversIpInfo['servers_id']],['init_domain']); 269 $serverInfo = $serverModel->read(['id'=>$serversIpInfo['servers_id']],['init_domain']);
270 $server_info = ['domain'=>$serverInfo['init_domain'],'ip'=>$serversIpInfo['ip']]; 270 $server_info = ['domain'=>$serverInfo['init_domain'],'ip'=>$serversIpInfo['ip']];
271 - if($project_info['serve_id'] == 9){ 271 + if($serversIpInfo['servers_id'] == 7){
272 $this->fail('请切换服务器,生成站点不能使用测试服务器'); 272 $this->fail('请切换服务器,生成站点不能使用测试服务器');
273 } 273 }
274 - if($project_info['serve_id'] == ServerConfig::SELF_SITE_ID){ 274 + if($serversIpInfo['servers_id'] == ServerConfig::SELF_SITE_ID){
275 $this->model->edit(['amp_status' => $this->param['amp_status'] ?? 0,],['id'=>$this->param['id']]); 275 $this->model->edit(['amp_status' => $this->param['amp_status'] ?? 0,],['id'=>$this->param['id']]);
276 $this->fail('自建站服务器无法生成站点'); 276 $this->fail('自建站服务器无法生成站点');
277 } 277 }
@@ -391,6 +391,12 @@ class DomainInfoLogic extends BaseLogic @@ -391,6 +391,12 @@ class DomainInfoLogic extends BaseLogic
391 $serverModel = new Servers(); 391 $serverModel = new Servers();
392 $serverInfo = $serverModel->read(['id'=>$serversIpInfo['servers_id']],['init_domain']); 392 $serverInfo = $serverModel->read(['id'=>$serversIpInfo['servers_id']],['init_domain']);
393 $server_info = ['domain'=>$serverInfo['init_domain'],'ip'=>$serversIpInfo['ip']]; 393 $server_info = ['domain'=>$serverInfo['init_domain'],'ip'=>$serversIpInfo['ip']];
  394 + if($serversIpInfo['servers_id'] == 7){
  395 + $this->fail('请切换服务器,生成站点不能使用测试服务器');
  396 + }
  397 + if($serversIpInfo['servers_id'] == ServerConfig::SELF_SITE_ID){
  398 + $this->fail('自建站服务器无法生成站点');
  399 + }
394 //域名是否都已经解析 400 //域名是否都已经解析
395 if(strpos($this->param['custom_domain'],'//') === false){ 401 if(strpos($this->param['custom_domain'],'//') === false){
396 $this->param['custom_domain'] = '//'.$this->param['custom_domain']; 402 $this->param['custom_domain'] = '//'.$this->param['custom_domain'];
@@ -8,6 +8,7 @@ use App\Exceptions\BsideGlobalException; @@ -8,6 +8,7 @@ use App\Exceptions\BsideGlobalException;
8 use App\Http\Logic\Logic; 8 use App\Http\Logic\Logic;
9 use App\Models\Com\UpdateNotify; 9 use App\Models\Com\UpdateNotify;
10 use App\Models\Devops\ServerConfig; 10 use App\Models\Devops\ServerConfig;
  11 +use App\Models\Devops\ServersIp;
11 use App\Models\Project\Project; 12 use App\Models\Project\Project;
12 use App\Models\RouteMap\RouteDelete; 13 use App\Models\RouteMap\RouteDelete;
13 use App\Models\Service\Service; 14 use App\Models\Service\Service;
@@ -175,11 +176,13 @@ class BaseLogic extends Logic @@ -175,11 +176,13 @@ class BaseLogic extends Logic
175 $data['project_id'] = $this->user['project_id']; 176 $data['project_id'] = $this->user['project_id'];
176 $str = http_build_query($data); 177 $str = http_build_query($data);
177 $url = $this->user['domain'].'api/delHtml/?'.$str; 178 $url = $this->user['domain'].'api/delHtml/?'.$str;
178 - if(isset($this->project['serve_id']) && ($this->project['serve_id'] == ServerConfig::SELF_SITE_ID)){ 179 + $serverIpModel = new ServersIp();
  180 + $serversIpInfo = $serverIpModel->read(['id'=>$this->project['serve_id']],['servers_id']);
  181 + if($serversIpInfo && ($serversIpInfo['servers_id'] == ServerConfig::SELF_SITE_ID)){
179 //自建站服务器直接返回 182 //自建站服务器直接返回
180 return $this->success(); 183 return $this->success();
181 } 184 }
182 - if(isset($this->project['serve_id']) && ($this->project['serve_id'] != 1)){//TODO::当前项目通知不过 ,跳过自动更新 185 + if($serversIpInfo && ($serversIpInfo['servers_id'] != 1)){//TODO::当前项目通知不过 ,跳过自动更新
183 exec('curl -k "'.$url.'" > /dev/null 2>&1 &'); 186 exec('curl -k "'.$url.'" > /dev/null 2>&1 &');
184 }else{ 187 }else{
185 shell_exec('curl -k "'.$url.'"'); 188 shell_exec('curl -k "'.$url.'"');
@@ -14,6 +14,4 @@ use App\Models\Base; @@ -14,6 +14,4 @@ use App\Models\Base;
14 class KeywordPage extends Base 14 class KeywordPage extends Base
15 { 15 {
16 protected $table = 'gl_product_keyword_page'; 16 protected $table = 'gl_product_keyword_page';
17 - //连接数据库  
18 - protected $connection = 'custom_mysql';  
19 } 17 }