作者 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,31 +38,37 @@ class DomainSettingLogic extends BaseLogic @@ -36,31 +38,37 @@ 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 - //获取域名解析  
45 - $project_model = new Project();  
46 - $project_info = $project_model->read(['id' => $this->user['project_id']], ['serve_id']);  
47 -  
48 - if ($project_info) {  
49 - $server_model = new ServersIp();  
50 - $record_info = $server_model->read(['id' => $project_info['serve_id']], ['domain']);  
51 - $record = $record_info ? $record_info['domain'] : ''; 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 + //已经绑定了主域名,获取域名解析
  51 + $project_model = new Project();
  52 + $project_info = $project_model->read(['id' => $this->user['project_id']], ['serve_id']);
  53 +
  54 + if ($project_info) {
  55 + $server_model = new ServersIp();
  56 + $record_info = $server_model->read(['id' => $project_info['serve_id']], ['domain']);
  57 + $record = $record_info ? $record_info['domain'] : '';
  58 + }
  59 + } else {
  60 + //未绑定主域名,分配域名解析
  61 + $record = Servers::where('init_domain', 'like', 'seo%')->where('being_number', '<', 10)->orderBy('being_number', 'desc')->orderBy('id', 'asc')->value('init_domain') ?? '';
52 } 62 }
53 - } else {  
54 - //未绑定主域名  
55 - $record = Servers::where('init_domain', 'like', 'seo%')->where('being_number', '<', 10)->orderBy('being_number', 'desc')->orderBy('id', 'asc')->value('init_domain') ?? '';  
56 } 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,64 +89,125 @@ class DomainSettingLogic extends BaseLogic @@ -88,64 +89,125 @@ class DomainSettingLogic extends BaseLogic
88 $this->fail('获取项目数据失败'); 89 $this->fail('获取项目数据失败');
89 } 90 }
90 91
91 - //构建blog二级域名  
92 - $domain_array = explode('.', $domain);  
93 - if (count($domain_array) == 1) {  
94 - $this->fail('请填写正确的主域名');  
95 - } elseif (count($domain_array) == 2) {  
96 - array_unshift($domain_array, 'blog');  
97 - } else {  
98 - $domain_array[0] = 'blog';  
99 - }  
100 - $blog_domain = implode('.', $domain_array); 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 + }
101 102
102 - //判断blog二级域名是否已经解析  
103 - if (!check_domain_record($blog_domain, $record_info)) {  
104 - $this->fail($blog_domain . '还未解析cname至' . $this->param['record']);  
105 - } 103 + //获取解析服务器详情
  104 + $record_info = $server_ip_model->read(['domain' => $record], ['id', 'servers_id', 'ip', 'domain', 'total']);
  105 + if (!$record_info) {
  106 + $this->fail('解析记录不存在');
  107 + }
106 108
107 - DB::beginTransaction();  
108 - try {  
109 - //保存一条主域名记录  
110 - $setting_info = $this->model->read(['project_id' => $this->user['project_id']]);  
111 - if ($setting_info === false) {  
112 - $this->model->add(['seo_domain' => $domain, 'project_id' => $this->user['project_id']]); 109 + //构建blog二级域名
  110 + $domain_array = explode('.', $domain);
  111 + if (count($domain_array) == 1) {
  112 + $this->fail('请填写正确的主域名');
  113 + } elseif (count($domain_array) == 2) {
  114 + array_unshift($domain_array, 'blog');
113 } else { 115 } else {
114 - $this->model->edit(['seo_domain' => $domain], ['id' => $setting_info['id']]); 116 + $domain_array[0] = 'blog';
  117 + }
  118 + $blog_domain = implode('.', $domain_array);
  119 +
  120 + //判断blog二级域名是否已经解析
  121 + if (!check_domain_record($blog_domain, $record_info)) {
  122 + $this->fail($blog_domain . '还未解析cname至' . $record);
115 } 123 }
116 124
117 - //添加域名到域名管理  
118 - $domain_model = new DomainInfo();  
119 - $info = $domain_model->read(['domain' => $blog_domain]);  
120 - 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']]);  
122 -  
123 - //保存优化设置  
124 - $optimize_model = new DeployOptimize();  
125 - $optimize_model->edit(['domain' => $id], ['project_id' => $this->user['project_id']]);  
126 -  
127 - //保存项目ip  
128 - $project_model->edit(['serve_id' => $record_info['id']], ['id' => $this->user['project_id']]);  
129 -  
130 - //变更ip使用数量  
131 - $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']]);  
134 -  
135 - //创建建站任务  
136 - $domain_create_model = new DomainCreateTask();  
137 - $domain_create_model->add([  
138 - 'server_id' => $record_info['servers_id'],  
139 - 'project_id' => $this->user['project_id'],  
140 - 'domain_id' => $id,  
141 - 'type' => DomainCreateTask::TYPE_BLOG  
142 - ]); 125 + DB::beginTransaction();
  126 + try {
  127 + //保存一条主域名记录
  128 + $setting_info = $this->model->read(['project_id' => $this->user['project_id']]);
  129 + if ($setting_info === false) {
  130 + $this->model->add(['seo_type' => WebSetting::SEO_TYPE_PUBLIC, 'seo_domain' => $domain, 'project_id' => $this->user['project_id']]);
  131 + } else {
  132 + $this->model->edit(['seo_type' => WebSetting::SEO_TYPE_PUBLIC, 'seo_domain' => $domain], ['id' => $setting_info['id']]);
  133 + }
  134 +
  135 + //添加域名到域名管理
  136 + $info = $domain_model->read(['domain' => $blog_domain]);
  137 + if ($info === false) {
  138 + $id = $domain_model->addReturnId(['domain' => $blog_domain, 'project_id' => $this->user['project_id'], 'belong_to' => 2, 'status' => 1, 'remark' => $project_info['company']]);
  139 +
  140 + //保存优化设置
  141 + $optimize_model->edit(['domain' => $id], ['project_id' => $this->user['project_id']]);
  142 +
  143 + //保存项目ip
  144 + $project_model->edit(['serve_id' => $record_info['id']], ['id' => $this->user['project_id']]);
  145 +
  146 + //变更ip使用数量
  147 + $server_ip_model->edit(['total' => $record_info['total'] + 1], ['id' => $record_info['id']]);
  148 + $server_model->edit(['being_number' => $record_info['total'] + 1], ['id' => $record_info['servers_id']]);
  149 +
  150 + //创建建站任务
  151 + $domain_create_model = new DomainCreateTask();
  152 + $domain_create_model->add([
  153 + 'server_id' => $record_info['servers_id'],
  154 + 'project_id' => $this->user['project_id'],
  155 + 'domain_id' => $id,
  156 + 'type' => DomainCreateTask::TYPE_BLOG
  157 + ]);
  158 + }
  159 +
  160 + DB::commit();
  161 + } catch (\Exception $e) {
  162 + DB::rollBack();
  163 + $this->fail('保存失败,请联系管理员');
  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信息填写未完整');
143 } 170 }
144 171
145 - DB::commit();  
146 - } catch (\Exception $e) {  
147 - DB::rollBack();  
148 - $this->fail('保存失败,请联系管理员'); 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 + }
149 } 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 */