|
@@ -10,8 +10,14 @@ |
|
@@ -10,8 +10,14 @@ |
|
10
|
namespace App\Http\Logic\Bside\SeoSetting;
|
10
|
namespace App\Http\Logic\Bside\SeoSetting;
|
|
11
|
|
11
|
|
|
12
|
use App\Http\Logic\Bside\BaseLogic;
|
12
|
use App\Http\Logic\Bside\BaseLogic;
|
|
13
|
-use App\Models\SeoSetting\KeywordUrl;
|
13
|
+use App\Models\Devops\Servers;
|
|
|
|
14
|
+use App\Models\Devops\ServersIp;
|
|
|
|
15
|
+use App\Models\Domain\DomainCreateTask;
|
|
|
|
16
|
+use App\Models\Domain\DomainInfo;
|
|
|
|
17
|
+use App\Models\Project\DeployOptimize;
|
|
|
|
18
|
+use App\Models\Project\Project;
|
|
14
|
use App\Models\WebSetting\WebSetting;
|
19
|
use App\Models\WebSetting\WebSetting;
|
|
|
|
20
|
+use Illuminate\Support\Facades\DB;
|
|
15
|
|
21
|
|
|
16
|
class DomainSettingLogic extends BaseLogic
|
22
|
class DomainSettingLogic extends BaseLogic
|
|
17
|
{
|
23
|
{
|
|
@@ -19,6 +25,37 @@ class DomainSettingLogic extends BaseLogic |
|
@@ -19,6 +25,37 @@ class DomainSettingLogic extends BaseLogic |
|
19
|
{
|
25
|
{
|
|
20
|
parent::__construct();
|
26
|
parent::__construct();
|
|
21
|
$this->param = $this->requestAll;
|
27
|
$this->param = $this->requestAll;
|
|
|
|
28
|
+ $this->model = new WebSetting();
|
|
|
|
29
|
+ }
|
|
|
|
30
|
+
|
|
|
|
31
|
+ /**
|
|
|
|
32
|
+ * 获取域名设置及目标解析记录
|
|
|
|
33
|
+ * @return array
|
|
|
|
34
|
+ * @author Akun
|
|
|
|
35
|
+ * @date 2025/03/21 10:09
|
|
|
|
36
|
+ */
|
|
|
|
37
|
+ public function infoDomain()
|
|
|
|
38
|
+ {
|
|
|
|
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(['project_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'] : '';
|
|
|
|
52
|
+ }
|
|
|
|
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
|
+ }
|
|
|
|
57
|
+
|
|
|
|
58
|
+ return ['domain' => $domain, 'record' => $record];
|
|
22
|
}
|
59
|
}
|
|
23
|
|
60
|
|
|
24
|
/**
|
61
|
/**
|
|
@@ -28,26 +65,71 @@ class DomainSettingLogic extends BaseLogic |
|
@@ -28,26 +65,71 @@ class DomainSettingLogic extends BaseLogic |
|
28
|
* @method :post
|
65
|
* @method :post
|
|
29
|
* @time :2025/3/20 16:12
|
66
|
* @time :2025/3/20 16:12
|
|
30
|
*/
|
67
|
*/
|
|
31
|
- public function saveDomain(){
|
|
|
|
32
|
- $domain = parse_url($this->param['domain'], PHP_URL_HOST);
|
|
|
|
33
|
- if(!empty($domain)){
|
|
|
|
34
|
- $this->param['domain'] = trim($domain['host']);
|
68
|
+ public function saveDomain()
|
|
|
|
69
|
+ {
|
|
|
|
70
|
+ //获取主域名
|
|
|
|
71
|
+ $domain_parse = parse_url($this->param['domain'], PHP_URL_HOST);
|
|
|
|
72
|
+ $domain = trim($domain_parse['host'] ?? '');
|
|
|
|
73
|
+ if (!$domain) {
|
|
|
|
74
|
+ $this->fail('主域名填写错误');
|
|
|
|
75
|
+ }
|
|
|
|
76
|
+
|
|
|
|
77
|
+ //获取解析服务器详情
|
|
|
|
78
|
+ $server_model = new ServersIp();
|
|
|
|
79
|
+ $record_info = $server_model->read(['domain' => $this->param['record']], ['id', 'servers_id', 'ip', 'domain']);
|
|
|
|
80
|
+ if (!$record_info) {
|
|
|
|
81
|
+ $this->fail('解析记录不存在');
|
|
35
|
}
|
82
|
}
|
|
36
|
- //保存一条主域名记录
|
83
|
+
|
|
|
|
84
|
+ //获取项目详情
|
|
|
|
85
|
+ $project_model = new Project();
|
|
|
|
86
|
+ $project_info = $project_model->read(['id' => $this->user['project_id']], ['company']);
|
|
|
|
87
|
+ if (!$project_info) {
|
|
|
|
88
|
+ $this->fail('获取项目数据失败');
|
|
|
|
89
|
+ }
|
|
|
|
90
|
+
|
|
|
|
91
|
+ //构建blog二级域名
|
|
|
|
92
|
+ $domain_array = explode('.', $domain);
|
|
|
|
93
|
+ if (count($domain_array) <= 2) {
|
|
|
|
94
|
+ array_unshift($domain_array, 'blog');
|
|
|
|
95
|
+ } else {
|
|
|
|
96
|
+ $domain_array[0] = 'blog';
|
|
|
|
97
|
+ }
|
|
|
|
98
|
+ $blog_domain = implode('.', $domain_array);
|
|
|
|
99
|
+
|
|
|
|
100
|
+ //判断blog二级域名是否已经解析
|
|
|
|
101
|
+ if (!check_domain_record($blog_domain, $record_info)) {
|
|
|
|
102
|
+ $this->fail($blog_domain . '还未解析cname至' . $this->param['record']);
|
|
|
|
103
|
+ }
|
|
|
|
104
|
+
|
|
|
|
105
|
+ DB::beginTransaction();
|
|
37
|
try {
|
106
|
try {
|
|
38
|
- $this->saveWebSetting($this->param['domain']);
|
107
|
+ //保存一条主域名记录
|
|
|
|
108
|
+ $this->saveWebSetting($domain);
|
|
|
|
109
|
+
|
|
39
|
//添加域名到域名管理
|
110
|
//添加域名到域名管理
|
|
40
|
- $info = $this->model->read(['project_id'=>$this->user['project_id']]);
|
|
|
|
41
|
- if($info === false){
|
|
|
|
42
|
- //保存数据
|
|
|
|
43
|
- $this->param['domain'] = str_replace('www','blog',$this->param['domain']);
|
|
|
|
44
|
- $id = $this->model->addReturnId(['domain'=>$this->param['domain'],'project_id'=>$this->user['project_id'],'belong_to'=>2,'status'=>1]);
|
|
|
|
45
|
- $projectModel = new Project();
|
|
|
|
46
|
- $projectModel->edit(['domain'=>$id],['project_id'=>$this->user['project_id']]);
|
|
|
|
47
|
- }else{
|
|
|
|
48
|
- $this->model->edit(['domain'=>$this->param['domain']],['project_id'=>$this->user['project_id']]);
|
111
|
+ $domain_model = new DomainInfo();
|
|
|
|
112
|
+ $info = $domain_model->read(['domain' => $blog_domain]);
|
|
|
|
113
|
+ if ($info === false) {
|
|
|
|
114
|
+ $id = $domain_model->addReturnId(['domain' => $blog_domain, 'project_id' => $this->user['project_id'], 'belong_to' => 2, 'status' => 1, 'remark' => $project_info['company']]);
|
|
|
|
115
|
+
|
|
|
|
116
|
+ //保存优化设置
|
|
|
|
117
|
+ $optimize_model = new DeployOptimize();
|
|
|
|
118
|
+ $optimize_model->edit(['domain' => $id], ['project_id' => $this->user['project_id']]);
|
|
|
|
119
|
+
|
|
|
|
120
|
+ //创建建站任务
|
|
|
|
121
|
+ $domain_create_model = new DomainCreateTask();
|
|
|
|
122
|
+ $domain_create_model->add([
|
|
|
|
123
|
+ 'server_id' => $record_info['servers_id'],
|
|
|
|
124
|
+ 'project_id' => $this->user['project_id'],
|
|
|
|
125
|
+ 'domain_id' => $id,
|
|
|
|
126
|
+ 'type' => DomainCreateTask::TYPE_BLOG
|
|
|
|
127
|
+ ]);
|
|
49
|
}
|
128
|
}
|
|
50
|
- }catch (\Exception $e){
|
129
|
+
|
|
|
|
130
|
+ DB::commit();
|
|
|
|
131
|
+ } catch (\Exception $e) {
|
|
|
|
132
|
+ DB::rollBack();
|
|
51
|
$this->fail('保存失败,请联系管理员');
|
133
|
$this->fail('保存失败,请联系管理员');
|
|
52
|
}
|
134
|
}
|
|
53
|
}
|
135
|
}
|
|
@@ -59,13 +141,13 @@ class DomainSettingLogic extends BaseLogic |
|
@@ -59,13 +141,13 @@ class DomainSettingLogic extends BaseLogic |
|
59
|
* @method :post
|
141
|
* @method :post
|
|
60
|
* @time :2025/3/20 15:38
|
142
|
* @time :2025/3/20 15:38
|
|
61
|
*/
|
143
|
*/
|
|
62
|
- public function saveWebSetting($domain){
|
|
|
|
63
|
- $webSettingModel = new WebSetting();
|
|
|
|
64
|
- $settingInfo = $webSettingModel->read(['project_id'=>$this->user['project_id']]);
|
|
|
|
65
|
- if($settingInfo === false){
|
|
|
|
66
|
- $webSettingModel->add(['seo_domain'=>$domain,'project_id'=>$this->user['project_id']]);
|
|
|
|
67
|
- }else{
|
|
|
|
68
|
- $webSettingModel->edit(['seo_domain'=>$domain],['id'=>$settingInfo['id']]);
|
144
|
+ public function saveWebSetting($domain)
|
|
|
|
145
|
+ {
|
|
|
|
146
|
+ $settingInfo = $this->model->read(['project_id' => $this->user['project_id']]);
|
|
|
|
147
|
+ if ($settingInfo === false) {
|
|
|
|
148
|
+ $this->model->add(['seo_domain' => $domain, 'project_id' => $this->user['project_id']]);
|
|
|
|
149
|
+ } else {
|
|
|
|
150
|
+ $this->model->edit(['seo_domain' => $domain], ['id' => $settingInfo['id']]);
|
|
69
|
}
|
151
|
}
|
|
70
|
return $this->success();
|
152
|
return $this->success();
|
|
71
|
}
|
153
|
}
|