UserMapModel.class.php
1.43 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
<?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,
];
}
}