PdfController.class.php
3.5 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
<?php
/**
* 【后台】导出单个学员成绩单
* PdfController.class.php
* @author:daijun
* @date:2018-04-09
*/
namespace Apicp\Controller\Export;
use Common\Common\ExamHelper;
use Common\Common\ExportDownload;
use Common\Common\User;
use Common\Service\AnswerService;
use Common\Service\AnswerDetailService;
use Common\Service\PaperService;
class PdfController extends AbstractController
{
/** @var PaperService 实例化试卷对象 */
protected $paper_service;
/** @var AnswerService 实例化答卷表对象 */
protected $answer_service;
/** @var AnswerDetailService 实例化答卷详情表对象 */
protected $answer_detail_service;
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();
return true;
}
public function Index()
{
$params = I('post.');
$ea_id = rintval($params['ea_id']);
// 答卷ID不能为空
if (empty($ea_id)) {
E('_EMPTY_EA_ID');
}
// 获取答卷信息
$answer = $this->answer_service->get($ea_id);
// 答卷不存在
if (empty($answer)) {
E('_ERR_ANSWER_NOT_FOUND');
}
// 根据UID获取用户信息
$user_service = &User::instance();
// 获取答卷用户信息
$user = $user_service->getByUid($answer['uid']);
// 获取阅卷人信息
if (empty($answer['marking_name'])) {
$marking_user = $user_service->getByUid($answer['marking_uid']);
$answer['marking_name'] = $marking_user['memUsername'];
}
// 获取答卷详情
$answer_detail = $this->answer_detail_service->list_by_conds(['ea_id' => $answer['ea_id']]);
// 获取试卷信息
$paper = $this->paper_service->get($answer['ep_id']);
// 格式化答卷详情
$answer_list = $this->answer_detail_service->question_list_format(
$answer_detail,
$paper['marking_type'],
AnswerService::ANSWER_PC_ANALYSIS
);
// 组装返回数据
$data = array(
'ep_name' => $paper['ep_name'],
'my_score' => $answer['my_score'],
'username' => $user['memUsername'],
'marking_name' => $answer['marking_name'] ? $answer['marking_name'] : '系统阅卷',
'answer_status' => intval($answer['answer_status']),
'marking_time' => $answer['marking_time'],
'marking_type' => intval($paper['marking_type']),
'list' => $answer_list
);
// 成绩单名称
$title = $paper['ep_name'] . '_' . $user['memUsername'] . '_成绩单';
$params_down = [
'title' => $title,
'ea_id' => $this->_login->user['eaId'],
'username' => $this->_login->user['eaRealname'],
'type' => ExportDownload::PDF_TYPE
];
// 新增开始生成状态
$id = ExportDownload::set_down_load($params_down);
// 生成PDF
$url = ExamHelper::instance()->create_pdf($title, $data, $this->_login->user['eaId'] . microtime(true));
// 更新状态
$update_data = [
'url' => $url,
'id' => $id
];
ExportDownload::update_down_load($update_data);
return true;
}
}