ServerConfigLogic.php
4.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
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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
<?php
namespace App\Http\Logic\Aside\Devops;
use App\Http\Logic\Aside\BaseLogic;
use App\Http\Logic\Aside\Project\ProjectLogic;
use App\Models\Devops\DevopsTask;
use App\Models\Project\Project;
use App\Models\Devops\ServerConfig;
use App\Services\ProjectServer;
use Illuminate\Support\Facades\DB;
/**
* Class ServerConfigLogic
* @package App\Http\Logic\Aside
* @author zbj
* @date 2023/4/23
*/
class ServerConfigLogic extends BaseLogic
{
public function __construct()
{
parent::__construct();
$this->param = $this->requestAll;
$this->model = new ServerConfig();
}
/**
* @remark :获取域名列表
* @name :serviceConfigList
* @author :lyh
* @method :post
* @time :2023/8/2 14:51
*/
public function serviceConfigList($map,$page,$row,$order = 'id',$filed = ['*']){
$lists = $this->model->lists($map,$page,$row,$order,$filed);
return $this->success($lists);
}
/**
* @remark :获取当前数据详情
* @name :getServiceConfig
* @author :lyh
* @method :post
* @time :2023/8/2 17:53
*/
public function getServiceConfig(){
$info = $this->model->read(['id'=>$this->param['id']]);
if($info === false){
$this->fail('当前数据不存在或者被删除');
}
return $this->success($info);
}
/**
* @remark :保存
* @name :save
* @author :lyh
* @method :post
* @time :2023/8/2 17:55
*/
public function serviceConfigSave()
{
DB::beginTransaction();
try {
//保存配置
if(isset($this->param['id']) && !empty($this->param['id'])){
$this->param['updated_at'] = date('Y-m-d H:i:s');
$this->model->edit($this->param,['id'=>$this->param['id']]);
}else{
$this->model->add($this->param);
}
//初始化数据库
DB::commit();
} catch (\Exception $e) {
DB::rollBack();
$this->fail('保存失败');
}
return $this->success();
}
/**
* @remark :初始化数据库
* @name :initializationMysql
* @author :lyh
* @method :post
* @time :2023/8/4 15:08
*/
public function initializationMysql($param){
if ($param['type'] == ServerConfig::TYPE_MYSQL) {
//切换数据库配置
$project = ProjectServer::useProject($param['project_id']);
//创建数据库
ProjectServer::createDatabase($project);
//创建表
ProjectServer::initTable($project);
}
return true;
}
/**
* @remark :删除记录
* @name :delServiceConfig
* @author :lyh
* @method :post
* @time :2023/8/2 15:43
*/
public function delServiceConfig(){
$info = $this->model->read(['id'=>$this->requestAll['id']]);
if($info === false){
$this->fail('当前数据不存在或已被删除');
}
$rs = $this->model->del(['id'=>$this->requestAll['id']]);
if($rs === false){
$this->fail('删除失败');
}
//TODO::上线放开
// if($info['type'] == $this->model::TYPE_MYSQL){
// $sql = 'DROP DATABASE '.$info['title'];
// DB::connection('custom_mysql')->statement($sql);
// }
return $this->success();
}
/**
* 更新指定项目 数据库
* @param $param
* @return array
* @author zbj
* @date 2023/4/24
*/
public function updateTable($param){
$project = ProjectServer::useProject($param['project_id']);
if(!$project){
$this->fail('项目不存在或数据库未配置');
}
DB::connection('custom_mysql')->statement($param['sql']);
return $this->success();
}
/**
* 更新本地 数据库
* @param $param
* @return array
* @author zbj
* @date 2023/4/24
*/
public function updateLocalTable($param){
DB::statement($param['sql']);
return $this->success();
}
/**
* 更新所有项目 数据库
* @param $param
* @return array
* @author zbj
* @date 2023/4/24
*/
public function updateAllTable($param){
DevopsTask::addTask($param['sql']);
return $this->success();
}
}