InviteUserModel.class.php
5.51 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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
<?php
/**
* Created by PhpStorm.
* User: Slok
* Date: 16/9/29
* Time: 20:44
*/
namespace Common\Model;
class InviteUserModel extends AbstractModel
{
// 用户信息(手机号|邮箱|微信号)已存在
const MEM_INFO_EXIST = 1;
// 审批状态: 待审批
const CHECK_STATUS_WAIT = 1;
// 审批状态: 通过审批
const CHECK_STATUS_PASS = 2;
// 审批状态: 驳回审批
const CHECK_STATUS_REJECT = 3;
// 邀请审批人类型 员工审批
const CHECK_TYPE_USER = 1;
// 邀请审批人类型 后台管理员审批
const CHECK_TYPE_ADMIN = 2;
// 用户加入方式: 管理员添加
const ADMIN_ADD_JOIN = 1;
// 用户加入方式: 邀请加入
const USER_INVITE_JOIN = 2;
// 邀请类型 直接邀请
const INVITE_TYPE_DIRECT = 1;
// 邀请类型 审批邀请
const INVITE_TYPE_APPROVAL = 2;
// 构造方法
public function __construct()
{
parent::__construct();
}
/**
* 根据帐户数据(手机号、微信号、邮箱)获取邀请数据
* @author zhonglei
* @param array $data
* @param bool $ignoreRefuse 忽略拒绝信息
* @return array
*/
public function getByAccount($data, $ignoreRefuse = false)
{
$conds = [];
foreach ($data as $k => $v) {
$conds[] = "`{$k}` = '{$v}'";
}
$refuseWhere = '';
if ($ignoreRefuse) {
$refuseWhere = " AND `check_status` in (1, 2)";
}
$where = implode(' or ', $conds);
$sql = "SELECT * FROM __TABLE__ WHERE ({$where}){$refuseWhere} AND `domain` = ? AND status < ? order by invite_id desc";
$param = [
QY_DOMAIN,
self::ST_DELETE,
];
return $this->_m->fetch_row($sql, $param);
}
/**
* 根据条件读取数据数组
*
* @param array $condition 条件数组
* @param int|array $page_option 分页参数
* @param array $order_option 排序
* @param string $fields 读取字段
*
* @return array|bool
*/
public function listByRight($condition, $page_option = null, $order_option = array(), $fields = '*')
{
$params = array();
// 条件
$wheres = array();
if (!$this->_parse_where($wheres, $params, $condition)) {
return false;
}
// 企业标记
$wheres[] = "`u`.`{$this->prefield}domain`=?";
$params[] = QY_DOMAIN;
// 状态条件
$wheres[] = "`u`.`{$this->prefield}status`<?";
$params[] = $this->get_st_delete();
// 排序
$orderby = '';
if (!$this->_order_by($orderby, $order_option)) {
return false;
}
// 分页参数
$limit = '';
if (!$this->_limit($limit, $page_option)) {
return false;
}
// 读取记录
$list = $this->_m->fetch_array("SELECT {$fields} FROM {$this->_tb_rightTable} AS r
LEFT JOIN __TABLE__ AS u ON r.invite_id=u.invite_id
WHERE " . implode(' AND ', $wheres) . "{$orderby}{$limit}", $params);
$count = $this->_m->fetch_array("SELECT COUNT(*) FROM {$this->_tb_rightTable} AS r
LEFT JOIN __TABLE__ AS u ON r.invite_id=u.invite_id
WHERE " . implode(' AND ', $wheres) . "{$orderby}{$limit}", $params);
return array($list, $count);
}
/**
* 根据条件删除邀请记录
* @param $condition
* @return bool
*/
public function delInviteUserRecord($condition) {
if (empty($condition['mobile'])) {
return false;
}
$whereOr = ['mobile in (' . $condition['mobile'] . ')'];
if (!empty($condition['email'])) {
$whereOr[] = 'email in (' . $condition['email'] . ')';
}
if (!empty($condition['weixin'])) {
$whereOr[] = 'weixin in (' . $condition['weixin'] . ')';
}
$whereOr = implode(" or ", $whereOr);
$sql = "UPDATE __TABLE__ SET `status` = ? WHERE `domain` = ? and `status` < ? AND ({$whereOr})";
return $this->_m->execsql($sql, [
self::ST_DELETE,
QY_DOMAIN,
self::ST_DELETE,
]);
}
/**
* 根据条件获取邀请列表
* @param $condition
* @param null $page_option
* @param array $order_option
* @param string $fields
* @return array|bool
*/
public function listInviteUserByParams($condition, $page_option = null, $order_option = array(), $fields = '*') {
$params = array();
$wheres = array();
if (!$this->_parse_where($wheres, $params, $condition)) {
return false;
}
// 企业标记
$wheres[] = "`ciu`.`{$this->prefield}domain`=?";
$params[] = QY_DOMAIN;
// 状态条件
$wheres[] = "`ciu`.`{$this->prefield}status`<?";
$params[] = $this->get_st_delete();
// 排序
$orderby = '';
if (!$this->_order_by($orderby, $order_option)) {
return false;
}
// 分页参数
$limit = '';
if (!$this->_limit($limit, $page_option)) {
return false;
}
$sql = "SELECT
*
FROM
oa_contact_invite_user ciu
LEFT JOIN oa_contact_invite_link cil on ciu.link_id = cil.link_id
WHERE ";
return $this->_m->fetch_array($sql . implode(' AND ', $wheres) . "{$orderby}{$limit}", $params);
}
}