BaseinfoModel.class.php
3.95 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
<?php
/**
* BaseinfoModel.class.php
* $author$
*/
namespace Common\Model;
use Common\Service\BaseinfoService;
class BaseinfoModel extends AbstractModel
{
// 全部人可见
const IS_ALL = 1;
// 部分人可见
const NOT_ALL = 0;
// 调研发布状态:发布
const PUBLISH_STATUS = 3;
/**
* 构造方法
*/
public function __construct()
{
parent::__construct();
}
/**
* 执行自定义查询SQL语句(安装应用回调时用)
*
* @author 侯英才
*
* @param string $sql 执行的SQL语句
*
* @return mixed
*/
public function query($sql)
{
$res = $this->_m->query($sql);
return $res;
}
/**
* 获取有权限的调研总数
*
* @param int $qu_status 调研状态 1进行中,2已结束
* @param array $ids 有权限的调研ID集合
*
* @return mixed
*/
public function count_by_where($qu_status, $ids)
{
//格式化查询条件
list($where, $params) = $this->get_list_where($qu_status, $ids);
$sql = 'SELECT COUNT(*) FROM __TABLE__' . $where;
return $this->_m->result($sql, $params);
}
/**
* 获取有权限的调研列表
*
* @param int $qu_status 调研状态 1进行中,2已结束
* @param array $ids 有权限的调研ID集合
* @param array $page_option 分页数组
* @param array $order_option 排序添加
*
* @return mixed
*/
public function list_by_where($qu_status, $ids, $page_option, $order_option)
{
// 格式化查询条件
list($where, $params) = $this->get_list_where($qu_status, $ids);
// 排序
$order_by = '';
if (!$this->_order_by($order_by, $order_option)) {
return false;
}
// 分页参数
$limit = '';
if (!$this->_limit($limit, $page_option)) {
return false;
}
$sql = 'SELECT * FROM __TABLE__' . $where . $order_by . $limit;
return $this->_m->fetch_array($sql, $params);
}
/**
* 调研sql查询条件
*
* @param $qu_status
* @param $ids
*
* @return array
*/
private function get_list_where($qu_status, $ids)
{
// sql查询条件
$where = ' WHERE `qu_type`=? AND `status`<? AND `domain`=? AND `release_status`=? ';
$params = [
BaseinfoService::ROUTINE_TYPE, // 常规类型
self::ST_DELETE,
QY_DOMAIN,
self::PUBLISH_STATUS // 调研发布状态:发布
];
// 进行中
if (BaseinfoService::FRONTEND_QU_STATUS_ING == $qu_status) {
$where .= ' AND `deadline` >=?';
} elseif (BaseinfoService::FRONTEND_QU_STATUS_END == $qu_status) { // 已结束
$where .= ' AND `deadline` <?';
}
$params[] = MILLI_TIME;
// 如果传入的调研id集合为空
if (empty($ids)) {
$where .= ' AND `is_all`=?';
} else {
$id_arr = implode(',', $ids);
$where .= ' AND (`is_all`=? OR `qu_id` IN (' . $id_arr . '))';
}
$params[] = self::IS_ALL;
return [$where, $params];
}
/**
* 执行sql语句
*
* @param $sql
*
* @return false|int
*/
public function execute($sql)
{
$res = $this->_m->execute($sql);
return $res;
}
/**
* 查询分类id及对应的调研总数
*
* @return mixed
*/
public function classify_baseinfo_count()
{
// 查询条件
$where['status'] = ['lt', self::ST_DELETE];
$where['domain'] = QY_DOMAIN;
return $this->_m->field('qc_id,COUNT(qc_id) AS count')->where($where)->group('qc_id')->select();
}
}