RecordModel.class.php
1.69 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
<?php
/**
* Created by PhpStorm.
* User: yingcai
* Date: 2018/3/23
* Time: 下午3:58
*/
namespace Common\Model;
class RecordModel extends AbstractModel
{
/**
* 构造方法
*/
public function __construct()
{
parent::__construct();
}
/**
* 查询总数
* @param array $params 条件sql,不包含where关键字
* @return int|mixed
*/
public function count_by_where($params = [])
{
// 组装查询语句
$where = ' status<' . self::ST_DELETE . " AND domain= '" . QY_DOMAIN . "'";
$where .= ' AND ac_id=' . $params['ac_id'];
$sql = 'SELECT COUNT(*) FROM (SELECT * FROM __TABLE__ WHERE ' . $where . ' GROUP BY uid) as tb_record';
return $this->_m->result($sql, []);
}
/**
* 查询列表
* @param array $params 条件sql,不包含where关键字
* @param null $page_option 分页参数
* @param string $fields 查询的字段
* @return array|bool
*/
public function list_by_where($params = [], $page_option = null, $fields = '*')
{
// 组装查询语句
$where = ' status<' . self::ST_DELETE . " AND domain= '" . QY_DOMAIN . "'";
$where .= ' AND ac_id=' . $params['ac_id'];
// 分页参数
$limit = '';
if (!$this->_limit($limit, $page_option)) {
return false;
}
$sql = "SELECT {$fields} FROM __TABLE__ WHERE lr_id IN(SELECT SUBSTRING_INDEX(group_concat(lr_id ORDER BY `lr_id` DESC),',',1) FROM __TABLE__ WHERE " . $where . " GROUP BY uid ) AND " . $where . " ORDER BY `lr_id` DESC {$limit}";
// 读取记录
return $this->_m->fetch_array($sql, []);
}
}