作者 刘锟

update

@@ -4,6 +4,7 @@ namespace App\Http\Logic\Aside\Domain; @@ -4,6 +4,7 @@ namespace App\Http\Logic\Aside\Domain;
4 4
5 5
6 use App\Http\Logic\Aside\BaseLogic; 6 use App\Http\Logic\Aside\BaseLogic;
  7 +use App\Jobs\EditAmpDomainBt;
7 use App\Jobs\EditCustomDomainBt; 8 use App\Jobs\EditCustomDomainBt;
8 use App\Jobs\EditDomainBt; 9 use App\Jobs\EditDomainBt;
9 use App\Models\Devops\ServerConfig; 10 use App\Models\Devops\ServerConfig;
@@ -303,14 +304,15 @@ class DomainInfoLogic extends BaseLogic @@ -303,14 +304,15 @@ class DomainInfoLogic extends BaseLogic
303 'amp_private_cert' => $this->param['amp_cert'] ?? '', 304 'amp_private_cert' => $this->param['amp_cert'] ?? '',
304 ]; 305 ];
305 $this->model->edit($data,['id'=>$this->param['id']]); 306 $this->model->edit($data,['id'=>$this->param['id']]);
306 - //生成证书 307 + //主站生成证书
307 EditDomainBt::dispatch($this->param['id']); 308 EditDomainBt::dispatch($this->param['id']);
308 // $this->setDomainSsl($server_info['init_domain'],$info['domain'],$this->param['extend_config'] ?? [],$this->param['other_domain'] ?? [],$this->param['is_https'] ?? 0); 309 // $this->setDomainSsl($server_info['init_domain'],$info['domain'],$this->param['extend_config'] ?? [],$this->param['other_domain'] ?? [],$this->param['is_https'] ?? 0);
309 310
310 - //amp站点生成证书  
311 -// if($data['amp_status']){ 311 + //amp站生成证书
  312 + if($data['amp_status']){
  313 + EditAmpDomainBt::dispatch($this->param['id']);
312 // $this->setAmpDomainSsl($server_info['init_domain'],$info['domain']); 314 // $this->setAmpDomainSsl($server_info['init_domain'],$info['domain']);
313 -// } 315 + }
314 316
315 return $this->success(); 317 return $this->success();
316 } 318 }
@@ -80,6 +80,9 @@ class WebSettingAmpLogic extends BaseLogic @@ -80,6 +80,9 @@ class WebSettingAmpLogic extends BaseLogic
80 //icon处理 80 //icon处理
81 $this->param['web_icon'] = str_replace_url($this->param['web_icon'] ?? ''); 81 $this->param['web_icon'] = str_replace_url($this->param['web_icon'] ?? '');
82 82
  83 + $this->param['company_skype'] = $this->param['company_skype'] ?? '';
  84 + $this->param['company_whatsapp'] = $this->param['company_whatsapp'] ?? '';
  85 +
