AnswerModel.class.php
7.64 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
294
295
296
297
298
299
300
301
<?php
/**
* 试卷-答卷表
* @author: houyingcai
* @email: 594609175@qq.com
* @date : 2017-05-19 18:04:10
* @version $Id$
*/
namespace Common\Model;
class AnswerModel extends AbstractModel
{
// 批阅状态:待批阅
const ANSWER_STATUS_NO = 1;
// 批阅状态:批阅中
const ANSWER_STATUS_ING = 2;
// 批阅状态:已批阅
const ANSWER_STATUS_OK = 3;
/**
* 构造方法
*/
public function __construct()
{
parent::__construct();
}
/**
* 查询一条数据
*
* @autor 蔡建华
* @param array $conds 查询条件
* @param string $fields 返还字段
*
* @return array|bool
*/
public function fetchOne($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);
return $this->_m->result($sql, $params);
}
/**
* 获取考试参与人员列表
*
* @author houyingcai
* @param array $conds 查询条件参数列表
* @param array $page_option 分页参数
* @param array $order_option 排序参数
* @param string $fields 返回字段
*
* @return array|bool
*/
public function get_mock_answer_list($conds, $page_option = null, $order_option = [], $fields = '*')
{
$params = [];
// 条件
$wheres = [];
if (!$this->_parse_where($wheres, $params, $conds)) {
return false;
}
// 企业标记
$wheres[] = '`domain`=?';
$params[] = QY_DOMAIN;
// 状态条件
$wheres[] = '`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 {$fields},COUNT(uid) AS join_count,MAX(my_score) AS my_max_score FROM (SELECT {$fields} FROM __TABLE__ WHERE " . implode(' AND ',
$wheres) . " ORDER BY my_score DESC,my_time ASC ) AS a GROUP BY a.uid {$orderby} {$limit}";
return $this->_m->fetch_array($sql, $params);
}
/**
* 统计考试参与人员总数
*
* @author houyingcai
* @param array $conds 查询条件参数列表
*
* @return array|bool
*/
public function count_mock_answer($conds)
{
$params = [];
// 条件
$wheres = [];
if (!$this->_parse_where($wheres, $params, $conds)) {
return false;
}
// 企业标记
$wheres[] = '`domain`=?';
$params[] = QY_DOMAIN;
// 状态条件
$wheres[] = '`status`<?';
$params[] = $this->get_st_delete();
$sql = 'select count(*) from (select * from __TABLE__ WHERE ' . implode(' AND ',
$wheres) . ' GROUP BY uid) __TABLE__';
return $this->_m->result($sql, $params);
}
/**
* 根据条件读取数据
*
* @author houyingcai
* @param array $conds 查询条件数组
* @param array $order_option 排序数组
* @param String $fields 查询字段
*
* @return array|bool
*/
public function get_by_conds($conds, $order_option = [], $fields = '*')
{
$params = [];
// 条件
$wheres = [];
if (!$this->_parse_where($wheres, $params, $conds)) {
return false;
}
// 排序
$orderby = '';
if (!$this->_order_by($orderby, $order_option)) {
return false;
}
// 企业标记
$wheres[] = "`{$this->prefield}domain`=?";
$params[] = QY_DOMAIN;
// 状态条件
$wheres[] = "`{$this->prefield}status`<?";
$params[] = $this->get_st_delete();
// 执行 SQL
return $this->_m->fetch_row("SELECT {$fields} FROM __TABLE__ WHERE " . implode(' AND ',
$wheres) . "{$orderby} LIMIT 1",
$params);
}
/**
* 执行自定义查询SQL语句(安装应用回调时用)
*
* @author 侯英才
* @param string $sql 执行的SQL语句
*
* @return mixed
*/
public function query($sql)
{
$res = $this->_m->query($sql);
return $res;
}
/**
* 执行自定义非查询SQL语句(安装应用回调时用)
*
* @author 侯英才
* @param string $sql 执行的SQL语句
*
* @return mixed
*/
public function execute($sql)
{
$res = $this->_m->execute($sql);
return $res;
}
/**
* 通过试卷IDS查询对应试卷已参与人员统计列表
*
* @author 何岳龙
* @param array $ep_ids 试卷IDS
*
* @return array
*/
public function list_by_total($ep_ids = [])
{
// sql 语句
$sql = "SELECT count(distinct (uid)) AS total,ep_id FROM __TABLE__";
// 试卷IDS
$wheres[] = '`ep_id` IN(?)';
$params[] = $ep_ids;
// 我的用时
$wheres[] = '`my_time` > ?';
$params[] = 0;
// 企业标记
$wheres[] = '`domain`=?';
$params[] = QY_DOMAIN;
// 状态条件
$wheres[] = '`status`<?';
$params[] = $this->get_st_delete();
return $this->_m->fetch_array($sql . ' WHERE ' . implode(' AND ', $wheres) . ' group BY ep_id', $params);
}
/**
* 获取批阅列表
*
* @param array $conds 查询条件
* @param array $page_option 分页
* @param array $order_option 排序
*
* @return array|bool
*/
public function list_marking_paper($conds, $page_option = [], $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;
}
$sql = "SELECT ep_id,count(ea_id) as total FROM __TABLE__ WHERE " . implode(' AND ', $wheres) . " GROUP BY ep_id {$limit} ";
return $this->_m->fetch_array($sql, $params);
}
/**
* 统计批阅列表总数
*
* @param array $conds 查询条件
*
* @return array|bool
*/
public function count_marking_paper($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 COUNT(*) FROM (SELECT * FROM __TABLE__ WHERE " . implode(' AND ', $wheres) . " GROUP BY ep_id ) __TABLE__";
return $this->_m->result($sql, $params);
}
}