作者 Your Name
  1 +<?php
  2 +
  3 +namespace App\Console\Commands\Domain;
  4 +
  5 +use App\Models\Devops\Servers;
  6 +use App\Models\Devops\ServersIp;
  7 +use App\Models\Domain\DomainCreateTask;
  8 +use App\Models\Domain\DomainInfo;
  9 +use App\Models\Project\Project;
  10 +use App\Utils\HttpUtils;
  11 +use GuzzleHttp\Exception\GuzzleException;
  12 +use Illuminate\Console\Command;
  13 +
  14 +class CreateSite extends Command
  15 +{
  16 + /**
  17 + * The name and signature of the console command.
  18 + *
  19 + * @var string
  20 + */
  21 + protected $signature = 'create_domain_site';
  22 +
  23 + /**
  24 + * The console command description.
  25 + *
  26 + * @var string
  27 + */
  28 + protected $description = '创建域名站点';
  29 +
  30 + public function handle()
  31 + {
  32 + $model = new DomainCreateTask();
  33 +
  34 + $task = $model->read(['status' => DomainCreateTask::STATUS_UN]);
  35 + if ($task) {
  36 + $model->edit(['status' => DomainCreateTask::STATUS_ING], ['id' => $task['id']]);
  37 +
  38 + $re = $this->editDomainBt($task['domain_id']);
  39 +
  40 + if (is_array($re)) {
  41 + $model->edit(['status' => DomainCreateTask::STATUS_FAL, 'error_msg' => $re[1]], ['id' => $task['id']]);
  42 + } else {
  43 + $model->edit(['status' => DomainCreateTask::STATUS_SUC], ['id' => $task['id']]);
  44 + }
  45 + }
  46 + }
  47 +
  48 + protected function editDomainBt($domain_id)
  49 + {
  50 + //获取域名数据
  51 + $domain_model = new DomainInfo();
  52 + $domain_info = $domain_model->read(['id' => $domain_id]);
  53 + if ($domain_info === false) {
  54 + return [false, '获取域名数据失败'];
  55 + }
  56 +
  57 + //获取项目数据
  58 + $project_model = new Project();
  59 + $project_info = $project_model->read(['id' => $domain_info['project_id']], 'serve_id');
  60 + if ($project_info === false) {
  61 + return [false, '获取项目数据失败'];
  62 + }
  63 +
  64 + //获取服务器数据
  65 + $serverIpModel = new ServersIp();
  66 + $serversIpInfo = $serverIpModel->read(['id' => $project_info['serve_id']], ['servers_id']);
  67 + if ($serversIpInfo === false) {
  68 + return [false, '获取服务器数据失败1'];
  69 + }
  70 + $serverModel = new Servers();
  71 + $serverInfo = $serverModel->read(['id' => $serversIpInfo['servers_id']], ['init_domain']);
  72 + if ($serverInfo === false) {
  73 + return [false, '获取服务器数据失败2'];
  74 + }
  75 +
  76 + /*****************编辑主站*******************/
  77 + if ($domain_info['type'] == 2) {
  78 + $api_url = 'http://' . $serverInfo['init_domain'] . '/api/setSsl';
  79 + $api_param = [
  80 + 'domain' => $domain_info['domain'],
  81 + 'private_key' => $domain_info['private_key'],
  82 + 'cert' => $domain_info['private_cert'],
  83 + 'rewrite' => $domain_info['extend_config'],
  84 + 'other_domain' => $domain_info['other_domain'],
  85 + 'is_https' => $domain_info['is_https'],
  86 + 'not_allow_country' => $domain_info['not_allow_country'],
  87 + 'not_allow_ip' => $domain_info['not_allow_ip'],
  88 + 'is_redirect' => $domain_info['is_redirect']
  89 + ];
  90 + } else {
  91 + $api_url = 'http://' . $serverInfo['init_domain'] . '/api/applySsl';
  92 + $api_param = [
  93 + 'domain' => $domain_info['domain'],
  94 + 'rewrite' => $domain_info['extend_config'],
  95 + 'other_domain' => $domain_info['other_domain'],
  96 + 'is_https' => $domain_info['is_https'],
  97 + 'not_allow_country' => $domain_info['not_allow_country'],
  98 + 'not_allow_ip' => $domain_info['not_allow_ip'],
  99 + 'is_redirect' => $domain_info['is_redirect']
  100 + ];
  101 + }
  102 +
  103 + try {
  104 + $rs = HttpUtils::get($api_url, $api_param);
  105 + $rs = json_decode($rs, true);
  106 + if (isset($rs['status']) && $rs['status'] == 200) {
  107 + $this->output($domain_info['domain'] . ',主站创建成功');
  108 + } else {
  109 + return [false, '主站:' . ($rs['message'] ?? '未知错误')];
  110 + }
  111 + } catch (\Exception | GuzzleException $e) {
  112 + return [false, '主站:' . $e->getMessage()];
  113 + }
  114 +
  115 + /*****************编辑amp站*******************/
  116 + if ($domain_info['amp_status']) {
  117 + $api_url_amp = 'http://' . $serverInfo['init_domain'] . '/api/createSiteAmp';
  118 + $api_param_amp = [
  119 + 'domain' => $domain_info['domain'],
  120 + 'not_allow_country' => $domain_info['not_allow_country'],
  121 + 'not_allow_ip' => $domain_info['not_allow_ip'],
  122 + 'is_redirect' => $domain_info['is_redirect']
  123 + ];
  124 + if ($domain_info['amp_type'] == 2) {
  125 + $api_param_amp['private_key'] = $domain_info['amp_private_key'];
  126 + $api_param_amp['cert'] = $domain_info['amp_private_cert'];
  127 + }
  128 +
  129 + try {
  130 + $rs_amp = HttpUtils::get($api_url_amp, $api_param_amp);
  131 + $rs_amp = json_decode($rs_amp, true);
  132 + if (isset($rs_amp['status']) && $rs_amp['status'] == 200) {
  133 + $this->output($domain_info['domain'] . ',amp站创建成功');
  134 + } else {
  135 + return [false, 'amp站:' . ($rs['message'] ?? '未知错误')];
  136 + }
  137 + } catch (\Exception | GuzzleException $e_amp) {
  138 + return [false, 'amp站:' . $e_amp->getMessage()];
  139 + }
  140 + }
  141 +
  142 + return true;
  143 + }
  144 +
  145 + /**
  146 + * 输出处理日志
  147 + * @param $message
  148 + */
  149 + public function output($message)
  150 + {
  151 + echo date('Y-m-d H:i:s') . ' | ' . $message . PHP_EOL;
  152 + }
  153 +}
