DomainSettingController.php
2.4 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
73
74
75
76
77
78
79
80
81
<?php
/**
* @remark :
* @name :DomainSettingController.php
* @author :lyh
* @method :post
* @time :2025/3/20 11:23
*/
namespace App\Http\Controllers\Bside\SeoSetting;
use App\Enums\Common\Code;
use App\Http\Controllers\Bside\BaseController;
use App\Models\Domain\DomainInfo;
use Illuminate\Http\Request;
/**
* @remark :白帽系统设置二级域名
* @name :DomainSettingController
* @author :lyh
* @method :post
* @time :2025/3/20 11:23
*/
class DomainSettingController extends BaseController
{
public function __construct(Request $request)
{
$this->model = new DomainInfo();
parent::__construct($request);
}
/**
* @remark :获取当前二级域名详情
* @name :getInfo
* @author :lyh
* @method :post
* @time :2025/3/20 11:26
*/
public function getInfo(){
$data = $this->model->read(['project_id'=>$this->user['project_id']]);
$this->response('success',Code::SUCCESS,$data);
}
/**
* @remark :保存域名数据
* @name :save
* @author :lyh
* @method :post
* @time :2025/3/20 11:29
*/
public function save(){
$this->request->validate([
'domain'=>['required'],
],[
'domain.required' => 'domain不能为空',
]);
$domain = parse_url($this->param['domain'], PHP_URL_HOST);
if(!empty($domain)){
$this->param['domain'] = trim($domain['host']);
}
//添加域名到域名管理
$info = $this->model->read(['project_id'=>$this->user['project_id']]);
if($info === false){
$domainInfo = $this->model->read(['domain'=>$domain]);
if ($domainInfo !== false) {
$this->fail('当前域名已存在');
}
//保存数据
$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{
$id = $info['id'];
$domainInfo = $this->model->read(['domain'=>$domain,'id'=>['!=',$id]]);
if ($domainInfo !== false) {
$this->fail('当前域名已存在');
}
$this->model->edit(['domain'=>$this->param['domain']],['project_id'=>$this->user['project_id']]);
}
}
}