83 $info = $this->model->read(['project_id' => $this->user['project_id']]); 86 $info = $this->model->read(['project_id' => $this->user['project_id']]);
84 if ($info === false) { 87 if ($info === false) {
85 $this->param['project_id'] = $this->user['project_id']; 88 $this->param['project_id'] = $this->user['project_id'];
  1 +<?php
  2 +
  3 +namespace App\Jobs;
  4 +
  5 +use App\Models\Devops\ServerConfig;
  6 +use App\Models\Domain\DomainInfo;
  7 +use App\Models\Project\Project;
  8 +use App\Utils\HttpUtils;
  9 +use GuzzleHttp\Exception\GuzzleException;
  10 +use Illuminate\Bus\Queueable;
  11 +use Illuminate\Contracts\Queue\ShouldQueue;
  12 +use Illuminate\Foundation\Bus\Dispatchable;
  13 +use Illuminate\Queue\InteractsWithQueue;
  14 +use Illuminate\Queue\SerializesModels;
  15 +
  16 +class EditAmpDomainBt implements ShouldQueue
  17 +{
  18 + use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
  19 +
  20 + public $tries = 1; // 可配置任务重试次数
  21 +
  22 + protected $domain_id;
  23 +
  24 + /**
  25 + * Create a new job instance.
  26 + *
  27 + * @param $domain_id
  28 + */
  29 + public function __construct($domain_id)
  30 + {
  31 + $this->domain_id = $domain_id;
  32 + }
  33 +
  34 + /**
  35 + * Execute the job.
  36 + *
  37 + * @return bool
  38 + */
  39 + public function handle()
  40 + {
  41 + //获取域名数据
  42 + $domain_model = new DomainInfo();
  43 + $domain_info = $domain_model->read(['id' => $this->domain_id]);
  44 + if ($domain_info === false) {
  45 + return $this->output($domain_info['domain'] . ':获取域名数据失败');
  46 + }
  47 +
  48 + //获取项目数据
  49 + $project_model = new Project();
  50 + $project_info = $project_model->read(['id' => $domain_info['project_id']], 'serve_id');
  51 + if ($project_info === false) {
  52 + return $this->output($domain_info['domain'] . ':获取项目数据失败');
  53 + }
  54 +
  55 + //获取服务器数据
  56 + $server_model = new ServerConfig();
  57 + $server_info = $server_model->read(['id' => $project_info['serve_id']], ['init_domain', 'host']);
  58 + if ($server_info === false) {
  59 + return $this->output($domain_info['domain'] . ':获取服务器数据失败');
  60 + }
  61 +
  62 + //编辑amp站
  63 + $api_url_amp = 'http://' . $server_info['init_domain'] . '/api/createSiteAmp';
  64 + $api_param_amp = [
  65 + 'domain' => $domain_info['domain'],
  66 + ];
  67 + if ($domain_info['amp_type'] == 2) {
  68 + $api_param_amp['private_key'] = $domain_info['amp_private_key'];
  69 + $api_param_amp['cert'] = $domain_info['amp_private_cert'];
  70 + }
  71 +
  72 + try {
  73 + $rs_amp = HttpUtils::get($api_url_amp, $api_param_amp);
  74 + $rs_amp = json_decode($rs_amp, true);
  75 + if (isset($rs_amp['status']) && $rs_amp['status'] == 200) {
  76 + $this->output($domain_info['domain'] . ':amp站编辑成功');
  77 + } else {
  78 + $this->output($domain_info['domain'] . ':amp站编辑失败,原因:' . ($rs_amp['message'] ?? ''));
  79 + }
  80 + } catch (\Exception | GuzzleException $e_amp) {
  81 + $this->output($domain_info['domain'] . ':amp站编辑失败,原因:' . $e_amp->getMessage());
  82 + }
  83 +
  84 + return true;
  85 + }
  86 +
  87 + /**
  88 + * 输出处理日志
  89 + * @param $message
  90 + * @return bool
  91 + */
  92 + public function output($message)
  93 + {
  94 + echo date('Y-m-d H:i:s') . ' | ' . $message . PHP_EOL;
  95 + return true;
  96 + }
  97 +
  98 + public function failed(\Exception $exception)
  99 + {
  100 + return $this->output($exception->getMessage());
  101 + }
  102 +}
@@ -79,6 +79,7 @@ class EditDomainBt implements ShouldQueue @@ -79,6 +79,7 @@ class EditDomainBt implements ShouldQueue
79 'is_https' => $domain_info['is_https'] 79 'is_https' => $domain_info['is_https']
80 ]; 80 ];
81 } 81 }
  82 +
82 try { 83 try {
83 $rs = HttpUtils::get($api_url, $api_param); 84 $rs = HttpUtils::get($api_url, $api_param);
84 $rs = json_decode($rs, true); 85 $rs = json_decode($rs, true);
@@ -91,30 +92,6 @@ class EditDomainBt implements ShouldQueue @@ -91,30 +92,6 @@ class EditDomainBt implements ShouldQueue
91 $this->output($domain_info['domain'] . ':主站编辑失败,原因:' . $e->getMessage()); 92 $this->output($domain_info['domain'] . ':主站编辑失败,原因:' . $e->getMessage());
92 } 93 }
93 94
94 - //编辑amp站  
95 - if ($domain_info['amp_status']) {  
96 - $api_url_amp = 'http://' . $server_info['init_domain'] . '/api/createSiteAmp';  
97 - $api_param_amp = [  
98 - 'domain' => $domain_info['domain'],  
99 - ];  
100 - if ($domain_info['amp_type'] == 2) {  
101 - $api_param_amp['private_key'] = $domain_info['amp_private_key'];  
102 - $api_param_amp['cert'] = $domain_info['amp_private_cert'];  
103 - }  
104 -  
105 - try {  
106 - $rs_amp = HttpUtils::get($api_url_amp, $api_param_amp);  
107 - $rs_amp = json_decode($rs_amp, true);  
108 - if (isset($rs_amp['status']) && $rs_amp['status'] == 200) {  
109 - $this->output($domain_info['domain'] . ':amp站编辑成功');  
110 - } else {  
111 - $this->output($domain_info['domain'] . ':amp站编辑失败,原因:' . ($rs_amp['message'] ?? ''));  
112 - }  
113 - } catch (\Exception | GuzzleException $e_amp) {  
114 - $this->output($domain_info['domain'] . ':amp站编辑失败,原因:' . $e_amp->getMessage());  
115 - }  
116 - }  
117 -  
118 return true; 95 return true;
119 } 96 }
120 97