@@ -317,21 +317,33 @@ class DomainInfoLogic extends BaseLogic @@ -317,21 +317,33 @@ class DomainInfoLogic extends BaseLogic
317 ]; 317 ];
318 $this->model->edit($data,['id'=>$this->param['id']]); 318 $this->model->edit($data,['id'=>$this->param['id']]);
319 319
320 - //新建站任务 320 + //新建站任务
321 $task_model = new DomainCreateTask(); 321 $task_model = new DomainCreateTask();
322 - $task_info = $task_model->read(['domain_id'=>$this->param['id'],'status'=>['<',DomainCreateTask::STATUS_SUC]]); 322 + $task_info = $task_model->read(['type'=>DomainCreateTask::TYPE_MAIN,'domain_id'=>$this->param['id'],'status'=>['<',DomainCreateTask::STATUS_SUC]]);
323 if(!$task_info){ 323 if(!$task_info){
324 $task_model->add([ 324 $task_model->add([
325 'project_id' => $info['project_id'], 325 'project_id' => $info['project_id'],
326 - 'domain_id' => $this->param['id'] 326 + 'domain_id' => $this->param['id'],
  327 + 'type' => DomainCreateTask::TYPE_MAIN
327 ]); 328 ]);
328 } 329 }
329 - //主站生成证书  
330 - EditDomainBt::dispatch($this->param['id']);  
331 - //amp站生成证书  
332 if($data['amp_status']){ 330 if($data['amp_status']){
333 - EditAmpDomainBt::dispatch($this->param['id']); 331 + $task_amp_info = $task_model->read(['type'=>DomainCreateTask::TYPE_AMP,'domain_id'=>$this->param['id'],'status'=>['<',DomainCreateTask::STATUS_SUC]]);
  332 + if(!$task_amp_info){
  333 + $task_model->add([
  334 + 'project_id' => $info['project_id'],
  335 + 'domain_id' => $this->param['id'],
  336 + 'type' => DomainCreateTask::TYPE_AMP
  337 + ]);
334 } 338 }
  339 + }
  340 +
  341 +// //主站生成证书
  342 +// EditDomainBt::dispatch($this->param['id']);
  343 +// //amp站生成证书
  344 +// if($data['amp_status']){
  345 +// EditAmpDomainBt::dispatch($this->param['id']);
  346 +// }
