DeleteController.class.php
2.62 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
<?php
/**
* Created by PhpStorm.
* User: liyifei2012it
* Date: 17/4/27
* Time: 14:50
*/
namespace Apicp\Controller\Source;
use Common\Common\AttachOperation;
use VcySDK\Service;
use VcySDK\Cron;
use Common\Service\TaskService;
use Common\Service\SourceService;
use Common\Service\ArticleChapterService;
class DeleteController extends \Apicp\Controller\AbstractController
{
/**
* Delete
* @author liyifei
* @desc 素材删除接口(支持单、多个删除)
* @param Array source_ids:true 素材ID集合
* @return array // 单个删除时,返回该素材被使用的课程ID;批量删除时,返回不可删除的素材ID;
*/
public function Index_post()
{
$source_ids = I('post.source_ids');
if (empty($source_ids) || !is_array($source_ids)) {
E('_ERR_SOURCE_PARAM_FORMAT');
}
// 初始化返回值
$data = [];
// 素材是否被使用
$chapterServ = new ArticleChapterService();
$chapterList = $chapterServ->list_by_conds(['source_id' => $source_ids]);
// 没有被使用
if (empty($chapterList)) {
$sourceServ = new SourceService();
// 删除素材
$sourceServ->delete_by_conds(['source_id' => $source_ids]);
// 素材-计划任务id数据
$taskServ = new TaskService();
$task_list = $taskServ->list_by_conds(['source_id' => $source_ids]);
// 删除定时任务
if (!empty($task_list)) {
// 计划任务id集合
$cron_ids = array_filter(array_column($task_list, 'cron_id'));
// 删除UC计划任务
$cronSdk = new Cron(Service::instance());
foreach ($cron_ids as $cron_id) {
$cronSdk->delete($cron_id);
}
// 删除本地计划任务记录
$taskServ->delete_by_conds(['cron_id' => $cron_ids]);
}
// 删除附件操作
$attach_serv = new AttachOperation();
$attach_serv->delete_attach(APP_DIR, 'source', $source_ids);
} else {
if (count($source_ids) == 1) {
// 单个删除时,返回使用该素材的课程ID列表
$data = array_values(array_unique(array_column($chapterList, 'article_id')));
} else {
// 批量删除时,返回被使用的素材ID
$data = array_unique(array_column($chapterList, 'source_id'));
}
}
$this->_result = [
'list' => array_values($data),
];
}
}