AutoPullController.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
82
83
84
85
86
87
<?php
namespace App\Http\Controllers\Aside\AutoPull;
use App\Enums\Common\Code;
use App\Helper\Arr;
use App\Http\Controllers\Aside\BaseController;
use App\Models\AutoPull\AutoPullNotify;
use App\Models\Manage\Manage;
class AutoPullController extends BaseController
{
/**
* 获取自动拉取代码任务列表
* @author Akun
* @date 2024/08/26 15:49
*/
public function getTaskLists()
{
$autoModule = new AutoPullNotify();
$lists = $autoModule->lists($this->map, $this->page, $this->row);
if (!empty($lists)) {
$manage_model = new Manage();
foreach ($lists['list'] as $k => $v) {
$lists['list'][$k]['operator_name'] = $manage_model->getName($v['user_id']);
$lists['list'][$k]['server_name'] = AutoPullNotify::serversMap()[$v['server_id']];
$process = Arr::s2a($v['process']);
$process_name = [];
if ($process) {
foreach ($process as $kp => $vp) {
$process_name[$kp] = AutoPullNotify::processMap()[$vp];
}
}
$lists['list'][$k]['process_name'] = $process_name ? $process_name : ['无'];
}
}
$this->response('success', Code::SUCCESS, $lists);
}
/**
* 添加自动拉取代码任务
* @author Akun
* @date 2024/08/26 16:31
*/
public function saveTask()
{
$this->request->validate([
'server_id' => 'required',
], [
'server_id.required' => '服务器不能为空'
]);
$model = new AutoPullNotify();
foreach ($this->param['server_id'] as $v) {
$model->add([
'user_id' => $this->uid,
'server_id' => $v,
'process' => Arr::a2s($this->param['process'] ?? []),
'status' => 0
]);
}
$this->response('success');
}
/**
* 获取服务器及进程配置
* @author Akun
* @date 2024/08/26 16:07
*/
public function taskMap()
{
$servers = AutoPullNotify::serversMap();
$process = AutoPullNotify::processMap();
$lists = [
'servers' => $servers,
'process' => $process
];
$this->response('success', Code::SUCCESS, $lists);
}
}