SubmitAllController.class.php
6.19 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
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
<?php
/**
* 【考试】考试手动交卷接口
* SubmitController.class.php
* @author: wanghuan
* @date: 2017-08-10
*/
namespace Api\Controller\Answer;
use Common\Common\Train;
use Common\Service\AnswerService;
use Common\Service\PaperService;
use Common\Common\TaskCenter;
class SubmitAllController extends AbstractController
{
public function Index_post()
{
// 接收post参数
$params = I('post.');
// 答卷id
$ea_id = intval($params['ea_id']);
$map_id = intval($params['map_id']);
$path_id = intval($params['path_id']);
// 答卷id为空,返回提示"答卷ID不能为空"
if (!$ea_id) {
E('_EMPTY_EA_ID');
}
// 答题列表
$qa_list = $params['qa_list'];
if (empty($qa_list)) {
E('_EMPTY_ANSWER_LIST');
}
// 常规考试
$data_type = PaperService::NOMAL_TYPE;
$obj_id = 0;
// 任务id
$customtask_id = I('post.customtask_id', 0, 'intval');
// 任务id不为空
if (!empty($customtask_id)) {
// 任务类
$data_type = PaperService::TASK_TYPE;
$obj_id = $customtask_id;
}
// 培训计划id
$plan_id = I('post.plan_id', 0, 'intval');
// 培训计划id不为空
if (!empty($plan_id)) {
// 线下培训
$data_type = PaperService::TRAIN_TYPE;
$obj_id = $plan_id;
}
if(empty($this->uid)){
// 用户uid不存在
E('_EMPTY_UID');
}
// 实例化答卷service
$answer_s = new AnswerService();
$answer_conds = [
'ea_id' => $ea_id,
'uid' => $this->uid
];
$answer_info = $answer_s->get_by_conds($answer_conds);
if(empty($answer_info)){
// 回答数据不存在
E('_ERR_ANSWER_NOT_FOUND');
}
// 交卷
$params = [
'ea_id' => $ea_id,
'uid' => $this->uid,
'qa_list' => $qa_list,
'data_type' => $data_type,
'obj_id' => $obj_id,
'map_id' => $map_id ? $map_id : '',
'path_id' => $path_id ? $path_id : '',
'user_info' => $this->_login->user
];
$result = $answer_s->submit_all($params, $award,$answer_info);
// 交卷失败
if (!$result) {
return false;
}
if (AnswerService::IS_MAKEUP == $answer_info['is_makeup']) {
// 如果是补考,返回结果
$this->_result = [
'list' => [],
'score_list' => []
];
return true;
}
// 格式化返回的积分策略数据
$integral = [];
if (!empty($result['score_list'])) {
foreach ($result['score_list'] as $v) {
// 执行成功
if ($v['result'] == 'SUCCESS') {
$integral[] = [
'content' => '积分',
'number' => intval($v['score'])
];
}
}
}
// 实例化试卷service
$paper_s = new PaperService();
// 试卷详情
$ep_id = $answer_info['ep_id'];
$paper_info = $paper_s->get($ep_id);
// 常规任务埋点:考试通过(模拟试卷考试通过才算完成,测评试卷只要参加考试并交卷就算完成)
if (PaperService::TASK_TYPE == $paper_info['exam_type'] && $customtask_id) {
$params = [
'uid' => $this->uid,
'customtask_id' => $customtask_id,
'app_data_id' => $ep_id,
'action_key' => 'exam_pass',
];
// 模拟试卷
if (PaperService::SIMULATION_PAPER_TYPE == $paper_info['paper_type'] && AnswerService::PASS == $answer_info['my_is_pass']) {
$params['description'] = '考试通过';
$taskCenter = &TaskCenter::instance();
$taskCenter->triggerCustomtask($params);
}
// 测评试卷
if (PaperService::EVALUATION_PAPER_TYPE == $paper_info['paper_type']) {
$params['description'] = '考试完成';
$taskCenter = &TaskCenter::instance();
$taskCenter->triggerCustomtask($params);
}
}
// 更新成功,类型为线下培训,培训id不为空
if ($plan_id && PaperService::TRAIN_TYPE == $paper_info['exam_type']) {
// 同步线下培训考试完成状态
$Train = &Train::instance();
$Train->syncTrainStatus($plan_id, $ep_id);
}
// 试卷使用类型(0:测评试卷,1:模拟试卷)
$paper_type = $paper_info['paper_type'];
// 是否更新参与人数(0=不更新,1=更新)
$is_update_join = 0;
// 测评试卷
if (PaperService::EVALUATION_PAPER_TYPE == $paper_type) {
// 更新
$is_update_join = 1;
} elseif (PaperService::SIMULATION_PAPER_TYPE == $paper_type) { // 模拟试卷
// 交卷次数
$condition = [
'ep_id' => $ep_id,
'uid' => $this->uid,
'answer_status' => PaperService::READ_OVER, // 已批阅
'data_type' => PaperService::NOMAL_TYPE, // 常规考试
];
$answer_count = $answer_s->count_by_conds($condition);
// 模拟试卷第一次交卷
if (1 == $answer_count) {
// 更新
$is_update_join = 1;
}
}
// 交卷成功,更新参与人数
if ($is_update_join) {
// 已参与人数加1,未参与人数减1
$update_data = [
'join_count' => $paper_info['join_count'] + 1,
'unjoin_count' => $paper_info['unjoin_count'] - 1
];
$paper_s->update($ep_id, $update_data);
}
// 返回结果
$this->_result = [
'list' => isset($award) ? $award : [],
'score_list' => isset($integral) ? $integral : []
];
return true;
}
}