RandomSnapshotModel.class.php
3.16 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
<?php
/**
* 随机题库表
* @author: 蔡建华
* @email: 594609175@qq.com
* @date : 2017-07-14 18:06:08
* @version $Id$
*/
namespace Common\Model;
class RandomSnapshotModel extends AbstractModel
{
/**
* 构造方法
*/
public function __construct()
{
parent::__construct();
}
/**
* 获取随机快照列表
*
* @author caijanhua
* @param array $conds 查询条件参数列表
* @param array $page_option 分页参数
* @param array $order_option 排序参数
* @param string $fields 返回字段
*
* @return array|bool
*/
public function conds_random_snapshot_list($conds, $page_option = null, $order_option = [], $fields = '*')
{
$params = [];
// 条件
$wheres = [];
if (!$this->_parse_where($wheres, $params, $conds)) {
return false;
}
$snapModel = new StatisticsModel();
$table = $snapModel->get_tname();
// 企业标记
$wheres[] = 'a.`domain`=?';
$params[] = QY_DOMAIN;
// 状态条件
$wheres[] = 'a.`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, CASE WHEN b.answer_total>0 THEN b.right_num/b.answer_total ELSE 'false' END as probability,CASE WHEN a.et_type=" . self::TOPIC_TYPE_VOICE . " or a.et_type=" . self::TOPIC_TYPE_QUESTION . " THEN 1 ELSE 0 END as ea_sort,
CASE when a.et_type=" . self::TOPIC_TYPE_SINGLE . " THEN 0
when a.et_type=" . self::TOPIC_TYPE_MULTIPLE . " THEN 1
when a.et_type=" . self::TOPIC_TYPE_JUDGMENT . " THEN 2
when a.et_type=" . self::TOPIC_TYPE_QUESTION . " THEN 3
when a.et_type=" . self::TOPIC_TYPE_VOICE . " THEN 4
END as order_defualt
FROM __TABLE__ a LEFT JOIN $table b ON a.er_id=b.esr_id AND a.ep_id=b.ep_id WHERE " . implode(' AND ',
$wheres) . " group by esr_id {$orderby} {$limit}";
return $this->_m->fetch_array($sql, $params);
}
/**
* 获取随机快照总数
*
* @author caijainhua
* @param array $conds 查询条件参数列表
*
* @return int
*/
public function conds_random_snapshot_count($conds)
{
$params = [];
// 条件
$wheres = [];
if (!$this->_parse_where($wheres, $params, $conds)) {
return false;
}
$snapModel = new StatisticsModel();
$table = $snapModel->get_tname();
// 企业标记
$wheres[] = 'a.`domain`=?';
$params[] = QY_DOMAIN;
// 状态条件
$wheres[] = 'a.`status`<?';
$params[] = $this->get_st_delete();
$sql = "SELECT count(er_id) as total FROM __TABLE__ a LEFT JOIN $table b ON a.er_id=b.esr_id AND a.ep_id=b.ep_id WHERE " . implode(' AND ',
$wheres) . ' group by esr_id';
return $this->_m->result($sql, $params);
}
}