作者 lyh

Merge branch 'master' of http://47.244.231.31:8099/zhl/globalso-v6 into lyh-server

@@ -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,7 +9,9 @@ @@ -9,7 +9,9 @@
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;
  14 +use App\Models\Devops\ServerConfig;
13 use App\Models\Devops\Servers; 15 use App\Models\Devops\Servers;
14 use App\Models\Devops\ServersIp; 16 use App\Models\Devops\ServersIp;
15 use App\Models\Domain\DomainCreateTask; 17 use App\Models\Domain\DomainCreateTask;
@@ -36,12 +38,16 @@ class DomainSettingLogic extends BaseLogic @@ -36,12 +38,16 @@ class DomainSettingLogic extends BaseLogic
36 */ 38 */
37 public function infoDomain() 39 public function infoDomain()
38 { 40 {
39 - $domain = $record = '';  
40 - $domain_info = $this->model->read(['project_id' => $this->user['project_id']], ['seo_domain']);  
41 - if (isset($domain_info['seo_domain']) && $domain_info['seo_domain']) {  
42 - //已经绑定了主域名  
43 - $domain = $domain_info['seo_domain'];  
44 - //获取域名解析 41 + $domain_info = $this->model->read(['project_id' => $this->user['project_id']], ['seo_type', 'seo_domain', 'seo_ftp']);
  42 + $type = $domain_info['seo_type'] ?? WebSetting::SEO_TYPE_PUBLIC;
  43 + $domain = $domain_info['seo_domain'] ?? '';
  44 + $ftp = isset($domain_info['seo_ftp']) && $domain_info['seo_ftp'] ? Arr::s2a($domain_info['seo_ftp']) : ['url' => '', 'username' => '', 'password' => '', 'port' => ''];
  45 +
  46 + $record = '';
  47 + if ($type == WebSetting::SEO_TYPE_PUBLIC) {
  48 + //公共服务器
  49 + if ($domain) {
  50 + //已经绑定了主域名,获取域名解析
45 $project_model = new Project(); 51 $project_model = new Project();
46 $project_info = $project_model->read(['id' => $this->user['project_id']], ['serve_id']); 52 $project_info = $project_model->read(['id' => $this->user['project_id']], ['serve_id']);
47 53
@@ -51,16 +57,18 @@ class DomainSettingLogic extends BaseLogic @@ -51,16 +57,18 @@ class DomainSettingLogic extends BaseLogic
51 $record = $record_info ? $record_info['domain'] : ''; 57 $record = $record_info ? $record_info['domain'] : '';
52 } 58 }
53 } else { 59 } else {
54 - //未绑定主域名 60 + //未绑定主域名,分配域名解析
55 $record = Servers::where('init_domain', 'like', 'seo%')->where('being_number', '<', 10)->orderBy('being_number', 'desc')->orderBy('id', 'asc')->value('init_domain') ?? ''; 61 $record = Servers::where('init_domain', 'like', 'seo%')->where('being_number', '<', 10)->orderBy('being_number', 'desc')->orderBy('id', 'asc')->value('init_domain') ?? '';
56 } 62 }
  63 + }
