DomainSettingLogic.php
2.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
<?php
/**
* @remark :
* @name :DomainSettingLogic.php
* @author :lyh
* @method :post
* @time :2025/3/20 16:01
*/
namespace App\Http\Logic\Bside\SeoSetting;
use App\Http\Logic\Bside\BaseLogic;
use App\Models\SeoSetting\KeywordUrl;
use App\Models\WebSetting\WebSetting;
class DomainSettingLogic extends BaseLogic
{
public function __construct()
{
parent::__construct();
$this->param = $this->requestAll;
}
/**
* @remark :保存设置
* @name :saveDomain
* @author :lyh
* @method :post
* @time :2025/3/20 16:12
*/
public function saveDomain(){
$domain = parse_url($this->param['domain'], PHP_URL_HOST);
if(!empty($domain)){
$this->param['domain'] = trim($domain['host']);
}
//保存一条主域名记录
try {
$this->saveWebSetting($this->param['domain']);
//添加域名到域名管理
$info = $this->model->read(['project_id'=>$this->user['project_id']]);
if($info === false){
//保存数据
$this->param['domain'] = str_replace('www','blog',$this->param['domain']);
$id = $this->model->addReturnId(['domain'=>$this->param['domain'],'project_id'=>$this->user['project_id'],'belong_to'=>2,'status'=>1]);
$projectModel = new Project();
$projectModel->edit(['domain'=>$id],['project_id'=>$this->user['project_id']]);
}else{
$this->model->edit(['domain'=>$this->param['domain']],['project_id'=>$this->user['project_id']]);
}
}catch (\Exception $e){
$this->fail('保存失败,请联系管理员');
}
}
/**
* @remark :保存主域名设置
* @name :saveWebSetting
* @author :lyh
* @method :post
* @time :2025/3/20 15:38
*/
public function saveWebSetting($domain){
$webSettingModel = new WebSetting();
$settingInfo = $webSettingModel->read(['project_id'=>$this->user['project_id']]);
if($settingInfo === false){
$webSettingModel->add(['seo_domain'=>$domain,'project_id'=>$this->user['project_id']]);
}else{
$webSettingModel->edit(['seo_domain'=>$domain],['id'=>$settingInfo['id']]);
}
return $this->success();
}
}