<?php /** * Created by PhpStorm. * User: liyifei2012it * Date: 18/4/25 * Time: 15:30 */ namespace Common\Model; use Common\Common\Constant; class UserMapModel extends AbstractModel { /** * 构造方法 */ public function __construct() { parent::__construct(); } /** * 根据地图ID,获取完成地图的人数 * @author tangxingguo * @param array $mapIds 地图ID * @return array */ public function getCompleteTotal($mapIds) { $data = $this->formatSql(['map_id' => $mapIds]); $sql = "SELECT COUNT(*) AS total, `map_id` FROM __TABLE__ WHERE {$data['where']} GROUP BY `map_id`"; return $this->_m->fetch_array($sql, $data['params']); } /** * 格式化sql * @author tangxingguo * @param array $conds 条件 * @return array */ public function formatSql($conds) { // 条件 $where = '`domain` = ? AND `status` < ? AND `complete_status` = ?'; // 条件的值 $params = [ QY_DOMAIN, $this->get_st_delete(), Constant::COMPLETE_STATUS_IS_TRUE ]; // 组合搜索条件及值 if (isset($conds['map_id'])) { $mapIds = implode("','", $conds['map_id']); $where .= " AND `map_id` in ('{$mapIds}')"; } return [ 'where' => $where, 'params' => $params, ]; } }