ServersIpLogic.php
3.0 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
<?php
/**
* @remark :
* @name :ServersIpLogic.php
* @author :lyh
* @method :post
* @time :2024/6/24 16:21
*/
namespace App\Http\Logic\Aside\Devops;
use App\Http\Logic\Aside\BaseLogic;
use App\Models\Devops\Servers;
use App\Models\Devops\ServersIp;
use App\Models\Project\Project;
class ServersIpLogic extends BaseLogic
{
/**
* 数据初始化
*/
public function __construct()
{
parent::__construct();
$this->param = $this->requestAll;
$this->model = new ServersIp();
}
/**
* @remark :获取数据详情
* @name :infoServersIp
* @author :lyh
* @method :post
* @time :2024/6/27 15:52
*/
public function infoServersIp(){
$info = $this->model->read(['id'=>$this->param['id']]);
$projectModel = new Project();
$info['project_title'] = $projectModel->formatQuery(['serve_id'=>$info['id']])->pluck('title')->toArray();
return $this->success($info);
}
/**
* @remark :保存数据
* @name :saveServersIp
* @author :lyh
* @method :post
* @time :2024/6/24 17:28
*/
public function saveServersIp(){
//验证域名是否唯一
if(!isset($this->param['id'])){
$info = $this->model->read(['domain'=>$this->param['domain']]);
if($info !== false){
$this->fail('当前初始域名已存在');
}
}
if(isset($this->param['id']) && !empty($this->param['id'])){
$id = $this->param['id'];
$this->model->edit($this->param,['id'=>$this->param['id']]);
}else{
$id = $this->model->addReturnId($this->param);
}
return $this->success(['id'=>$id]);
}
/**
* @remark :批量添加
* @name :batchSaveServersIp
* @author :lyh
* @method :post
* @time :2024/6/24 17:25
*/
public function batchSaveServersIp(){
//獲取初始域名
$serverModel = new Servers();
$info = $serverModel->read(['id'=>$this->param['servers_id']]);
if($info === false){
$this->fail('當前服務器數據不存在');
}
foreach ($this->param['ip'] as $v){
if(empty($v)){
continue;
}
$param = [
'ip'=>$v,
'domain'=>ip_to_unique_string($v).'.'.$info['domain'],
'servers_id'=>$this->param['servers_id']
];
$this->model->addReturnId($param);
}
return $this->success();
}
/**
* @remark :批量删除数据
* @name :batchDelServersIp
* @author :lyh
* @method :post
* @time :2024/6/27 13:55
*/
public function batchDelServersIp(){
foreach ($this->param['ids'] as $id){
$info = $this->model->read(['id'=>$id],['total']);
if($info['total'] != 0){
continue;
}
$this->model->edit(['status'=>1],['id'=>$id]);
}
return $this->success();
}
}