ExamModel.class.php
2 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
<?php
/**
* Created by PhpStorm.
* User: zhonglei
* Date: 2017/6/5
* Time: 14:33
*/
namespace Common\Model;
class ExamModel extends AbstractModel
{
// 构造方法
public function __construct()
{
parent::__construct();
}
/**
* 处理条件语句及其值
* @author liyifei
* @param array $conds 条件
* @return array
*/
public function buildSql($conds)
{
// 条件
$where = '`domain` = ? AND `status` < ?';
// 条件的值
$params = [
QY_DOMAIN,
$this->get_st_delete(),
];
// 组合搜索条件及值
if (isset($conds['article_id'])) {
$where .= ' AND `article_id` = ?';
$params[] = $conds['article_id'];
}
if (isset($conds['article_chapter_id'])) {
$where .= ' AND `article_chapter_id` = ?';
$params[] = $conds['article_chapter_id'];
}
if (isset($conds['source_id'])) {
$where .= ' AND `source_id` = ?';
$params[] = $conds['source_id'];
}
return [
'where' => $where,
'params' => $params,
];
}
/**
* 获取参与测评的不重复的UID列表
* @param array $conds 条件
* @param array $pages 分页
* @return array
*/
public function listUidByConds($conds, $pages)
{
$data = $this->buildSql($conds);
$sql = "SELECT DISTINCT `uid` FROM __TABLE__ WHERE {$data['where']}";
return $this->_m->fetch_array($sql, $data['params'], $pages);
}
/**
* 根据条件,获取测评人员总数
* @author liyifei
* @param array $conds 条件
* @return array
*/
public function countUidByConds($conds)
{
$data = $this->buildSql($conds);
$sql = "SELECT COUNT(DISTINCT `uid`) AS total FROM __TABLE__ WHERE {$data['where']}";
$count = $this->_m->result($sql, $data['params']);
return intval($count);
}
}