作者 李宇航

合并分支 'lyh-server' 到 'master'

gx



查看合并请求 !1522
@@ -11,6 +11,7 @@ namespace App\Http\Controllers\Bside\SeoSetting; @@ -11,6 +11,7 @@ namespace App\Http\Controllers\Bside\SeoSetting;
11 11
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\Models\Domain\DomainInfo; 15 use App\Models\Domain\DomainInfo;
15 use App\Models\WebSetting\WebSetting; 16 use App\Models\WebSetting\WebSetting;
16 use Illuminate\Http\Request; 17 use Illuminate\Http\Request;
@@ -49,52 +50,13 @@ class DomainSettingController extends BaseController @@ -49,52 +50,13 @@ class DomainSettingController extends BaseController
49 * @method :post 50 * @method :post
50 * @time :2025/3/20 11:29 51 * @time :2025/3/20 11:29
51 */ 52 */
52 - public function save(){ 53 + public function save(DomainSettingLogic $logic){
53 $this->request->validate([ 54 $this->request->validate([
54 'domain'=>['required'], 55 'domain'=>['required'],
55 ],[ 56 ],[
56 'domain.required' => 'domain不能为空', 57 'domain.required' => 'domain不能为空',
57 ]); 58 ]);
58 - $domain = parse_url($this->param['domain'], PHP_URL_HOST);  
59 - if(!empty($domain)){  
60 - $this->param['domain'] = trim($domain['host']);  
61 - }  
62 - //保存一条主域名记录  
63 - try {  
64 - $this->saveWebSetting($this->param['domain']);  
65 - //添加域名到域名管理  
66 - $info = $this->model->read(['project_id'=>$this->user['project_id']]);  
67 - if($info === false){  
68 - //保存数据  
69 - $this->param['domain'] = str_replace('www','blog',$this->param['domain']);  
70 - $id = $this->model->addReturnId(['domain'=>$this->param['domain'],'project_id'=>$this->user['project_id'],'belong_to'=>2,'status'=>1]);  
71 - $projectModel = new Project();  
72 - $projectModel->edit(['domain'=>$id],['project_id'=>$this->user['project_id']]);  
73 - }else{  
74 - $this->model->edit(['domain'=>$this->param['domain']],['project_id'=>$this->user['project_id']]);  
75 - }  
76 - }catch (\Exception $e){  
77 - $this->fail('保存失败,请联系管理员');  
78 - }  
79 -  
80 - $this->response('success');  
81 - }  
82 -  
83 - /**  
84 - * @remark :保存主域名设置  
85 - * @name :saveWebSetting  
86 - * @author :lyh  
87 - * @method :post  
88 - * @time :2025/3/20 15:38  
89 - */  
90 - public function saveWebSetting($domain){  
91 - $webSettingModel = new WebSetting();  
92 - $settingInfo = $webSettingModel->read(['project_id'=>$this->user['project_id']]);  
93 - if($settingInfo === false){  
94 - $webSettingModel->add(['seo_domain'=>$domain,'project_id'=>$this->user['project_id']]);  
95 - }else{  
96 - $webSettingModel->edit(['seo_domain'=>$domain],['id'=>$settingInfo['id']]);  
97 - }  
98 - return $this->success(); 59 + $data = $logic->saveDomain();
  60 + $this->response('success',Code::SUCCESS,$data);
99 } 61 }
100 } 62 }
  1 +<?php
  2 +/**
  3 + * @remark :
  4 + * @name :DomainSettingLogic.php
  5 + * @author :lyh
  6 + * @method :post
  7 + * @time :2025/3/20 16:01
  8 + */
  9 +
  10 +namespace App\Http\Logic\Bside\SeoSetting;
  11 +
  12 +use App\Http\Logic\Bside\BaseLogic;
  13 +use App\Models\SeoSetting\KeywordUrl;
  14 +use App\Models\WebSetting\WebSetting;
  15 +
  16 +class DomainSettingLogic extends BaseLogic
  17 +{
  18 + public function __construct()
  19 + {
  20 + parent::__construct();
  21 + $this->param = $this->requestAll;
  22 + }
  23 +
  24 + /**
  25 + * @remark :保存设置
  26 + * @name :saveDomain
  27 + * @author :lyh
  28 + * @method :post
  29 + * @time :2025/3/20 16:12
  30 + */
  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']);
  35 + }
  36 + //保存一条主域名记录
  37 + try {
  38 + $this->saveWebSetting($this->param['domain']);
  39 + //添加域名到域名管理
  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']]);
  49 + }
  50 + }catch (\Exception $e){
  51 + $this->fail('保存失败,请联系管理员');
  52 + }
  53 + }
  54 +
  55 + /**
  56 + * @remark :保存主域名设置
  57 + * @name :saveWebSetting
  58 + * @author :lyh
  59 + * @method :post
  60 + * @time :2025/3/20 15:38
  61 + */
  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']]);
  69 + }
  70 + return $this->success();
  71 + }
  72 +}