StopCustomtaskController.class.php
1.9 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
<?php
/**
* Created by PhpStorm.
* User: liyifei2012it
* Date: 17/6/13
* Time: 18:13
*/
namespace Frontend\Controller\Callback;
use Common\Common\Constant;
use Common\Service\CustomtaskCronService;
use Common\Service\CustomtaskService;
use Common\Service\UserTaskService;
use Think\Log;
class StopCustomtaskController extends AbstractController
{
/**
* 定时停止常规任务回调接口
* @author tangxingguo
*/
public function Index()
{
Log::record('customtask stop cron callback get: ' . var_export($_GET, true), Log::INFO);
$customtaskId = I('get.customtask_id', 0, 'intval');
$cronId = I('get.cron_id', '', 'trim');
if ($customtaskId == 0 || empty($cronId)) {
exit('FAIL');
}
// 任务信息
$customtaskServ = new CustomtaskService();
$customtask = $customtaskServ->get($customtaskId);
if (empty($customtask)) {
Log::record('customtask stop cron callback info empty', Log::INFO);
exit('FAIL');
}
// 任务状态不为进行中
if ($customtask['task_status'] != Constant::CUSTOMTASK_STATUS_PROCESS) {
Log::record('customtask stop cron callback info error: ' . var_export($customtask, true), Log::INFO);
exit('FAIL');
}
// 任务状态改为已终止
$customtaskServ->update($customtaskId, ['task_status' => Constant::CUSTOMTASK_STATUS_END]);
// 未完成人员任务状态改为终止
$userTaskServ = new UserTaskService();
$userTaskServ->update_by_conds([
'customtask_id' => $customtaskId,
'task_status' => Constant::CUSTOMTASK_STATUS_PROCESS,
], ['task_status' => Constant::CUSTOMTASK_STATUS_END]);
// 删除计划任务
$cronServ = new CustomtaskCronService();
$cronServ->deleteCron_deprecated($cronId);
exit('SUCCESS');
}
}