作者 刘锟

白帽-二级域名绑定改版

@@ -45,11 +45,11 @@ class DomainSettingController extends BaseController @@ -45,11 +45,11 @@ class DomainSettingController extends BaseController
45 public function save(DomainSettingLogic $logic) 45 public function save(DomainSettingLogic $logic)
46 { 46 {
47 $this->request->validate([ 47 $this->request->validate([
  48 + 'type' => ['required'],
48 'domain' => ['required'], 49 'domain' => ['required'],
49 - 'record' => ['required'],  
50 ], [ 50 ], [
  51 + 'type.required' => '服务器类型不能为空',
51 'domain.required' => '主域名不能为空', 52 'domain.required' => '主域名不能为空',
52 - 'record.required' => '解析记录不能为空',  
53 ]); 53 ]);
54 $logic->saveDomain(); 54 $logic->saveDomain();
55 $this->response('success', Code::SUCCESS); 55 $this->response('success', Code::SUCCESS);
@@ -9,6 +9,7 @@ @@ -9,6 +9,7 @@
9 9
10 namespace App\Http\Logic\Bside\SeoSetting; 10 namespace App\Http\Logic\Bside\SeoSetting;
11 11
  12 +use App\Helper\Arr;
12 use App\Http\Logic\Bside\BaseLogic; 13 use App\Http\Logic\Bside\BaseLogic;
13 use App\Models\Devops\Servers; 14 use App\Models\Devops\Servers;
14 use App\Models\Devops\ServersIp; 15 use App\Models\Devops\ServersIp;
@@ -37,11 +38,11 @@ class DomainSettingLogic extends BaseLogic @@ -37,11 +38,11 @@ class DomainSettingLogic extends BaseLogic
37 public function infoDomain() 38 public function infoDomain()
38 { 39 {
39 $domain_info = $this->model->read(['project_id' => $this->user['project_id']], ['seo_type', 'seo_domain', 'seo_ftp']); 40 $domain_info = $this->model->read(['project_id' => $this->user['project_id']], ['seo_type', 'seo_domain', 'seo_ftp']);
40 - $domain = $domain_info['seo_domain'] ?: '';  
41 - $ftp = $domain_info['seo_ftp'] ? json_decode($domain['seo_ftp'], true) : ['url' => '', 'username' => '', 'password' => '', 'port' => ''];  
42 - $type = $domain_info['seo_type'] ?: 1;  
43 - $record = ''; 41 + $type = $domain_info['seo_type'] ?? WebSetting::SEO_TYPE_PUBLIC;
  42 + $domain = $domain_info['seo_domain'] ?? '';
  43 + $ftp = isset($domain_info['seo_ftp']) && $domain_info['seo_ftp'] ? Arr::s2a($domain_info['seo_ftp']) : ['url' => '', 'username' => '', 'password' => '', 'port' => ''];
44 44
  45 + $record = '';
45 if ($type == WebSetting::SEO_TYPE_PUBLIC) { 46 if ($type == WebSetting::SEO_TYPE_PUBLIC) {
46 //公共服务器 47 //公共服务器
47 if ($domain) { 48 if ($domain) {
@@ -65,7 +66,8 @@ class DomainSettingLogic extends BaseLogic @@ -65,7 +66,8 @@ class DomainSettingLogic extends BaseLogic
65 66
66 /** 67 /**
67 * @remark :保存设置 68 * @remark :保存设置
68 - * @name :saveDomain 69 + * @throws \App\Exceptions\AsideGlobalException
  70 + * @throws \App\Exceptions\BsideGlobalException
69 * @author :lyh 71 * @author :lyh
70 * @method :post 72 * @method :post
71 * @time :2025/3/20 16:12 73 * @time :2025/3/20 16:12
@@ -79,9 +81,16 @@ class DomainSettingLogic extends BaseLogic @@ -79,9 +81,16 @@ class DomainSettingLogic extends BaseLogic
79 $this->fail('主域名填写错误'); 81 $this->fail('主域名填写错误');
80 } 82 }
81 83
  84 + if ($this->param['type'] = WebSetting::SEO_TYPE_PUBLIC) {
  85 +
  86 + $record = $this->param['record'] ?? '';
  87 + if (empty($record)) {
  88 + $this->fail('解析记录不能为空');
  89 + }
  90 +
82 //获取解析服务器详情 91 //获取解析服务器详情
83 $server_ip_model = new ServersIp(); 92 $server_ip_model = new ServersIp();
84 - $record_info = $server_ip_model->read(['domain' => $this->param['record']], ['id', 'servers_id', 'ip', 'domain', 'total']); 93 + $record_info = $server_ip_model->read(['domain' => $record], ['id', 'servers_id', 'ip', 'domain', 'total']);
85 if (!$record_info) { 94 if (!$record_info) {
86 $this->fail('解析记录不存在'); 95 $this->fail('解析记录不存在');
87 } 96 }
@@ -106,7 +115,7 @@ class DomainSettingLogic extends BaseLogic @@ -106,7 +115,7 @@ class DomainSettingLogic extends BaseLogic
106 115
107 //判断blog二级域名是否已经解析 116 //判断blog二级域名是否已经解析
108 if (!check_domain_record($blog_domain, $record_info)) { 117 if (!check_domain_record($blog_domain, $record_info)) {
109 - $this->fail($blog_domain . '还未解析cname至' . $this->param['record']); 118 + $this->fail($blog_domain . '还未解析cname至' . $record);
110 } 119 }
111 120
112 DB::beginTransaction(); 121 DB::beginTransaction();
@@ -114,9 +123,9 @@ class DomainSettingLogic extends BaseLogic @@ -114,9 +123,9 @@ class DomainSettingLogic extends BaseLogic
114 //保存一条主域名记录 123 //保存一条主域名记录
115 $setting_info = $this->model->read(['project_id' => $this->user['project_id']]); 124 $setting_info = $this->model->read(['project_id' => $this->user['project_id']]);
116 if ($setting_info === false) { 125 if ($setting_info === false) {
117 - $this->model->add(['seo_domain' => $domain, 'project_id' => $this->user['project_id']]); 126 + $this->model->add(['seo_type' => WebSetting::SEO_TYPE_PUBLIC, 'seo_domain' => $domain, 'project_id' => $this->user['project_id']]);
118 } else { 127 } else {
119 - $this->model->edit(['seo_domain' => $domain], ['id' => $setting_info['id']]); 128 + $this->model->edit(['seo_type' => WebSetting::SEO_TYPE_PUBLIC, 'seo_domain' => $domain], ['id' => $setting_info['id']]);
120 } 129 }
121 130
122 //添加域名到域名管理 131 //添加域名到域名管理
@@ -152,5 +161,22 @@ class DomainSettingLogic extends BaseLogic @@ -152,5 +161,22 @@ class DomainSettingLogic extends BaseLogic
152 DB::rollBack(); 161 DB::rollBack();
153 $this->fail('保存失败,请联系管理员'); 162 $this->fail('保存失败,请联系管理员');
154 } 163 }
  164 +
  165 + } else {
  166 +
  167 + $ftp = $this->param['ftp'] ?? [];
  168 + if (empty($ftp) || empty($ftp['url']) || empty($ftp['username']) || empty($ftp['password']) || empty($ftp['port'])) {
  169 + $this->fail('ftp信息填写未完整');
  170 + }
  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']]);
  178 + }
  179 + }
  180 +
155 } 181 }
156 } 182 }