PdfZipController.class.php
5.16 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
<?php
/**
* 【后台】批量导出学员成绩单
* PdfZipController.class.php
* @author:heyuelong
* @date:2018年4月23日10:01:06
*/
namespace Apicp\Controller\Export;
use Common\Common\Cache;
use Common\Common\Department;
use Common\Common\ExamHelper;
use Common\Common\ExportDownload;
use Common\Service\AnswerService;
use Common\Service\AnswerDetailService;
use Common\Service\PaperService;
class PdfZipController extends AbstractController
{
/** @var PaperService 实例化试卷对象 */
protected $paper_service;
/** @var AnswerService 实例化答卷表对象 */
protected $answer_service;
/** @var AnswerDetailService 实例化答卷详情表对象 */
protected $answer_detail_service;
/** @var Department */
protected $department;
public function before_action($action = '')
{
if (!parent::before_action($action)) {
return false;
}
$this->paper_service = new PaperService();
$this->answer_service = new AnswerService();
$this->answer_detail_service = new AnswerDetailService();
$this->department = &Department::instance();
return true;
}
public function Index()
{
$params = I('post.');
// 试卷id为空,返回提示""
if (!$params['ep_id']) {
return true;
}
$types = array(
ExamHelper::HAS_JOINED,
ExamHelper::NOT_JOINED
);
// 导出类型不正确
if (!in_array($params['type'], $types)) {
E('_ERR_EXPORT_TYPE');
}
// 获取试卷信息
$paper = $this->paper_service->get($params['ep_id']);
// 试卷不存在
if (empty($paper)) {
E('_ERR_PAPER_NOT_FOUND');
}
// 拼接数组
if (!empty($params['dpIds'])) {
$params['dpIds'] = explode(';', $params['dpIds']);
}
// 拼接数组
if (!empty($params['end_time'])) {
$params['end_time'] = explode(';', $params['end_time']);
}
// 初始化列表数据
$lists = [];
// 【已参与】人员列表(测评试卷)
if (
$params['type'] == ExamHelper::HAS_JOINED &&
$paper['paper_type'] == PaperService::EVALUATION_PAPER_TYPE
) {
// 组装查询条件
$conds = $this->answer_service->get_conditions($paper, $params);
// 【考试完成时间】
if (isset($params['end_time']) && !empty($params['end_time']) && is_array($params['end_time'])) {
$end_time = $params['end_time'];
$end_time1 = $end_time[0];
$end_time2 = $end_time[1];
if ($end_time1 && $end_time2) {
$conds['my_end_time>=?'] = $end_time1;
$conds['my_end_time<=?'] = $end_time2;
}
}
// 最高分记录
$conds['is_score_top'] = PaperService::IS_SCORE_TOP_TRUE;
// 参与这场考试的人员的考试信息
$lists = $this->answer_service->list_by_conds($conds, null, [], 'ea_id');
}
// 【已参与】人员列表(模拟试卷)
if (
$params['type'] == ExamHelper::HAS_JOINED &&
$paper['paper_type'] == PaperService::SIMULATION_PAPER_TYPE
) {
// 组装查询条件
$conds = $this->answer_service->get_conditions($paper, $params);
// 【考试完成时间】
if (isset($params['end_time']) && !empty($params['end_time']) && is_array($params['end_time'])) {
$end_time = $params['end_time'];
$end_time1 = $end_time[0];
$end_time2 = $end_time[1];
if ($end_time1 && $end_time2) {
$conds['my_end_time>=?'] = $end_time1;
$conds['my_end_time<=?'] = $end_time2;
}
}
// 参与考试的人员的考试信息
$lists = $this->answer_service->get_mock_join_list($conds, null, []);
}
// 如果存在数据则生成
if (!empty($lists)) {
$title = $paper['ep_name'] . '_已参与批量导出成绩单';
$params_down = [
'title' => $title,
'ea_id' => $this->_login->user['eaId'],
'username' => $this->_login->user['eaRealname'],
'type' => ExportDownload::ZIP_TYPE
];
// 新增开始生成状态
$id = ExportDownload::set_down_load($params_down);
$ea_ids = array_column($lists, 'ea_id');
$params = [
'user_id' => $this->_login->user['eaId'],
'time' => microtime(true),
'id' => $id,
'title' => $title
];
// 生成缓存
Cache::instance()->set('Common.Exam_Down_Pdf_' . $id, $ea_ids);
$url = oaUrl('Frontend/Callback/DownPdf');
// 生成定时任务
ExportDownload::set_Cron($params, $url, '考试中心成绩单生成PDF批量下载', 'Exam_Down_Pdf_' . $id);
};
return true;
}
}