|
@@ -41,23 +41,23 @@ class ServerInformationLogic extends BaseLogic |
|
@@ -41,23 +41,23 @@ class ServerInformationLogic extends BaseLogic |
|
41
|
{
|
41
|
{
|
|
42
|
$request = $this->param ?? [];
|
42
|
$request = $this->param ?? [];
|
|
43
|
$service = new ServerInformation();
|
43
|
$service = new ServerInformation();
|
|
44
|
- $this->extracted($request, $service);
|
|
|
|
45
|
- if ($this->checkIp($service->ip)) {
|
|
|
|
46
|
- return $this->fail('服务器信息添加失败,ip已存在');
|
44
|
+ $this->extracted( $request, $service );
|
|
|
|
45
|
+ if ( $this->checkIp( $service->ip ) ) {
|
|
|
|
46
|
+ return $this->fail( '服务器信息添加失败,ip已存在' );
|
|
47
|
}
|
47
|
}
|
|
48
|
DB::beginTransaction();
|
48
|
DB::beginTransaction();
|
|
49
|
|
49
|
|
|
50
|
- if ($service->save()) {
|
50
|
+ if ( $service->save() ) {
|
|
51
|
$original = $service->getOriginal();
|
51
|
$original = $service->getOriginal();
|
|
52
|
$original['type'] = $request['type'];
|
52
|
$original['type'] = $request['type'];
|
|
53
|
$original['belong_to'] = $request['belong_to'];
|
53
|
$original['belong_to'] = $request['belong_to'];
|
|
54
|
// 添加日志
|
54
|
// 添加日志
|
|
55
|
- $this->server_action_log(ServerInformationLog::ACTION_ADD, $original, $original, '添加服务器信息成功 - ID : ' . $service->id);
|
55
|
+ $this->server_action_log( ServerInformationLog::ACTION_ADD, $original, $original, '添加服务器信息成功 - ID : ' . $service->id );
|
|
56
|
DB::commit();
|
56
|
DB::commit();
|
|
57
|
return $this->success();
|
57
|
return $this->success();
|
|
58
|
}
|
58
|
}
|
|
59
|
DB::rollBack();
|
59
|
DB::rollBack();
|
|
60
|
- return $this->fail('服务器信息添加失败');
|
60
|
+ return $this->fail( '服务器信息添加失败' );
|
|
61
|
|
61
|
|
|
62
|
}
|
62
|
}
|
|
63
|
|
63
|
|
|
@@ -73,49 +73,49 @@ class ServerInformationLogic extends BaseLogic |
|
@@ -73,49 +73,49 @@ class ServerInformationLogic extends BaseLogic |
|
73
|
$fields_array = $service->FieldsArray();
|
73
|
$fields_array = $service->FieldsArray();
|
|
74
|
$request = $this->param ?? [];
|
74
|
$request = $this->param ?? [];
|
|
75
|
$original = $service->getOriginal();
|
75
|
$original = $service->getOriginal();
|
|
76
|
- $original['type'] = $service->ServiceStr($original['type']);
|
|
|
|
77
|
- $original['belong_to'] = $service->BelongToStr($original['belong_to']);
|
|
|
|
78
|
- $this->extracted($request, $service);
|
76
|
+ $original['type'] = $service->ServiceStr( $original['type'] );
|
|
|
|
77
|
+ $original['belong_to'] = $service->BelongToStr( $original['belong_to'] );
|
|
|
|
78
|
+ $this->extracted( $request, $service, $original );
|
|
79
|
// 检查ip是否存在
|
79
|
// 检查ip是否存在
|
|
80
|
- if ($service->ip != $request['ip']) {
|
|
|
|
81
|
- if ($this->checkIp($request['ip'])) {
|
|
|
|
82
|
- $this->fail('服务器信息修改失败,ip已存在', Code::USER_ERROR);
|
80
|
+ if ( $service->ip != $request['ip'] ) {
|
|
|
|
81
|
+ if ( $this->checkIp( $request['ip'] ) ) {
|
|
|
|
82
|
+ $this->fail( '服务器信息修改失败,ip已存在', Code::USER_ERROR );
|
|
83
|
}
|
83
|
}
|
|
84
|
}
|
84
|
}
|
|
85
|
DB::beginTransaction();
|
85
|
DB::beginTransaction();
|
|
86
|
- if ($service->save()) {
|
86
|
+ if ( $service->save() ) {
|
|
87
|
$revised = $service->getAttributes();
|
87
|
$revised = $service->getAttributes();
|
|
88
|
- $diff = array_diff_assoc($original, $revised);
|
|
|
|
89
|
- unset($diff['created_at']);
|
|
|
|
90
|
- unset($diff['updated_at']);
|
|
|
|
91
|
- unset($diff['deleted']);
|
88
|
+ $diff = array_diff_assoc( $original, $revised );
|
|
|
|
89
|
+ unset( $diff['created_at'] );
|
|
|
|
90
|
+ unset( $diff['updated_at'] );
|
|
|
|
91
|
+ unset( $diff['deleted'] );
|
|
92
|
$remarks = '';
|
92
|
$remarks = '';
|
|
93
|
- if ($diff) {
|
93
|
+ if ( $diff ) {
|
|
94
|
$remarks .= '修改ID为 ' . $service->id . ' 的服务器信息,修改内容为:';
|
94
|
$remarks .= '修改ID为 ' . $service->id . ' 的服务器信息,修改内容为:';
|
|
95
|
- foreach ($diff as $key => $value) {
|
95
|
+ foreach ( $diff as $key => $value ) {
|
|
96
|
$remarks .= $fields_array[$key] . ' 由 ' . $value . ' 修改为 ' . $revised[$key] . '; ';
|
96
|
$remarks .= $fields_array[$key] . ' 由 ' . $value . ' 修改为 ' . $revised[$key] . '; ';
|
|
97
|
}
|
97
|
}
|
|
98
|
} else {
|
98
|
} else {
|
|
99
|
$remarks .= '修改ID为 ' . $service->id . ' 的服务器信息,无修改';
|
99
|
$remarks .= '修改ID为 ' . $service->id . ' 的服务器信息,无修改';
|
|
100
|
}
|
100
|
}
|
|
101
|
// 添加日志
|
101
|
// 添加日志
|
|
102
|
- $this->server_action_log(ServerInformationLog::ACTION_UPDATE, $original, $revised, $remarks);
|
102
|
+ $this->server_action_log( ServerInformationLog::ACTION_UPDATE, $original, $revised, $remarks );
|
|
103
|
DB::commit();
|
103
|
DB::commit();
|
|
104
|
return $this->success();
|
104
|
return $this->success();
|
|
105
|
}
|
105
|
}
|
|
106
|
DB::rollBack();
|
106
|
DB::rollBack();
|
|
107
|
- return $this->fail('服务器信息修改失败');
|
107
|
+ return $this->fail( '服务器信息修改失败' );
|
|
108
|
}
|
108
|
}
|
|
109
|
|
109
|
|
|
110
|
- public function getService(int $deleted = ServerInformation::DELETED_NORMAL)
|
110
|
+ public function getService( int $deleted = ServerInformation::DELETED_NORMAL )
|
|
111
|
{
|
111
|
{
|
|
112
|
$id = $this->param['id'] ?? 0;
|
112
|
$id = $this->param['id'] ?? 0;
|
|
113
|
- if (!$id) {
|
|
|
|
114
|
- return $this->fail('ID不能为空');
|
113
|
+ if ( !$id ) {
|
|
|
|
114
|
+ return $this->fail( 'ID不能为空' );
|
|
115
|
}
|
115
|
}
|
|
116
|
- $data = ServerInformation::query()->where('deleted', $deleted)->find($id);
|
|
|
|
117
|
- if (!$data) {
|
|
|
|
118
|
- return $this->fail('数据不存在!');
|
116
|
+ $data = ServerInformation::query()->where( 'deleted', $deleted )->find( $id );
|
|
|
|
117
|
+ if ( !$data ) {
|
|
|
|
118
|
+ return $this->fail( '数据不存在!' );
|
|
119
|
}
|
119
|
}
|
|
120
|
return $data;
|
120
|
return $data;
|
|
121
|
}
|
121
|
}
|
|
@@ -125,10 +125,10 @@ class ServerInformationLogic extends BaseLogic |
|
@@ -125,10 +125,10 @@ class ServerInformationLogic extends BaseLogic |
|
125
|
* @param $ip
|
125
|
* @param $ip
|
|
126
|
* @return bool
|
126
|
* @return bool
|
|
127
|
*/
|
127
|
*/
|
|
128
|
- public function checkIp($ip)
|
128
|
+ public function checkIp( $ip )
|
|
129
|
{
|
129
|
{
|
|
130
|
- $usIp = ServerInformation::query()->where('ip', $ip)->first();
|
|
|
|
131
|
- if ($usIp) {
|
130
|
+ $usIp = ServerInformation::query()->where( 'ip', $ip )->first();
|
|
|
|
131
|
+ if ( $usIp ) {
|
|
132
|
return true;
|
132
|
return true;
|
|
133
|
} else {
|
133
|
} else {
|
|
134
|
return false;
|
134
|
return false;
|
|
@@ -142,15 +142,15 @@ class ServerInformationLogic extends BaseLogic |
|
@@ -142,15 +142,15 @@ class ServerInformationLogic extends BaseLogic |
|
142
|
* @throws AsideGlobalException
|
142
|
* @throws AsideGlobalException
|
|
143
|
* @throws BsideGlobalException
|
143
|
* @throws BsideGlobalException
|
|
144
|
*/
|
144
|
*/
|
|
145
|
- public function serverInfo(int $deleted = ServerInformation::DELETED_NORMAL)
|
145
|
+ public function serverInfo( int $deleted = ServerInformation::DELETED_NORMAL )
|
|
146
|
{
|
146
|
{
|
|
147
|
$id = $this->param['id'] ?? 0;
|
147
|
$id = $this->param['id'] ?? 0;
|
|
148
|
- if (!$id) {
|
|
|
|
149
|
- return $this->fail('ID不能为空');
|
148
|
+ if ( !$id ) {
|
|
|
|
149
|
+ return $this->fail( 'ID不能为空' );
|
|
150
|
}
|
150
|
}
|
|
151
|
- $data = ServerInformation::query()->where('deleted', $deleted)->find($id, ['type', 'ip', 'title', 'belong_to', 'ports', 'created_at', 'updated_at']);
|
|
|
|
152
|
- if (!$data) {
|
|
|
|
153
|
- return $this->fail('数据不存在!');
|
151
|
+ $data = ServerInformation::query()->where( 'deleted', $deleted )->find( $id, [ 'type', 'ip', 'title', 'belong_to', 'ports', 'created_at', 'updated_at' ] );
|
|
|
|
152
|
+ if ( !$data ) {
|
|
|
|
153
|
+ return $this->fail( '数据不存在!' );
|
|
154
|
}
|
154
|
}
|
|
155
|
return $data;
|
155
|
return $data;
|
|
156
|
}
|
156
|
}
|
|
@@ -161,10 +161,10 @@ class ServerInformationLogic extends BaseLogic |
|
@@ -161,10 +161,10 @@ class ServerInformationLogic extends BaseLogic |
|
161
|
* @param array $original 原始数据
|
161
|
* @param array $original 原始数据
|
|
162
|
* @param array $revised 修改后数据
|
162
|
* @param array $revised 修改后数据
|
|
163
|
*/
|
163
|
*/
|
|
164
|
- public function server_action_log(int $action = ServerInformationLog::ACTION_ADD, array $original = [], array $revised = [], $remarks = '')
|
164
|
+ public function server_action_log( int $action = ServerInformationLog::ACTION_ADD, array $original = [], array $revised = [], $remarks = '' )
|
|
165
|
{
|
165
|
{
|
|
166
|
$log = new ServerInformationLog();
|
166
|
$log = new ServerInformationLog();
|
|
167
|
- $this->log($log, $action, $original, $revised, $remarks);
|
167
|
+ $this->log( $log, $action, $original, $revised, $remarks );
|
|
168
|
}
|
168
|
}
|
|
169
|
|
169
|
|
|
170
|
/**
|
170
|
/**
|
|
@@ -172,14 +172,14 @@ class ServerInformationLogic extends BaseLogic |
|
@@ -172,14 +172,14 @@ class ServerInformationLogic extends BaseLogic |
|
172
|
* @param $service
|
172
|
* @param $service
|
|
173
|
* @return void
|
173
|
* @return void
|
|
174
|
*/
|
174
|
*/
|
|
175
|
- public function extracted(array $request, $service)
|
175
|
+ public function extracted( array $request, $service, array $original = [] )
|
|
176
|
{
|
176
|
{
|
|
177
|
- $service->type = trim($request['type']); // 服务器类型
|
|
|
|
178
|
- $service->ip = trim($request['ip']); // 服务器ip
|
|
|
|
179
|
- $service->title = trim($request['title']); // 服务器标题
|
|
|
|
180
|
- $service->belong_to = trim($request['belong_to']); // 服务器归属
|
|
|
|
181
|
- $service->sshpass = trim($request['sshpass']); // ssh密码
|
|
|
|
182
|
- $service->ports = trim($request['ports']); // ssh端口
|
177
|
+ $service->type = trim( $request['type'] ) ?? $original['type']; // 服务器类型
|
|
|
|
178
|
+ $service->ip = trim( $request['ip'] ) ?? $original['ip']; // 服务器ip
|
|
|
|
179
|
+ $service->title = trim( $request['title'] ) ?? $original['title']; // 服务器标题
|
|
|
|
180
|
+ $service->belong_to = trim( $request['belong_to'] ) ?? $original['belong_to']; // 服务器归属
|
|
|
|
181
|
+ $service->sshpass = trim( $request['sshpass'] ) ?? $original['sshpass']; // ssh密码
|
|
|
|
182
|
+ $service->ports = trim( $request['ports'] ) ?? $original['ports']; // ssh端口
|
|
183
|
}
|
183
|
}
|
|
184
|
|
184
|
|
|
185
|
/**
|
185
|
/**
|
|
@@ -188,27 +188,27 @@ class ServerInformationLogic extends BaseLogic |
|
@@ -188,27 +188,27 @@ class ServerInformationLogic extends BaseLogic |
|
188
|
* @throws AsideGlobalException
|
188
|
* @throws AsideGlobalException
|
|
189
|
* @throws BsideGlobalException
|
189
|
* @throws BsideGlobalException
|
|
190
|
*/
|
190
|
*/
|
|
191
|
- public function get_batch_update($action = ServerInformationLog::ACTION_DELETE, $deleted = ServerInformation::DELETED_NORMAL)
|
191
|
+ public function get_batch_update( $action = ServerInformationLog::ACTION_DELETE, $deleted = ServerInformation::DELETED_NORMAL )
|
|
192
|
{
|
192
|
{
|
|
193
|
$ids = $this->getIds();
|
193
|
$ids = $this->getIds();
|
|
194
|
- $data = ServerInformation::query()->whereIn('id', $ids)->where('deleted', $deleted)->get();
|
|
|
|
195
|
- $restore_ids = $data->pluck('id')->toArray();
|
194
|
+ $data = ServerInformation::query()->whereIn( 'id', $ids )->where( 'deleted', $deleted )->get();
|
|
|
|
195
|
+ $restore_ids = $data->pluck( 'id' )->toArray();
|
|
196
|
$actionArr = ServerInformationLog::actionArr();
|
196
|
$actionArr = ServerInformationLog::actionArr();
|
|
197
|
$actionStr = $actionArr[$action];
|
197
|
$actionStr = $actionArr[$action];
|
|
198
|
- if (empty($restore_ids)) {
|
|
|
|
199
|
- $this->fail($actionStr . '服务器信息不存在!', Code::USER_ERROR);
|
198
|
+ if ( empty( $restore_ids ) ) {
|
|
|
|
199
|
+ $this->fail( $actionStr . '服务器信息不存在!', Code::USER_ERROR );
|
|
200
|
}
|
200
|
}
|
|
201
|
$original = $data->toArray();
|
201
|
$original = $data->toArray();
|
|
202
|
DB::beginTransaction();
|
202
|
DB::beginTransaction();
|
|
203
|
try {
|
203
|
try {
|
|
204
|
$update = $deleted == ServerInformation::DELETED_NORMAL ? ServerInformation::DELETED_DELETE : ServerInformation::DELETED_NORMAL;
|
204
|
$update = $deleted == ServerInformation::DELETED_NORMAL ? ServerInformation::DELETED_DELETE : ServerInformation::DELETED_NORMAL;
|
|
205
|
- ServerInformation::query()->whereIn('id', $restore_ids)->update(['deleted' => $update]);
|
|
|
|
206
|
- $this->server_action_log($action, $original, $original, $actionStr . '服务器信息 - ID : ' . implode(', ', $restore_ids));
|
205
|
+ ServerInformation::query()->whereIn( 'id', $restore_ids )->update( [ 'deleted' => $update ] );
|
|
|
|
206
|
+ $this->server_action_log( $action, $original, $original, $actionStr . '服务器信息 - ID : ' . implode( ', ', $restore_ids ) );
|
|
207
|
DB::commit();
|
207
|
DB::commit();
|
|
208
|
return $this->success();
|
208
|
return $this->success();
|
|
209
|
- } catch (\Exception $e) {
|
209
|
+ } catch ( \Exception $e ) {
|
|
210
|
DB::rollBack();
|
210
|
DB::rollBack();
|
|
211
|
- return $this->fail('服务器信息' . $actionStr . '失败', Code::USER_ERROR);
|
211
|
+ return $this->fail( '服务器信息' . $actionStr . '失败', Code::USER_ERROR );
|
|
212
|
}
|
212
|
}
|
|
213
|
}
|
213
|
}
|
|
214
|
|
214
|
|
|
@@ -221,16 +221,16 @@ class ServerInformationLogic extends BaseLogic |
|
@@ -221,16 +221,16 @@ class ServerInformationLogic extends BaseLogic |
|
221
|
public function getIds()
|
221
|
public function getIds()
|
|
222
|
{
|
222
|
{
|
|
223
|
$id = $this->param['id'] ?? 0;
|
223
|
$id = $this->param['id'] ?? 0;
|
|
224
|
- if (!$id) {
|
|
|
|
225
|
- return $this->fail('参数错误');
|
224
|
+ if ( !$id ) {
|
|
|
|
225
|
+ return $this->fail( '参数错误' );
|
|
226
|
}
|
226
|
}
|
|
227
|
$ids = [];
|
227
|
$ids = [];
|
|
228
|
- if (!is_array($id)) {
|
|
|
|
229
|
- $ids = explode(',', $id);
|
228
|
+ if ( !is_array( $id ) ) {
|
|
|
|
229
|
+ $ids = explode( ',', $id );
|
|
230
|
}
|
230
|
}
|
|
231
|
- $ids = array_filter($ids, 'intval');
|
|
|
|
232
|
- if (empty($ids)) {
|
|
|
|
233
|
- return $this->fail('参数错误');
|
231
|
+ $ids = array_filter( $ids, 'intval' );
|
|
|
|
232
|
+ if ( empty( $ids ) ) {
|
|
|
|
233
|
+ return $this->fail( '参数错误' );
|
|
234
|
}
|
234
|
}
|
|
235
|
return $ids;
|
235
|
return $ids;
|
|
236
|
}
|
236
|
}
|