<?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, []); } }