DomainInfoLogic.php
3.9 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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
<?php
namespace App\Http\Logic\Aside\Domain;
use App\Http\Logic\Aside\BaseLogic;
use App\Models\Domain\DomainInfo;
use App\Models\Project\DeployOptimize;
use App\Models\Project\Project;
use GuzzleHttp\Client;
use GuzzleHttp\Exception\GuzzleException;
use Illuminate\Support\Carbon;
class DomainInfoLogic extends BaseLogic
{
public function __construct()
{
parent::__construct();
$this->model = new DomainInfo();
$this->param = $this->requestAll;
}
/**
* @remark :保存域名
* @name :createDomain
* @author :lyh
* @method :post
* @time :2023/8/1 14:52
*/
public function saveDomain()
{
//验证域名
$this->verifyDomain($this->param['domain'],isset($this->param['id']) ?? '');
if(isset($this->param['id']) && !empty($this->param['id'])){
$rs = $this->model->edit($this->param,['id'=>$this->param['id']]);
}else{
$rs = $this->model->add($this->param);
}
if($rs === false){
$this->fail('error');
}
return $this->success();
}
/**
* @remark :验证域名是否存在
* @name :verifyDomain
* @author :lyh
* @method :post
* @time :2023/8/1 14:59
*/
public function verifyDomain($domain,$id = ''){
if(!empty($id)){
$info = $this->model->read(['domain'=>$domain,'id'=>['!=',$id]]);
if ($info !== false) {
$this->fail('当前域名已存在');
}
}else{
$info = $this->model->read(['domain'=>$domain]);
if ($info !== false) {
$this->fail('当前域名已存在');
}
}
return $this->success();
}
/**
* @remark :修改当前域名状态
* @name :editStatus
* @author :lyh
* @method :post
* @time :2023/8/1 15:43
*/
public function editDomainStatus(){
//查看当前域名是否有项目在使用
if($this->param['status'] != $this->model::STATUS_ONE){
$info = $this->model->read(['id'=>$this->param['id']]);
if($info === false){
$this->fail('当前域名有项目正在使用中');
}
}
$rs = $this->model->edit(['status'=>$this->param['status']],['id'=>$this->param['id']]);
if($rs === false){
$this->fail('error');
}
return $this->success();
}
/**
* @remark :获取所有项目列表
* @name :getProjectList
* @author :lyh
* @method :post
* @time :2023/8/1 16:10
*/
public function getProjectList($map){
$projectModel = new Project();
$lists = $projectModel->list($map,'id',['id','title']);
return $this->success($lists);
}
/**
* @remark :删除域名
* @name :delDomain
* @author :lyh
* @method :post
* @time :2023/8/1 15:41
*/
public function delDomain(){
$ids = $this->param['id'];
foreach ($ids as $k => $v){
$info = $this->model->read(['id'=>$v]);
$deployOptimizeModel = new DeployOptimize();
$domainInfo = $deployOptimizeModel->read(['domain'=>$info['domain']]);
if($domainInfo !== false){
$this->fail('当前域名正在使用中');
}
}
$this->param['id'] = ['in',$ids];
$rs = $this->model->del($this->param);
if($rs === false){
$this->fail('error');
}
return $this->success();
}
public function infoDomain(){
$info = $this->model->read(['id'=>$this->param['id']]);
if($info === false){
$this->fail('当前数据不存在或者已被删除');
}
if(!empty($info['project_id'])){
$info['company'] = (new Project())->read(['id'=>$info['project_id']],['title'])['title'];
}
return $this->success($info);
}
}