DeleteController.class.php
6.08 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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
<?php
/**
* 【考试中心-后台】 删除试卷
* @author: houyingcai
* @email: 594609175@qq.com
* @date : 2017-05-23 16:29:40
* @version $Id$
*/
namespace Apicp\Controller\Paper;
use Common\Common\AttachOperation;
use Common\Common\DataCenter;
use Common\Service\AnswerDetailExtendService;
use Common\Service\AnswerDetailService;
use Common\Service\AnswerService;
use Common\Service\PaperService;
use Common\Service\PaperTempService;
use Common\Service\RightService;
use Common\Service\SnapshotService;
use Think\Exception;
use VcySDK\Cron;
use VcySDK\Service;
use Common\Common\StudyMap;
class DeleteController extends AbstractController
{
/** @var PaperService */
protected $paper_service;
/** @var RightService */
protected $right_service;
/** @var SnapshotService */
protected $snapshot_service;
/** @var PaperTempService */
protected $paper_temp_service;
/** @var AnswerService */
protected $answer_service;
/** @var AnswerDetailService */
protected $answer_detail_service;
/** @var AnswerDetailExtendService */
protected $answer_detail_extend_service;
public function before_action($action = '')
{
if (!parent::before_action($action)) {
return false;
}
// 实例化试卷表对象
$this->paper_service = new PaperService();
// 实例化权限表对象
$this->right_service = new RightService();
// 实例化试卷快照表对象
$this->snapshot_service = new SnapshotService();
// 实例化试卷临时备选题目储存表对象
$this->paper_temp_service = new PaperTempService();
// 实例化试卷答题表
$this->answer_service = new AnswerService();
// 实例化试卷答题详情表
$this->answer_detail_service = new AnswerDetailService();
// 实例化试卷答题试题扩展详情表
$this->answer_detail_extend_service = new AnswerDetailExtendService();
return true;
}
public function Index_post()
{
$params = I('post.ep_ids');
$ep_ids = array_column($params, 'ep_id');
// 试卷ID不能为空
if (empty($ep_ids) || !is_array($ep_ids)) {
E('_ERR_EP_ID_EMPY');
}
// 被学习路径关联的课程不可删除
$mapUsedIds = StudyMap::checkAppDataUsed($ep_ids);
if (!empty($mapUsedIds)) {
E('_ERR_MAP_USED_CANNOT_DELETE');
}
// 获取试卷列表
$papers_list = $this->paper_service->list_by_conds(['ep_id' => $ep_ids]);
// 遍历验证是否可删除数据
foreach ($papers_list as $key => $v) {
// 如果是常规了考试且是已发布的
if (PaperService::NOMAL_TYPE == $v['exam_type'] && PaperService::PAPER_PUBLISH == $v['exam_status']) {
// 如果有在进行中的
if ($v['begin_time'] < MILLI_TIME && $v['end_time'] >= MILLI_TIME) {
E('_EMPTY_PAPER_DEL_DATA');
}
}
}
$answer_list = $this->answer_service->list_by_conds(['ep_id' => $ep_ids]);
// 获取回答记录中的语音题回答记录
$answer_detail_list = $this->answer_detail_service->list_by_conds(['ep_id' => $ep_ids, 'et_type' => PaperService::TOPIC_TYPE_VOICE, 'my_answer<>?' => '']);
try {
$this->paper_service->start_trans();
// 获取所有试卷
$papers = $papers_list;
// 删除试卷
$this->paper_service->delete($ep_ids);
// 删除试卷权限
$delete_condition = [
'epc_id' => $ep_ids,
'er_type' => PaperService::RIGHT_PAPER
];
$this->right_service->delete_by_conds($delete_condition);
// 删除回答
$this->answer_service->delete_by_conds(['ep_id' => $ep_ids]);
// 删除回答详情
$this->answer_detail_service->delete_by_conds(['ep_id' => $ep_ids]);
// 删除试题扩展详情
$this->answer_detail_extend_service->delete_by_conds(['ep_id' => $ep_ids]);
// 删除试卷快照
$this->snapshot_service->delete_by_conds(['ep_id' => $ep_ids]);
// 删除试卷临时备选题目
$this->paper_temp_service->delete_by_conds(['ep_id' => $ep_ids]);
// 循环删除试卷统计的计划任务
$cron_serv = new Cron(Service::instance());
foreach ($papers as $key => $val) {
if (!empty($val['cron_statistics'])) {
try {
$cron_serv->delete($val['cron_statistics']);
} catch (\VcySDK\Exception $e) {
}
}
}
$this->paper_service->commit();
} catch (Exception $e) {
$this->paper_service->rollback();
E('_ERR_DELETE_TOPIC_FAILED');
return false;
}
// 删除附件操作
$attach_serv = new AttachOperation();
$attach_serv->delete_attach(
APP_DIR,
'paper',
$ep_ids
);
// 循环删除推荐
foreach ($ep_ids as $v) {
$url = rpcUrl('/Public/Rpc/Recommender/ArticleDelete');
$data_send = [
'app' => APP_DIR,
'dataCategoryId' => '',
'dataId' => $v
];
\Com\Rpc::phprpc($url)->invoke('Index', $data_send);
}
/* 数据中心:删除点赞埋点*/
// 查询考试的所有回答记录
$answer_serv = new AnswerService();
$answer_list = $answer_serv->list_by_conds(['ep_id' => $ep_ids, 'answer_status' => AnswerService::READ_OVER],
null, [], 'ea_id');
// 答卷记录id集合
$cids = [];
if (!empty($answer_list)) {
$cids = array_column($answer_list, 'ea_id');
}
if (!empty($cids)) {
$datacenter =& DataCenter::instance();
// 执行删除
$datacenter->delLike($cids);
}
return true;
}
}