作者 刘锟

合并分支 'akun' 到 'master'

Akun



查看合并请求 !459
@@ -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\EditCustomDomainBt;
7 use App\Jobs\EditDomainBt; 8 use App\Jobs\EditDomainBt;
8 use App\Models\Devops\ServerConfig; 9 use App\Models\Devops\ServerConfig;
9 use App\Models\Domain\DomainInfo; 10 use App\Models\Domain\DomainInfo;
@@ -403,16 +404,18 @@ class DomainInfoLogic extends BaseLogic @@ -403,16 +404,18 @@ class DomainInfoLogic extends BaseLogic
403 $info = $custom_model->read(['project_id'=>$project_id,'language_id'=>$this->param['language_id']]); 404 $info = $custom_model->read(['project_id'=>$project_id,'language_id'=>$this->param['language_id']]);
404 if($info === false){ 405 if($info === false){
405 $this->param['project_id'] = $project_id; 406 $this->param['project_id'] = $project_id;
406 - $custom_model->add($this->param); 407 + $id = $custom_model->addReturnId($this->param);
407 }else{ 408 }else{
408 $custom_model->edit($this->param,['id'=>$info['id']]); 409 $custom_model->edit($this->param,['id'=>$info['id']]);
  410 + $id = $info['id'];
409 } 411 }
410 412
411 if($this->param['is_create']){ 413 if($this->param['is_create']){
412 //创建站点,设置证书 414 //创建站点,设置证书
413 - $this->param['key'] = $this->param['private_key'] ?? '';  
414 - $this->param['cert'] = $this->param['private_cert'] ?? '';  
415 - $this->setDomainSsl($server_info['init_domain'],$this->param['custom_domain'],[],[],1); 415 + EditCustomDomainBt::dispatch($id);
  416 +// $this->param['key'] = $this->param['private_key'] ?? '';
  417 +// $this->param['cert'] = $this->param['private_cert'] ?? '';
  418 +// $this->setDomainSsl($server_info['init_domain'],$this->param['custom_domain'],[],[],1);
416 } 419 }
417 420
418 return $this->success(); 421 return $this->success();
  1 +<?php
  2 +
  3 +namespace App\Jobs;
  4 +
  5 +use App\Models\Devops\ServerConfig;
  6 +use App\Models\Project\CountryCustom;
  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 EditCustomDomainBt 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 CountryCustom();
  43 + $domain_info = $domain_model->read(['id' => $this->domain_id]);
  44 + if ($domain_info === false) {
  45 + return $this->output($domain_info['custom_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['custom_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['custom_domain'] . ':获取服务器数据失败');
  60 + }
  61 +
  62 + //编辑站点
  63 + if ($domain_info['type'] == 2) {
  64 + $api_url = 'http://' . $server_info['init_domain'] . '/api/setSsl';
  65 + $api_param = [
  66 + 'domain' => $domain_info['custom_domain'],
  67 + 'private_key' => $domain_info['private_key'],
  68 + 'cert' => $domain_info['private_cert'],
  69 + 'rewrite' => [],
  70 + 'other_domain' => [],
  71 + 'is_https' => 1
  72 + ];
  73 + } else {
  74 + $api_url = 'http://' . $server_info['init_domain'] . '/api/applySsl';
  75 + $api_param = [
  76 + 'domain' => $domain_info['custom_domain'],
  77 + 'rewrite' => [],
  78 + 'other_domain' => [],
  79 + 'is_https' => 1
  80 + ];
  81 + }
  82 + try {
  83 + $rs = HttpUtils::get($api_url, $api_param);
  84 + $rs = json_decode($rs, true);
  85 + if (isset($rs['status']) && $rs['status'] == 200) {
  86 + $this->output($domain_info['custom_domain'] . ':站点编辑成功');
  87 + } else {
  88 + $this->output($domain_info['custom_domain'] . ':站点编辑失败,原因:' . ($rs['message'] ?? ''));
  89 + }
  90 + } catch (\Exception | GuzzleException $e) {
  91 + $this->output($domain_info['custom_domain'] . ':站点编辑失败,原因:' . $e->getMessage());
  92 + }
  93 +
  94 + return true;
  95 + }
  96 +
  97 + /**
  98 + * 输出处理日志
  99 + * @param $message
  100 + * @return bool
  101 + */
  102 + public function output($message)
  103 + {
  104 + echo date('Y-m-d H:i:s') . ' | ' . $message . PHP_EOL;
  105 + return true;
  106 + }
  107 +
  108 + public function failed(\Exception $exception)
  109 + {
  110 + return $this->output($exception->getMessage());
  111 + }
  112 +}