作者 lyh

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

@@ -199,17 +199,17 @@ class UpdateSeoTdk extends Command @@ -199,17 +199,17 @@ class UpdateSeoTdk extends Command
199 } 199 }
200 $project_id = $task->project_id; 200 $project_id = $task->project_id;
201 201
202 - echo date('Y-m-d H:i:s') . ' start project_id: ' . $project_id . PHP_EOL; 202 + echo getmypid() . ' ' . date('Y-m-d H:i:s') . ' start project_id: ' . $project_id . PHP_EOL;
203 try { 203 try {
204 $this->project = ProjectServer::useProject($project_id); 204 $this->project = ProjectServer::useProject($project_id);
205 $this->seo_tdk($project_id, $task->id); 205 $this->seo_tdk($project_id, $task->id);
206 DB::disconnect('custom_mysql'); 206 DB::disconnect('custom_mysql');
207 }catch (\Exception $e){ 207 }catch (\Exception $e){
208 - echo date('Y-m-d H:i:s') . 'line: '. $e->getLine() .' error: ' . $project_id . '->' . $e->getMessage() . PHP_EOL; 208 + echo getmypid() . ' ' . date('Y-m-d H:i:s') . 'line: '. $e->getLine() .' error: ' . $project_id . '->' . $e->getMessage() . PHP_EOL;
209 ProjectUpdateTdk::retry($task->id, $e->getMessage()); 209 ProjectUpdateTdk::retry($task->id, $e->getMessage());
210 } 210 }
211 Cache::forget('project_deploy_optimize_info_' . $project_id); 211 Cache::forget('project_deploy_optimize_info_' . $project_id);
212 - echo date('Y-m-d H:i:s') . ' end project_id: ' . $project_id . PHP_EOL; 212 + echo getmypid() . ' ' . date('Y-m-d H:i:s') . ' end project_id: ' . $project_id . PHP_EOL;
213 } 213 }
214 } 214 }
215 public function sendNotify($project_id, $route) 215 public function sendNotify($project_id, $route)
@@ -234,7 +234,7 @@ class UpdateSeoTdk extends Command @@ -234,7 +234,7 @@ class UpdateSeoTdk extends Command
234 'language'=> [], 234 'language'=> [],
235 ]; 235 ];
236 http_post($url, json_encode($param)); 236 http_post($url, json_encode($param));
237 - echo '更新中请稍后, 更新完成将会发送站内信通知更新结果!'. PHP_EOL; 237 + echo getmypid() . ' ' . '更新中请稍后, 更新完成将会发送站内信通知更新结果!'. PHP_EOL;
238 } 238 }
239 public function seo_tdk($project_id, $task_id) 239 public function seo_tdk($project_id, $task_id)
240 { 240 {
@@ -246,7 +246,7 @@ class UpdateSeoTdk extends Command @@ -246,7 +246,7 @@ class UpdateSeoTdk extends Command
246 foreach ($this->maps as $table => $map) { 246 foreach ($this->maps as $table => $map) {
247 $total_page = DB::connection('custom_mysql')->table($table)->count(); 247 $total_page = DB::connection('custom_mysql')->table($table)->count();
248 $update[$table] = ['total_page'=>$total_page, 'title'=>0, 'keyword'=>0, 'des'=>0,'keyword_title'=>0,'keyword_content'=>0]; 248 $update[$table] = ['total_page'=>$total_page, 'title'=>0, 'keyword'=>0, 'des'=>0,'keyword_title'=>0,'keyword_content'=>0];
249 - echo date('Y-m-d H:i:s') . '更新--' . $table . ': 项目id' . $project_id . PHP_EOL; 249 + echo getmypid() . ' ' . date('Y-m-d H:i:s') . '更新--' . $table . ': 项目id' . $project_id . PHP_EOL;
250 $list = DB::connection('custom_mysql')->table($table) 250 $list = DB::connection('custom_mysql')->table($table)
251 ->where(function ($query) use ($table, $map){ 251 ->where(function ($query) use ($table, $map){
252 if($table == 'gl_product'){ 252 if($table == 'gl_product'){
@@ -280,7 +280,7 @@ class UpdateSeoTdk extends Command @@ -280,7 +280,7 @@ class UpdateSeoTdk extends Command
280 } 280 }
281 281
282 282
283 - echo date('Y-m-d H:i:s') . '更新--' . $table . ': 项目id' . $project_id . ':id' . $v['id'] . PHP_EOL; 283 + echo getmypid() . ' ' . date('Y-m-d H:i:s') . '更新--' . $table . ': 项目id' . $project_id . ':id' . $v['id'] . PHP_EOL;
284 $v = DB::connection('custom_mysql')->table($table)->where('id', $v['id'])->first(); 284 $v = DB::connection('custom_mysql')->table($table)->where('id', $v['id'])->first();
285 $v = (array)$v; 285 $v = (array)$v;
286 $data = []; 286 $data = [];
@@ -295,7 +295,7 @@ class UpdateSeoTdk extends Command @@ -295,7 +295,7 @@ class UpdateSeoTdk extends Command
295 } 295 }
296 //已有值的 跳过 296 //已有值的 跳过
297 if ($value) { 297 if ($value) {
298 - echo $field.'已有值 跳过' . PHP_EOL; 298 + echo getmypid() . ' ' . $field.'已有值 跳过' . PHP_EOL;
299 continue; 299 continue;
300 } 300 }
301 301
@@ -423,7 +423,7 @@ class UpdateSeoTdk extends Command @@ -423,7 +423,7 @@ class UpdateSeoTdk extends Command
423 if(strpos($prompt, '{topic}') !== false){ 423 if(strpos($prompt, '{topic}') !== false){
424 $topic = $data[$this->topic_fields[$table]] ?? ''; 424 $topic = $data[$this->topic_fields[$table]] ?? '';
425 if(!$topic){ 425 if(!$topic){
426 - echo 'topic为空 跳过' . PHP_EOL; 426 + echo getmypid() . ' ' . 'topic为空 跳过' . PHP_EOL;
427 return false; 427 return false;
428 } 428 }
429 $prompt = str_replace('{topic}', $topic, $prompt); 429 $prompt = str_replace('{topic}', $topic, $prompt);
@@ -432,7 +432,7 @@ class UpdateSeoTdk extends Command @@ -432,7 +432,7 @@ class UpdateSeoTdk extends Command
432 if(strpos($prompt, '{keyword}') !== false) { 432 if(strpos($prompt, '{keyword}') !== false) {
433 $keyword = $this->mainKeywords($project_id, 1); 433 $keyword = $this->mainKeywords($project_id, 1);
434 if(!$keyword){ 434 if(!$keyword){
435 - echo '核心关键词为空 跳过' . PHP_EOL; 435 + echo getmypid() . ' ' . '核心关键词为空 跳过' . PHP_EOL;
436 return false; 436 return false;
437 } 437 }
438 $prompt = str_replace('{keyword}', $keyword, $prompt); 438 $prompt = str_replace('{keyword}', $keyword, $prompt);
@@ -441,7 +441,7 @@ class UpdateSeoTdk extends Command @@ -441,7 +441,7 @@ class UpdateSeoTdk extends Command
441 if(strpos($prompt, '{company name}') !== false) { 441 if(strpos($prompt, '{company name}') !== false) {
442 $company_name = $this->companyName($project_id); 442 $company_name = $this->companyName($project_id);
443 if(!$company_name){ 443 if(!$company_name){
444 - echo '公司英文全称为空 跳过' . PHP_EOL; 444 + echo getmypid() . ' ' . '公司英文全称为空 跳过' . PHP_EOL;
445 return false; 445 return false;
446 } 446 }
447 $prompt = str_replace('{company name}', $company_name, $prompt); 447 $prompt = str_replace('{company name}', $company_name, $prompt);
@@ -450,7 +450,7 @@ class UpdateSeoTdk extends Command @@ -450,7 +450,7 @@ class UpdateSeoTdk extends Command
450 if(strpos($prompt, '{company detail}') !== false) { 450 if(strpos($prompt, '{company detail}') !== false) {
451 $company_detail = $this->companyName($project_id, 'company_detail'); 451 $company_detail = $this->companyName($project_id, 'company_detail');
452 if(!$company_detail){ 452 if(!$company_detail){
453 - echo '公司英文描述为空 跳过' . PHP_EOL; 453 + echo getmypid() . ' ' . '公司英文描述为空 跳过' . PHP_EOL;
454 return false; 454 return false;
455 } 455 }
456 $prompt = str_replace('{company detail}', $company_detail, $prompt); 456 $prompt = str_replace('{company detail}', $company_detail, $prompt);
@@ -460,7 +460,7 @@ class UpdateSeoTdk extends Command @@ -460,7 +460,7 @@ class UpdateSeoTdk extends Command
460 foreach ($matches[0] as $key=>$val) { 460 foreach ($matches[0] as $key=>$val) {
461 $keyword = $this->getPrefixKeyword($project_id, 'prefix', $matches[1][$key]); 461 $keyword = $this->getPrefixKeyword($project_id, 'prefix', $matches[1][$key]);
462 if(!$keyword){ 462 if(!$keyword){
463 - echo '前缀关键词为空 跳过' . PHP_EOL; 463 + echo getmypid() . ' ' . '前缀关键词为空 跳过' . PHP_EOL;
464 return false; 464 return false;
465 } 465 }
466 $prompt = str_replace($val, $keyword, $prompt); 466 $prompt = str_replace($val, $keyword, $prompt);
@@ -471,7 +471,7 @@ class UpdateSeoTdk extends Command @@ -471,7 +471,7 @@ class UpdateSeoTdk extends Command
471 foreach ($matches[0] as $key=>$val) { 471 foreach ($matches[0] as $key=>$val) {
472 $keyword = $this->getPrefixKeyword($project_id, 'suffix', $matches[1][$key]); 472 $keyword = $this->getPrefixKeyword($project_id, 'suffix', $matches[1][$key]);
473 if(!$keyword){ 473 if(!$keyword){
474 - echo '前缀关键词为空 跳过' . PHP_EOL; 474 + echo getmypid() . ' ' . '前缀关键词为空 跳过' . PHP_EOL;
475 return false; 475 return false;
476 } 476 }
477 $prompt = str_replace($val, $keyword, $prompt); 477 $prompt = str_replace($val, $keyword, $prompt);
@@ -482,7 +482,7 @@ class UpdateSeoTdk extends Command @@ -482,7 +482,7 @@ class UpdateSeoTdk extends Command
482 if(strpos($prompt, '{core keywords 8}') !== false) { 482 if(strpos($prompt, '{core keywords 8}') !== false) {
483 $main_keyword = $this->mainKeywords($project_id, 8); 483 $main_keyword = $this->mainKeywords($project_id, 8);
484 if(!$main_keyword){ 484 if(!$main_keyword){
485 - echo '核心关键词为空 跳过' . PHP_EOL; 485 + echo getmypid() . ' ' . '核心关键词为空 跳过' . PHP_EOL;
486 return false; 486 return false;
487 } 487 }
488 $prompt = str_replace('{core keywords 8}', $main_keyword, $prompt); 488 $prompt = str_replace('{core keywords 8}', $main_keyword, $prompt);
@@ -592,6 +592,8 @@ class UpdateSeoTdk extends Command @@ -592,6 +592,8 @@ class UpdateSeoTdk extends Command
592 $text = Gpt::instance()->openai_chat_qqs($prompt); 592 $text = Gpt::instance()->openai_chat_qqs($prompt);
593 593
594 if (!$text) { 594 if (!$text) {
  595 + echo getmypid() . ' ' . '生成失败' . PHP_EOL;
  596 +
595 $cache_key = "ai_error_times_{$project_id}_{$table}_{$id}"; 597 $cache_key = "ai_error_times_{$project_id}_{$table}_{$id}";
596 if (!Cache::get($cache_key)) { 598 if (!Cache::get($cache_key)) {
597 Cache::put($cache_key, 0, 7 * 24 * 3600); 599 Cache::put($cache_key, 0, 7 * 24 * 3600);
@@ -37,7 +37,94 @@ class Temp extends Command @@ -37,7 +37,94 @@ class Temp extends Command
37 37
38 public function handle() 38 public function handle()
39 { 39 {
40 - $this->check_cname_projects(); 40 + $this->change_cname_projects_240();
  41 + }
  42 +
  43 + /**
  44 + * 240服务器上解析cname的项目迁移
  45 + * @author Akun
  46 + * @date 2025/02/17 14:21
  47 + */
  48 + public function change_cname_projects_240()
  49 + {
  50 + $server_ip_model = new ServersIp();
  51 +
  52 + $server_ip_ids = $server_ip_model->where('servers_id', 1)->get()->pluck('id')->toArray();
  53 +
  54 + $project_list = Project::select(['id', 'serve_id'])->whereIn('serve_id', $server_ip_ids)->get();
  55 +
  56 + $domain_model = new DomainInfo();
  57 + foreach ($project_list as $value) {
  58 + $project_id = $value->id;
  59 +
  60 + $domain_info = $domain_model->read(['project_id' => $project_id, 'status' => 1], ['id', 'domain', 'amp_status']);
  61 + if (!$domain_info) {
  62 + //过滤未绑定正式域名的项目
  63 + continue;
  64 + }
  65 + $domain_id = $domain_info['id'];
  66 + $domain = $domain_info['domain'];
  67 +
  68 + //迁移主站
  69 + $check = dns_get_record($domain, DNS_A);
  70 + $host = $check[0]['host'] ?? '';
  71 + if ($host == 'cname.globalso.com') {
  72 + //获取主站备份证书
  73 + $ssl_info = DB::table('gl_domain_ssl_backup')->select(['private_key', 'private_cert'])->where('domain', $domain)->first();
  74 + if (!$ssl_info) {
  75 + $this->output('项目id:' . $project_id . ' | 未备份主站证书');
  76 + continue;
  77 + }
  78 +
  79 + //创建主站建站任务
  80 + $task_info = DomainCreateTask::where('type', 1)->where('server_id', 20)->where('project_id', $project_id)->first();
  81 + if (!$task_info) {
  82 + $task_model = new DomainCreateTask();
  83 + $task_model->type = 1;
  84 + $task_model->server_id = 20;
  85 + $task_model->project_id = $project_id;
  86 + $task_model->domain_id = $domain_id;
  87 + $task_model->certs = json_encode(['key' => $ssl_info->private_key, 'csr' => $ssl_info->private_cert]);
  88 + $task_model->save();
  89 + }
  90 + }
  91 +
  92 + if ($domain_info['amp_status'] == 1) {
  93 + //迁移amp站
  94 + $domain_array = parse_url($domain);
  95 + $host = $domain_array['host'] ?? $domain_array['path'];
  96 + $host_array = explode('.', $host);
  97 + if (count($host_array) <= 2) {
  98 + array_unshift($host_array, 'm');
  99 + } else {
  100 + $host_array[0] = 'm';
  101 + }
  102 + $amp_domain = implode('.', $host_array);
  103 +
  104 + $check_amp = dns_get_record($amp_domain, DNS_A);
  105 + $host_amp = $check_amp[0]['host'] ?? '';
  106 + if ($host_amp == 'cname.globalso.com') {
  107 + //获取amp站备份证书
  108 + $ssl_info_amp = DB::table('gl_domain_ssl_backup')->select(['private_key', 'private_cert'])->where('domain', $amp_domain)->first();
  109 + if (!$ssl_info_amp) {
  110 + $this->output('项目id:' . $project_id . ' | 未备份amp站证书');
  111 + continue;
  112 + }
  113 +
  114 + //创建amp站建站任务
  115 + $task_info_amp = DomainCreateTask::where('type', 2)->where('server_id', 20)->where('project_id', $project_id)->first();
  116 + if (!$task_info_amp) {
  117 + $task_model = new DomainCreateTask();
  118 + $task_model->type = 2;
  119 + $task_model->server_id = 20;
  120 + $task_model->project_id = $project_id;
  121 + $task_model->domain_id = $domain_id;
  122 + $task_model->certs = json_encode(['key' => $ssl_info_amp->private_key, 'csr' => $ssl_info_amp->private_cert]);
  123 + $task_model->save();
  124 + }
  125 + }
  126 + }
  127 + }
41 } 128 }
42 129
43 /** 130 /**
@@ -426,59 +513,6 @@ class Temp extends Command @@ -426,59 +513,6 @@ class Temp extends Command
426 } 513 }
427 514
428 /** 515 /**
429 - * 检查服务器上解析cname的项目  
430 - * @author Akun  
431 - * @date 2025/02/17 14:21  
432 - */  
433 - public function check_cname_projects()  
434 - {  
435 - $server_id = 1;  
436 - $server_name = '硅谷云服务器';  
437 -  
438 - $server_ip_model = new ServersIp();  
439 -  
440 - $server_ip_ids = $server_ip_model->where('servers_id', $server_id)->get()->pluck('id')->toArray();  
441 -  
442 - $project_list = Project::select(['id', 'serve_id', 'title'])->whereIn('serve_id', $server_ip_ids)->get();  
443 -  
444 - $domain_model = new DomainInfo();  
445 - $data = [];  
446 - foreach ($project_list as $value) {  
447 - $domain_info = $domain_model->read(['project_id' => $value->id, 'status' => 1], ['id', 'domain']);  
448 - if (!$domain_info) {  
449 - //过滤未绑定正式域名的项目  
450 - continue;  
451 - }  
452 - $domain = $domain_info['domain'];  
453 -  
454 - $check = dns_get_record($domain, DNS_A);  
455 - $ip = $check[0]['ip'] ?? '';  
456 - $host = $check[0]['host'] ?? '';  
457 - if ($host == 'cname.globalso.com') {  
458 - $data[] = [  
459 - $value->id,  
460 - $value->title,  
461 - $domain,  
462 - $ip  
463 - ];  
464 - }  
465 - }  
466 - $map = ['项目id', '名称', '域名', '解析IP'];  
467 - if ($data) {  
468 - $table = new BatchExportService($server_name . '解析cname的项目');  
469 - $file = $table->head($map)->data($data)->save();  
470 - if (!$file) {  
471 - $this->output('文件生成失败,请重试');  
472 - } else {  
473 - $this->output('export success');  
474 - }  
475 - } else {  
476 - $this->output('no data');  
477 - }  
478 - }  
479 -  
480 -  
481 - /**  
482 * 检查不在所属服务器解析上的域名 516 * 检查不在所属服务器解析上的域名
483 * @author Akun 517 * @author Akun
484 * @date 2024/09/26 10:48 518 * @date 2024/09/26 10:48
@@ -75,6 +75,7 @@ class Gpt @@ -75,6 +75,7 @@ class Gpt
75 $json = []; 75 $json = [];
76 } 76 }
77 } catch (\Throwable $e) { 77 } catch (\Throwable $e) {
  78 + Log::error('openai_chat_qqs data:', $data);
78 Log::error('openai_chat_qqs time ' . (time() - $time) . ' error:' . $e->getMessage()); 79 Log::error('openai_chat_qqs time ' . (time() - $time) . ' error:' . $e->getMessage());
79 $json = []; 80 $json = [];
80 } 81 }