Merge branch 'master' of http://47.244.231.31:8099/zhl/globalso-v6
正在显示
2 个修改的文件
包含
160 行增加
和
7 行删除
app/Console/Commands/Domain/CreateSite.php
0 → 100644
| 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,7 +317,7 @@ class DomainInfoLogic extends BaseLogic | @@ -317,7 +317,7 @@ 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(['domain_id'=>$this->param['id'],'status'=>['<',DomainCreateTask::STATUS_SUC]]); |
| 323 | if(!$task_info){ | 323 | if(!$task_info){ |
| @@ -326,12 +326,12 @@ class DomainInfoLogic extends BaseLogic | @@ -326,12 +326,12 @@ class DomainInfoLogic extends BaseLogic | ||
| 326 | 'domain_id' => $this->param['id'] | 326 | 'domain_id' => $this->param['id'] |
| 327 | ]); | 327 | ]); |
| 328 | } | 328 | } |
| 329 | - //主站生成证书 | ||
| 330 | - EditDomainBt::dispatch($this->param['id']); | ||
| 331 | - //amp站生成证书 | ||
| 332 | - if($data['amp_status']){ | ||
| 333 | - EditAmpDomainBt::dispatch($this->param['id']); | ||
| 334 | - } | 329 | +// //主站生成证书 |
| 330 | +// EditDomainBt::dispatch($this->param['id']); | ||
| 331 | +// //amp站生成证书 | ||
| 332 | +// if($data['amp_status']){ | ||
| 333 | +// EditAmpDomainBt::dispatch($this->param['id']); | ||
| 334 | +// } | ||
| 335 | return $this->success(); | 335 | return $this->success(); |
| 336 | } | 336 | } |
| 337 | 337 |
-
请 注册 或 登录 后发表评论