DeleteController.class.php
2.37 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
<?php
/**
* Created by PhpStorm.
* User: liyifei2012it
* Date: 17/7/26
* Time: 14:08
*/
namespace Apicp\Controller\Customtask;
use Common\Common\AttachOperation;
use Think\Log;
use VcySDK\Service;
use VcySDK\Cron;
use Common\Service\CustomtaskService;
use Common\Service\CustomtaskRightService;
use Common\Service\CustomtaskContentService;
use Common\Service\CustomtaskCronService;
use Common\Service\UserContentService;
use Common\Service\UserTaskService;
class DeleteController extends \Apicp\Controller\AbstractController
{
/**
* Delete
* @author liyifei
* @desc 常规任务删除接口
* @param array customtask_ids 常规任务ID
* @return void
*/
public function Index_post()
{
$customtask_ids = I('post.customtask_ids');
if (!is_array($customtask_ids) || empty($customtask_ids)) {
E('_ERR_CUSTOMTASK_POST_PARAMS');
}
$conds = ['customtask_id' => $customtask_ids];
// 删除常规任务
$taskServ = new CustomtaskService();
$taskServ->delete_by_conds($conds);
// 删除任务适用范围
$rightServ = new CustomtaskRightService();
$rightServ->delete_by_conds($conds);
// 删除任务内容
$contentServ = new CustomtaskContentService();
$contentServ->delete_by_conds($conds);
// 删除用户常规任务内容
$userContentServ = new UserContentService();
$userContentServ->delete_by_conds($conds);
// 删除用户常规任务进度
$userTaskServ = new UserTaskService();
$userTaskServ->delete_by_conds($conds);
// 结束计划任务
$cronServ = new CustomtaskCronService();
$list = $cronServ->list_by_conds($conds);
if (!empty($list)) {
$cronIds = array_column($list, 'cron_id');
$cronSdk = new Cron(Service::instance());
foreach ($cronIds as $cronId) {
try {
$cronSdk->delete($cronId);
} catch (\Think\Exception $e) {
Log::record("删除UC计划任务失败, cronId={$cronId}");
}
}
}
// 删除计划任务
$cronServ->delete_by_conds($conds);
// 删除附件操作
$attach_serv = new AttachOperation();
$attach_serv->delete_attach(APP_DIR, 'customtask', $customtask_ids);
}
}