作者 刘锟

合并分支 'akun' 到 'master'

Akun



查看合并请求 !1594
@@ -11,6 +11,7 @@ namespace App\Http\Logic\Bside\SeoSetting; @@ -11,6 +11,7 @@ namespace App\Http\Logic\Bside\SeoSetting;
11 11
12 use App\Helper\Arr; 12 use App\Helper\Arr;
13 use App\Http\Logic\Bside\BaseLogic; 13 use App\Http\Logic\Bside\BaseLogic;
  14 +use App\Models\Devops\ServerConfig;
14 use App\Models\Devops\Servers; 15 use App\Models\Devops\Servers;
15 use App\Models\Devops\ServersIp; 16 use App\Models\Devops\ServersIp;
16 use App\Models\Domain\DomainCreateTask; 17 use App\Models\Domain\DomainCreateTask;
@@ -81,27 +82,30 @@ class DomainSettingLogic extends BaseLogic @@ -81,27 +82,30 @@ class DomainSettingLogic extends BaseLogic
81 $this->fail('主域名填写错误'); 82 $this->fail('主域名填写错误');
82 } 83 }
83 84
84 - if ($this->param['type'] = WebSetting::SEO_TYPE_PUBLIC) { 85 + //获取项目详情
  86 + $project_model = new Project();
  87 + $project_info = $project_model->read(['id' => $this->user['project_id']], ['company']);
  88 + if (!$project_info) {
  89 + $this->fail('获取项目数据失败');
  90 + }
85 91
  92 + $server_ip_model = new ServersIp();
  93 + $domain_model = new DomainInfo();
  94 + $server_model = new Servers();
  95 + $optimize_model = new DeployOptimize();
  96 + if ($this->param['type'] = WebSetting::SEO_TYPE_PUBLIC) {
  97 + //公共服务器
86 $record = $this->param['record'] ?? ''; 98 $record = $this->param['record'] ?? '';
87 if (empty($record)) { 99 if (empty($record)) {
88 $this->fail('解析记录不能为空'); 100 $this->fail('解析记录不能为空');
89 } 101 }
90 102
91 //获取解析服务器详情 103 //获取解析服务器详情
92 - $server_ip_model = new ServersIp();  
93 $record_info = $server_ip_model->read(['domain' => $record], ['id', 'servers_id', 'ip', 'domain', 'total']); 104 $record_info = $server_ip_model->read(['domain' => $record], ['id', 'servers_id', 'ip', 'domain', 'total']);
94 if (!$record_info) { 105 if (!$record_info) {
95 $this->fail('解析记录不存在'); 106 $this->fail('解析记录不存在');
96 } 107 }
97 108
98 - //获取项目详情  
99 - $project_model = new Project();  
100 - $project_info = $project_model->read(['id' => $this->user['project_id']], ['company']);  
101 - if (!$project_info) {  
102 - $this->fail('获取项目数据失败');  
103 - }  
104 -  
105 //构建blog二级域名 109 //构建blog二级域名
106 $domain_array = explode('.', $domain); 110 $domain_array = explode('.', $domain);
107 if (count($domain_array) == 1) { 111 if (count($domain_array) == 1) {
@@ -129,13 +133,11 @@ class DomainSettingLogic extends BaseLogic @@ -129,13 +133,11 @@ class DomainSettingLogic extends BaseLogic
129 } 133 }
130 134
131 //添加域名到域名管理 135 //添加域名到域名管理
132 - $domain_model = new DomainInfo();  
133 $info = $domain_model->read(['domain' => $blog_domain]); 136 $info = $domain_model->read(['domain' => $blog_domain]);
134 if ($info === false) { 137 if ($info === false) {
135 $id = $domain_model->addReturnId(['domain' => $blog_domain, 'project_id' => $this->user['project_id'], 'belong_to' => 2, 'status' => 1, 'remark' => $project_info['company']]); 138 $id = $domain_model->addReturnId(['domain' => $blog_domain, 'project_id' => $this->user['project_id'], 'belong_to' => 2, 'status' => 1, 'remark' => $project_info['company']]);
136 139
137 //保存优化设置 140 //保存优化设置
138 - $optimize_model = new DeployOptimize();  
139 $optimize_model->edit(['domain' => $id], ['project_id' => $this->user['project_id']]); 141 $optimize_model->edit(['domain' => $id], ['project_id' => $this->user['project_id']]);
140 142
141 //保存项目ip 143 //保存项目ip
@@ -143,7 +145,6 @@ class DomainSettingLogic extends BaseLogic @@ -143,7 +145,6 @@ class DomainSettingLogic extends BaseLogic
143 145
144 //变更ip使用数量 146 //变更ip使用数量
145 $server_ip_model->edit(['total' => $record_info['total'] + 1], ['id' => $record_info['id']]); 147 $server_ip_model->edit(['total' => $record_info['total'] + 1], ['id' => $record_info['id']]);
146 - $server_model = new Servers();  
147 $server_model->edit(['being_number' => $record_info['total'] + 1], ['id' => $record_info['servers_id']]); 148 $server_model->edit(['being_number' => $record_info['total'] + 1], ['id' => $record_info['servers_id']]);
148 149
149 //创建建站任务 150 //创建建站任务
@@ -161,22 +162,54 @@ class DomainSettingLogic extends BaseLogic @@ -161,22 +162,54 @@ class DomainSettingLogic extends BaseLogic
161 DB::rollBack(); 162 DB::rollBack();
162 $this->fail('保存失败,请联系管理员'); 163 $this->fail('保存失败,请联系管理员');
163 } 164 }
164 -  
165 } else { 165 } else {
166 - 166 + //个人服务器
167 $ftp = $this->param['ftp'] ?? []; 167 $ftp = $this->param['ftp'] ?? [];
168 if (empty($ftp) || empty($ftp['url']) || empty($ftp['username']) || empty($ftp['password']) || empty($ftp['port'])) { 168 if (empty($ftp) || empty($ftp['url']) || empty($ftp['username']) || empty($ftp['password']) || empty($ftp['port'])) {
169 $this->fail('ftp信息填写未完整'); 169 $this->fail('ftp信息填写未完整');
170 } 170 }
171 171
172 - //保存一条主域名记录  
173 - $setting_info = $this->model->read(['project_id' => $this->user['project_id']]);  
174 - if ($setting_info === false) {  
175 - $this->model->add(['seo_type' => WebSetting::SEO_TYPE_OWN, 'seo_domain' => $domain, 'seo_ftp' => Arr::a2s($ftp), 'project_id' => $this->user['project_id']]);  
176 - } else {  
177 - $this->model->edit(['seo_type' => WebSetting::SEO_TYPE_OWN, 'seo_domain' => $domain, 'seo_ftp' => Arr::a2s($ftp)], ['id' => $setting_info['id']]); 172 + //获取自建站服务器详情
  173 + $record_info = $server_ip_model->read(['servers_id' => ServerConfig::SELF_SITE_ID], ['id', 'servers_id', 'total']);
  174 + if (!$record_info) {
  175 + $this->fail('解析记录不存在');
  176 + }
  177 +
  178 + DB::beginTransaction();
  179 + try {
  180 + //保存一条主域名记录
  181 + $setting_info = $this->model->read(['project_id' => $this->user['project_id']]);
  182 + if ($setting_info === false) {
  183 + $this->model->add(['seo_type' => WebSetting::SEO_TYPE_OWN, 'seo_domain' => $domain, 'seo_ftp' => Arr::a2s($ftp), 'project_id' => $this->user['project_id']]);
  184 + } else {
  185 + $this->model->edit(['seo_type' => WebSetting::SEO_TYPE_OWN, 'seo_domain' => $domain, 'seo_ftp' => Arr::a2s($ftp)], ['id' => $setting_info['id']]);
  186 + }
  187 +
  188 + //添加域名到域名管理
  189 + $info = $domain_model->read(['domain' => $domain]);
  190 + if ($info === false) {
  191 + $id = $domain_model->addReturnId(['domain' => $domain, 'project_id' => $this->user['project_id'], 'belong_to' => 2, 'status' => 1, 'remark' => $project_info['company']]);
  192 +
  193 + //保存优化设置
  194 + $optimize_model = new DeployOptimize();
  195 + $optimize_model->edit(['domain' => $id], ['project_id' => $this->user['project_id']]);
  196 +
  197 + //保存项目ip
  198 + $project_model->edit(['serve_id' => $record_info['id']], ['id' => $this->user['project_id']]);
  199 +
  200 + //变更ip使用数量
  201 + $server_ip_model->edit(['total' => $record_info['total'] + 1], ['id' => $record_info['id']]);
  202 + $server_model = new Servers();
  203 + $server_model->edit(['being_number' => $record_info['total'] + 1], ['id' => $record_info['servers_id']]);
  204 + }
  205 +
  206 + DB::commit();
  207 + } catch (\Exception $e) {
  208 + DB::rollBack();
  209 + $this->fail('保存失败,请联系管理员');
178 } 210 }
179 } 211 }
180 212
  213 + return $this->success();
181 } 214 }
182 } 215 }