335 return $this->success(); 347 return $this->success();
336 } 348 }
337 349
@@ -451,7 +451,7 @@ class RankDataLogic extends BaseLogic @@ -451,7 +451,7 @@ class RankDataLogic extends BaseLogic
451 $first_num = $first_page_num = $first_three_pages_num = $first_five_pages_num = $first_ten_pages_num = 0; 451 $first_num = $first_page_num = $first_three_pages_num = $first_five_pages_num = $first_ten_pages_num = 0;
452 $first_page_without_extension_num = 0; //不算扩展词在首页的数量 452 $first_page_without_extension_num = 0; //不算扩展词在首页的数量
453 $first_page_extension_num = 0; //扩展词在首页的数量 453 $first_page_extension_num = 0; //扩展词在首页的数量
454 - 454 + $g_top_first_page_extension_num = 0;
455 foreach ($data as &$ranks){ 455 foreach ($data as &$ranks){
456 ksort($ranks); 456 ksort($ranks);
457 // foreach ($ranks as &$rank){ 457 // foreach ($ranks as &$rank){
@@ -473,6 +473,7 @@ class RankDataLogic extends BaseLogic @@ -473,6 +473,7 @@ class RankDataLogic extends BaseLogic
473 $first_page_num ++; 473 $first_page_num ++;
474 $last['g'] == 1 && $first_page_without_extension_num++; 474 $last['g'] == 1 && $first_page_without_extension_num++;
475 $last['g'] == 2 && $first_page_extension_num++; 475 $last['g'] == 2 && $first_page_extension_num++;
  476 + $last['g'] == 3 && $g_top_first_page_extension_num++;
476 } 477 }
477 //排名前三页 478 //排名前三页
478 if($last['position'] > 0 && $last['position'] <= 30){ 479 if($last['position'] > 0 && $last['position'] <= 30){
@@ -496,7 +497,7 @@ class RankDataLogic extends BaseLogic @@ -496,7 +497,7 @@ class RankDataLogic extends BaseLogic
496 $model = new RankData(); 497 $model = new RankData();
497 } 498 }
498 //g-top方案达标天数 499 //g-top方案达标天数
499 - $this->g_top_plan($project_id,$first_page_without_extension_num); 500 + $this->g_top_plan($project_id,$g_top_first_page_extension_num);
500 //保证关键词数 501 //保证关键词数
501 $keyword_num = DeployBuild::where('project_id', $project_id)->value('keyword_num'); 502 $keyword_num = DeployBuild::where('project_id', $project_id)->value('keyword_num');
502 $type = Project::where('id', $project_id)->value('type'); 503 $type = Project::where('id', $project_id)->value('type');
@@ -12,4 +12,7 @@ class DomainCreateTask extends Base @@ -12,4 +12,7 @@ class DomainCreateTask extends Base
12 const STATUS_ING = 1; 12 const STATUS_ING = 1;
13 const STATUS_SUC = 2; 13 const STATUS_SUC = 2;
14 const STATUS_FAL = 3; 14 const STATUS_FAL = 3;
  15 +
  16 + const TYPE_MAIN = 1;
  17 + const TYPE_AMP = 2;
15 } 18 }