57 64
58 - return ['domain' => $domain, 'record' => $record]; 65 + return ['type' => $type, 'domain' => $domain, 'record' => $record, 'ftp' => $ftp];
59 } 66 }
60 67
61 /** 68 /**
62 * @remark :保存设置 69 * @remark :保存设置
63 - * @name :saveDomain 70 + * @throws \App\Exceptions\AsideGlobalException
  71 + * @throws \App\Exceptions\BsideGlobalException
64 * @author :lyh 72 * @author :lyh
65 * @method :post 73 * @method :post
66 * @time :2025/3/20 16:12 74 * @time :2025/3/20 16:12
@@ -74,13 +82,6 @@ class DomainSettingLogic extends BaseLogic @@ -74,13 +82,6 @@ class DomainSettingLogic extends BaseLogic
74 $this->fail('主域名填写错误'); 82 $this->fail('主域名填写错误');
75 } 83 }
76 84
77 - //获取解析服务器详情  
78 - $server_ip_model = new ServersIp();  
79 - $record_info = $server_ip_model->read(['domain' => $this->param['record']], ['id', 'servers_id', 'ip', 'domain', 'total']);  
80 - if (!$record_info) {  
81 - $this->fail('解析记录不存在');  
82 - }  
83 -  
84 //获取项目详情 85 //获取项目详情
85 $project_model = new Project(); 86 $project_model = new Project();
86 $project_info = $project_model->read(['id' => $this->user['project_id']], ['company']); 87 $project_info = $project_model->read(['id' => $this->user['project_id']], ['company']);
@@ -88,6 +89,23 @@ class DomainSettingLogic extends BaseLogic @@ -88,6 +89,23 @@ class DomainSettingLogic extends BaseLogic
88 $this->fail('获取项目数据失败'); 89 $this->fail('获取项目数据失败');
89 } 90 }
90 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 + //公共服务器
  98 + $record = $this->param['record'] ?? '';
  99 + if (empty($record)) {
  100 + $this->fail('解析记录不能为空');
  101 + }
  102 +
  103 + //获取解析服务器详情
  104 + $record_info = $server_ip_model->read(['domain' => $record], ['id', 'servers_id', 'ip', 'domain', 'total']);
  105 + if (!$record_info) {
  106 + $this->fail('解析记录不存在');
  107 + }
  108 +
91 //构建blog二级域名 109 //构建blog二级域名
92 $domain_array = explode('.', $domain); 110 $domain_array = explode('.', $domain);
93 if (count($domain_array) == 1) { 111 if (count($domain_array) == 1) {
@@ -101,7 +119,7 @@ class DomainSettingLogic extends BaseLogic @@ -101,7 +119,7 @@ class DomainSettingLogic extends BaseLogic
101 119
102 //判断blog二级域名是否已经解析 120 //判断blog二级域名是否已经解析
103 if (!check_domain_record($blog_domain, $record_info)) { 121 if (!check_domain_record($blog_domain, $record_info)) {
104 - $this->fail($blog_domain . '还未解析cname至' . $this->param['record']); 122 + $this->fail($blog_domain . '还未解析cname至' . $record);
105 } 123 }
106 124
107 DB::beginTransaction(); 125 DB::beginTransaction();
@@ -109,19 +127,17 @@ class DomainSettingLogic extends BaseLogic @@ -109,19 +127,17 @@ class DomainSettingLogic extends BaseLogic
109 //保存一条主域名记录 127 //保存一条主域名记录
110 $setting_info = $this->model->read(['project_id' => $this->user['project_id']]); 128 $setting_info = $this->model->read(['project_id' => $this->user['project_id']]);
111 if ($setting_info === false) { 129 if ($setting_info === false) {
112 - $this->model->add(['seo_domain' => $domain, 'project_id' => $this->user['project_id']]); 130 + $this->model->add(['seo_type' => WebSetting::SEO_TYPE_PUBLIC, 'seo_domain' => $domain, 'project_id' => $this->user['project_id']]);
113 } else { 131 } else {
114 - $this->model->edit(['seo_domain' => $domain], ['id' => $setting_info['id']]); 132 + $this->model->edit(['seo_type' => WebSetting::SEO_TYPE_PUBLIC, 'seo_domain' => $domain], ['id' => $setting_info['id']]);
115 } 133 }
116 134
117 //添加域名到域名管理 135 //添加域名到域名管理
118 - $domain_model = new DomainInfo();  
119 $info = $domain_model->read(['domain' => $blog_domain]); 136 $info = $domain_model->read(['domain' => $blog_domain]);
120 if ($info === false) { 137 if ($info === false) {
121 $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']]);
122 139
123 //保存优化设置 140 //保存优化设置
124 - $optimize_model = new DeployOptimize();  
125 $optimize_model->edit(['domain' => $id], ['project_id' => $this->user['project_id']]); 141 $optimize_model->edit(['domain' => $id], ['project_id' => $this->user['project_id']]);
126 142
127 //保存项目ip 143 //保存项目ip
@@ -129,7 +145,6 @@ class DomainSettingLogic extends BaseLogic @@ -129,7 +145,6 @@ class DomainSettingLogic extends BaseLogic
129 145
130 //变更ip使用数量 146 //变更ip使用数量
131 $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']]);
132 - $server_model = new Servers();  
133 $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']]);
134 149
135 //创建建站任务 150 //创建建站任务
@@ -147,5 +162,52 @@ class DomainSettingLogic extends BaseLogic @@ -147,5 +162,52 @@ class DomainSettingLogic extends BaseLogic
147 DB::rollBack(); 162 DB::rollBack();
148 $this->fail('保存失败,请联系管理员'); 163 $this->fail('保存失败,请联系管理员');
149 } 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 + $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->edit(['domain' => $id], ['project_id' => $this->user['project_id']]);
  195 +
  196 + //保存项目ip
  197 + $project_model->edit(['serve_id' => $record_info['id']], ['id' => $this->user['project_id']]);
  198 +
  199 + //变更ip使用数量
  200 + $server_ip_model->edit(['total' => $record_info['total'] + 1], ['id' => $record_info['id']]);
  201 + $server_model->edit(['being_number' => $record_info['total'] + 1], ['id' => $record_info['servers_id']]);
  202 + }
  203 +
  204 + DB::commit();
  205 + } catch (\Exception $e) {
  206 + DB::rollBack();
  207 + $this->fail('保存失败,请联系管理员');
  208 + }
  209 + }
  210 +
  211 + return $this->success();
150 } 212 }
151 } 213 }
@@ -20,6 +20,9 @@ class WebSetting extends Base @@ -20,6 +20,9 @@ class WebSetting extends Base
20 public static $okStatus = 200; 20 public static $okStatus = 200;
21 public static $errStatus = 500; 21 public static $errStatus = 500;
22 22
  23 + const SEO_TYPE_PUBLIC = 1;
  24 + const SEO_TYPE_OWN = 2;
  25 +
23 /** 26 /**
24 * 网站设置 27 * 网站设置
25 */ 28 */