ExamAnswerModel.class.php
8.24 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
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
<?php
/**
* Created by PhpStorm.
* User: yingcai
* Date: 2017/10/10
* Time: 下午4:00
*/
namespace Common\Model;
class ExamAnswerModel extends \Com\Model
{
const EXAM_PAPER = 1;
// 构造方法
public function __construct()
{
parent::__construct('Answer', 'oa_exam_');
}
/**
* 统计周期内考试人数
*
* @author houyingcai
*
* @param array $conds 查询条件
* @param array $order_option 排序参数
* @param string $fields 返回字段
*
* @return array|bool
*/
public function count_join_users($conds = [], $order_option = [], $fields = '*')
{
$where = ' status < ? AND domain = ? ';
$params[] = $this->get_st_delete();
$params[] = QY_DOMAIN;
if ($conds['start_time'] && $conds['end_time']) {
$where .= ' AND created >= ? AND created <= ?';
$params[] = $conds['start_time'];
$params[] = $conds['end_time'];
} else {
return false;
}
if (!empty($conds['ep_id'])) {
$where .= ' AND ep_id in (?)';
$params[] = $conds['ep_id'];
}
$where .= ' AND my_end_time > 0 AND data_type = ' . self::EXAM_PAPER;
// 排序
$orderby = '';
if (!$this->_order_by($orderby, $order_option)) {
return false;
}
$sql = "SELECT COUNT(*) FROM (SELECT {$fields} FROM __TABLE__ WHERE {$where}{$orderby} GROUP BY `uid`) __TABLE__";
return $this->_m->result($sql, $params);
}
/**
* 获取学霸排行列表
*
* @param array $conds 条件数组
* @param int|array $page_option 分页参数
* @param array $order_option 排序
* @param string $fields 读取字段
*
* @return array|bool
*/
public function super_scholar_rank($conds, $page_option = null, $order_option = [], $fields = '*')
{
$params = [];
// 条件
$wheres = [];
if (!$this->_parse_where($wheres, $params, $conds)) {
return false;
}
// 企业标记
$wheres[] = "`{$this->prefield}domain`=?";
$params[] = QY_DOMAIN;
// 状态条件
$wheres[] = "`{$this->prefield}status`<?";
$params[] = $this->get_st_delete();
// 排序
$orderby = '';
if (!$this->_order_by($orderby, $order_option)) {
return false;
}
// 分页参数
$limit = '';
if (!$this->_limit($limit, $page_option)) {
return false;
}
// 读取记录
return $this->_m->fetch_array("SELECT {$fields} FROM __TABLE__ WHERE " . implode(' AND ',
$wheres) . " GROUP BY uid {$orderby}{$limit}", $params);
}
/**
* 根据条件获取用户答卷记录
*
* @param array $conds 查询条件
* @param string $fields 查询字段
*
* @return array|bool
*/
public function list_answer($conds = [], $fields = '*')
{
$params = [];
// 条件
$wheres = [];
if (!$this->_parse_where($wheres, $params, $conds)) {
return false;
}
// 企业标记
$wheres[] = "`{$this->prefield}domain`=?";
$params[] = QY_DOMAIN;
// 状态条件
$wheres[] = "`{$this->prefield}status`<?";
$params[] = $this->get_st_delete();
$sql = "SELECT {$fields} FROM __TABLE__ WHERE " . implode(' AND ', $wheres) . " GROUP BY ep_id,uid ";
// 读取记录
return $this->_m->fetch_array($sql, $params);
}
/**
* 根据UID统计用户考试次数
*
* @param string $uid 员工UID
*
* @return array|bool
*/
public function count_user_data_exam($uid)
{
$conds = [
'l.`uid`' => $uid,
'l.`my_end_time` > ?' => 0,
];
$params = [];
// 条件
$wheres = [];
if (!$this->_parse_where($wheres, $params, $conds)) {
return false;
}
// 企业标记
$wheres[] = "r.`{$this->prefield}domain`=?";
$params[] = QY_DOMAIN;
// 状态条件
$wheres[] = "r.`{$this->prefield}status`<?";
$params[] = $this->get_st_delete();
$sql = 'SELECT l.* FROM __TABLE__ l RIGHT JOIN `oa_exam_paper` r ON l.ep_id = r.ep_id WHERE ' . implode(' AND ',
$wheres) . ' AND r.exam_type = ' . self::EXAM_PAPER . ' GROUP BY l.ep_id';
return count($this->_m->fetch_array($sql, $params));
}
/**
* 根据UID获取员工考试记录
*
* @param string $uid 员工UID
* @param array $page_option 分页
* @param array $order_option 排序
*
* @return array|bool
*/
public function list_user_data_exam($uid, $page_option = null, $order_option = [])
{
$conds = [
'l.`uid`' => $uid,
'l.`my_end_time` > ?' => 0,
];
$params = [];
// 条件
$wheres = [];
if (!$this->_parse_where($wheres, $params, $conds)) {
return false;
}
// 企业标记
$wheres[] = "r.`{$this->prefield}domain`=?";
$params[] = QY_DOMAIN;
// 状态条件
$wheres[] = "r.`{$this->prefield}status`<?";
$params[] = $this->get_st_delete();
// 排序
$orderby = '';
if (!$this->_order_by($orderby, $order_option)) {
return false;
}
// 分页参数
$limit = '';
if (!$this->_limit($limit, $page_option)) {
return false;
}
$sql = "SELECT a.ea_id,a.ep_id,a.my_score,a.my_begin_time,a.my_end_time,a.my_time,b.total
FROM __TABLE__ a,
(
SELECT l.uid,l.ep_id,max(l.my_score) my_score,count(l.ep_id) as total
FROM __TABLE__ l RIGHT JOIN `oa_exam_paper` r ON l.ep_id = r.ep_id
WHERE " . implode(' AND ', $wheres) . " AND r.exam_type = " . self::EXAM_PAPER . " GROUP BY l.ep_id {$orderby}{$limit}
) b
WHERE a.ep_id = b.ep_id AND a.my_score = b.my_score AND a.uid = b.uid
GROUP BY a.ep_id ORDER BY a.ea_id DESC";
return $this->_m->fetch_array($sql, $params);
}
/**
* 员工考试统计列表总数
*
* @param array $conds 查询条件
*
* @return array|bool
*/
public function count_user_exam_count($conds)
{
$params = [];
// 条件
$wheres = [];
if (!$this->_parse_where($wheres, $params, $conds)) {
return false;
}
// 企业标记
$wheres[] = "`{$this->prefield}domain`=?";
$params[] = QY_DOMAIN;
// 状态条件
$wheres[] = "`{$this->prefield}status`<?";
$params[] = $this->get_st_delete();
$sql = "SELECT uid,ep_id FROM __TABLE__ WHERE " . implode(' AND ', $wheres) . " GROUP BY ep_id,uid";
return $this->_m->fetch_array($sql, $params);
}
/**
* 获取员工考试统计列表
*
* @param array $conds 查询条件
* @param array $page_option 分页
* @param array $order_option 排序
*
* @return array|bool
*/
public function list_user_exam_count($conds, $page_option = null, $order_option = [])
{
$params = [];
// 条件
$wheres = [];
if (!$this->_parse_where($wheres, $params, $conds)) {
return false;
}
// 企业标记
$wheres[] = "`{$this->prefield}domain`=?";
$params[] = QY_DOMAIN;
// 状态条件
$wheres[] = "`{$this->prefield}status`<?";
$params[] = $this->get_st_delete();
// 排序
$orderby = '';
if (!$this->_order_by($orderby, $order_option)) {
return false;
}
// 分页参数
$limit = '';
if (!$this->_limit($limit, $page_option)) {
return false;
}
// 根据试卷ID和用户ID进行分组
$sql = "SELECT ea_id,uid,ep_id,MAX(my_score) my_score,my_is_pass,my_time,my_begin_time,my_end_time FROM (SELECT * FROM __TABLE__ WHERE " . implode(' AND ', $wheres) . " AND answer_status>0 ORDER BY my_score DESC) AS b GROUP BY ep_id,uid {$orderby}{$limit}";
return $this->_m->fetch_array($sql, $params);
}
}