作者 lyh

gx

@@ -12,6 +12,7 @@ namespace App\Http\Controllers\Bside\SeoSetting; @@ -12,6 +12,7 @@ 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\Models\Domain\DomainInfo; 14 use App\Models\Domain\DomainInfo;
  15 +use App\Models\WebSetting\WebSetting;
15 use Illuminate\Http\Request; 16 use Illuminate\Http\Request;
16 17
17 /** 18 /**
@@ -58,24 +59,42 @@ class DomainSettingController extends BaseController @@ -58,24 +59,42 @@ class DomainSettingController extends BaseController
58 if(!empty($domain)){ 59 if(!empty($domain)){
59 $this->param['domain'] = trim($domain['host']); 60 $this->param['domain'] = trim($domain['host']);
60 } 61 }
61 - //添加域名到域名管理  
62 - $info = $this->model->read(['project_id'=>$this->user['project_id']]);  
63 - if($info === false){  
64 - $domainInfo = $this->model->read(['domain'=>$domain]);  
65 - if ($domainInfo !== false) {  
66 - $this->fail('当前域名已存在'); 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']]);
67 } 75 }
68 - //保存数据  
69 - $id = $this->model->addReturnId(['domain'=>$this->param['domain'],'project_id'=>$this->user['project_id'],'belong_to'=>2,'status'=>1]);  
70 - $projectModel = new Project();  
71 - $projectModel->edit(['domain'=>$id],['project_id'=>$this->user['project_id']]); 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']]);
72 }else{ 95 }else{
73 - $id = $info['id'];  
74 - $domainInfo = $this->model->read(['domain'=>$domain,'id'=>['!=',$id]]);  
75 - if ($domainInfo !== false) {  
76 - $this->fail('当前域名已存在');  
77 - }  
78 - $this->model->edit(['domain'=>$this->param['domain']],['project_id'=>$this->user['project_id']]); 96 + $webSettingModel->edit(['seo_domain'=>$domain],['id'=>$settingInfo['id']]);
79 } 97 }
  98 + return $this->success();
80 } 99 }
81 } 100 }