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