作者 刘锟

合并分支 'akun' 到 'master'

Akun



查看合并请求 !1527
@@ -12,9 +12,6 @@ namespace App\Http\Controllers\Bside\SeoSetting; @@ -12,9 +12,6 @@ namespace App\Http\Controllers\Bside\SeoSetting;
12 use App\Enums\Common\Code; 12 use App\Enums\Common\Code;
13 use App\Http\Controllers\Bside\BaseController; 13 use App\Http\Controllers\Bside\BaseController;
14 use App\Http\Logic\Bside\SeoSetting\DomainSettingLogic; 14 use App\Http\Logic\Bside\SeoSetting\DomainSettingLogic;
15 -use App\Models\Domain\DomainInfo;  
16 -use App\Models\WebSetting\WebSetting;  
17 -use Illuminate\Http\Request;  
18 15
19 /** 16 /**
20 * @remark :白帽系统设置二级域名 17 * @remark :白帽系统设置二级域名
@@ -25,12 +22,6 @@ use Illuminate\Http\Request; @@ -25,12 +22,6 @@ use Illuminate\Http\Request;
25 */ 22 */
26 class DomainSettingController extends BaseController 23 class DomainSettingController extends BaseController
27 { 24 {
28 - public function __construct(Request $request)  
29 - {  
30 - $this->model = new WebSetting();  
31 - parent::__construct($request);  
32 - }  
33 -  
34 /** 25 /**
35 * @remark :获取当前二级域名详情 26 * @remark :获取当前二级域名详情
36 * @name :getInfo 27 * @name :getInfo
@@ -38,9 +29,10 @@ class DomainSettingController extends BaseController @@ -38,9 +29,10 @@ class DomainSettingController extends BaseController
38 * @method :post 29 * @method :post
39 * @time :2025/3/20 11:26 30 * @time :2025/3/20 11:26
40 */ 31 */
41 - public function getInfo(){  
42 - $data = $this->model->read(['project_id'=>$this->user['project_id']],['seo_domain']);  
43 - $this->response('success',Code::SUCCESS,$data); 32 + public function getInfo(DomainSettingLogic $logic)
  33 + {
  34 + $data = $logic->infoDomain();
  35 + $this->response('success', Code::SUCCESS, $data);
44 } 36 }
45 37
46 /** 38 /**
@@ -50,13 +42,16 @@ class DomainSettingController extends BaseController @@ -50,13 +42,16 @@ class DomainSettingController extends BaseController
50 * @method :post 42 * @method :post
51 * @time :2025/3/20 11:29 43 * @time :2025/3/20 11:29
52 */ 44 */
53 - public function save(DomainSettingLogic $logic){ 45 + public function save(DomainSettingLogic $logic)
  46 + {
54 $this->request->validate([ 47 $this->request->validate([
55 - 'domain'=>['required'],  
56 - ],[  
57 - 'domain.required' => 'domain不能为空', 48 + 'domain' => ['required'],
  49 + 'record' => ['required'],
  50 + ], [
  51 + 'domain.required' => '主域名不能为空',
  52 + 'record.required' => '解析记录不能为空',
58 ]); 53 ]);
59 $data = $logic->saveDomain(); 54 $data = $logic->saveDomain();
60 - $this->response('success',Code::SUCCESS,$data); 55 + $this->response('success', Code::SUCCESS, $data);
61 } 56 }
62 } 57 }
@@ -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\Devops\Servers;
  14 +use App\Models\Devops\ServersIp;
  15 +use App\Models\Domain\DomainCreateTask;
  16 +use App\Models\Domain\DomainInfo;
13 use App\Models\Project\DeployOptimize; 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('主域名填写错误');
35 } 75 }
36 - //保存一条主域名记录 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('解析记录不存在');
  82 + }
  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 DeployOptimize();  
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 }
@@ -16,4 +16,5 @@ class DomainCreateTask extends Base @@ -16,4 +16,5 @@ class DomainCreateTask extends Base
16 const TYPE_MAIN = 1; 16 const TYPE_MAIN = 1;
17 const TYPE_AMP = 2; 17 const TYPE_AMP = 2;
18 const TYPE_CUSTOM = 3; 18 const TYPE_CUSTOM = 3;
  19 + const TYPE_BLOG = 4;
19 } 20 }