StopController.class.php
2.71 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
<?php
/**
* Created by PhpStorm.
* User: zhonglei
* Date: 17/7/25
* Time: 11:57
*/
namespace Apicp\Controller\Customtask;
use Com\PackageValidate;
use Common\Common\Constant;
use Common\Common\TaskHelper;
use Common\Service\CustomtaskCronService;
use Common\Service\CustomtaskService;
use Common\Service\UserTaskService;
class StopController extends \Apicp\Controller\AbstractController
{
/**
* Stop
* @author tangxingguo
* @desc 终止常规任务接口
* @param Int customtask_id 常规任务ID
* @param String stop_desc 终止原因
*/
public function Index_post()
{
// 验证规则
$rules = [
'customtask_id' => 'require|integer',
'stop_desc' => 'require',
];
// 验证数据
$validate = new PackageValidate($rules, [], array_keys($rules));
$customtaskId = $validate->postData['customtask_id'];
$stopDesc = $validate->postData['stop_desc'];
// 取数据
$customtaskServ = new CustomtaskService();
$customtaskInfo = $customtaskServ->get($customtaskId);
if (empty($customtaskInfo)) {
E('_ERR_CUSTOMTASK_NOT_FOUND');
}
if ($customtaskInfo['task_status'] != Constant::CUSTOMTASK_STATUS_PROCESS) {
// 进行中的任务才能进行终止
E('_ERR_DAILYTASK_STATUS_NOT_STOP');
}
// 终止常规任务
$user = $this->_login->user;
$data = [
'task_status' => Constant::CUSTOMTASK_STATUS_STOP,
'stop_desc' => $stopDesc,
'stop_ea_id' => $user['eaId'],
'stop_ea_name' => $user['eaRealname'],
'stop_time' => MILLI_TIME,
];
$customtaskServ->update($customtaskId, $data);
if ($customtaskInfo['task_status'] == Constant::CUSTOMTASK_STATUS_PROCESS) {
// 任务正在进行,消息通知未完成人员
$customtaskInfo = $customtaskServ->get($customtaskId);
$taskHelper = new TaskHelper();
$taskHelper->preSendCustomtaskStopMsg($customtaskInfo);
}
// 将用户任务状态修改为已终止
$userTaskServ = new UserTaskService();
$userTaskServ->update_by_conds([
'customtask_id' => $customtaskId,
'task_status' => Constant::CUSTOMTASK_STATUS_PROCESS,
], ['task_status' => Constant::CUSTOMTASK_STATUS_STOP]);
// 删除定时任务
$cronServ = new CustomtaskCronService();
$cronList = $cronServ->list_by_conds(['customtask_id' => $customtaskId]);
if (!empty($cronList)) {
foreach ($cronList as $v) {
$cronServ->deleteCron_deprecated($v['cron_id']);
}
}
}
}