MemberMedalModel.class.php
2.57 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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
<?php
/**
* MemberMedalModel.class.php
* 用户勋章表 Model
*/
namespace Common\Model;
class MemberMedalModel extends AbstractModel
{
// 构造方法
public function __construct()
{
parent::__construct();
}
/**
* 增加人员获得勋章数
* @param $imId
* @param $uid
* @return array|bool
*/
public function addMedalTotal($imId, $uid)
{
if (empty($imId) || empty($uid)) {
return false;
}
$sql = "UPDATE `oa_integral_member_medal`
SET `im_total` = `im_total` + 1
WHERE
`im_id` = {$imId} AND
`mem_uid` = '{$uid}' AND
`domain` = ? AND
`status` < ?";
return $this->_m->execsql($sql, [QY_DOMAIN, $this->get_st_delete()]);
}
/**
* 根据用户IDS 获取用户获得勋章总数
* @param $uids
* @return array|bool
*/
public function getMemMedalTotal($uids)
{
if (empty($uids)) {
return false;
}
$sql = "SELECT count(*) as medal_total, mem_uid FROM oa_integral_member_medal
WHERE
mem_uid IN (?)
AND `domain` = ?
AND `status` < ?
GROUP BY mem_uid";
return $this->_m->fetch_array($sql, [
$uids,
QY_DOMAIN,
$this->get_st_delete()
]);
}
/**
* 取获得勋章的用户
* @author tangxingguo
* @param $conds
* @return array
*/
public function getUids($conds)
{
$data = $this->buildSql($conds);
$sql = "SELECT `mem_uid` FROM __TABLE__ WHERE {$data['where']} GROUP BY `mem_uid`";
return $this->_m->fetch_array($sql, $data['params']);
}
/**
* 处理条件语句及其值
* @author tangxingguo
* @param array $conds 条件
* @return array
*/
public function buildSql($conds)
{
// 条件
$where = '`domain` = ? AND `status` < ?';
// 条件的值
$params = [
QY_DOMAIN,
$this->get_st_delete(),
];
// 组合搜索条件及值
if (isset($conds['mem_uid'])) {
$mem_uids = implode("','", $conds['mem_uid']);
$where .= " AND `mem_uid` in ('{$mem_uids}')";
}
if (isset($conds['mem_username'])) {
$where .= " AND `mem_username` LIKE '%{$conds['mem_username']}%'";
}
return [
'where' => $where,
'params' => $params,
];
}
}