ChooseMemberCountController.class.php
3.53 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
<?php
/**
* 根据已选择获取已选择总人数
* Created by PhpStorm.
* User: 大熊
* Date: 2018/6/7
* Time: 10:52
*/
namespace Apicp\Controller\ChooseMem;
use Common\Common\Tag;
use Common\Common\User;
class ChooseMemberCountController extends AbstractController
{
/**
* 是否全公司:是
*/
const ALL_TRUE = 1;
/**
* 是否全公司:否
*/
const ALL_FALSE = 0;
/**
* 根据已选择获取已选择总人数
* @return bool
*/
public function Index()
{
$param = I('post.');
if (!isset($param['is_all']) || !in_array($param['is_all'], [self::ALL_FALSE, self::ALL_TRUE])) {
$this->_set_error('参数字段有误');
return false;
}
$userIds = $this->rightByIds($param);
$this->_result = [
'number' => count($userIds)
];
return true;
}
/**
* 获取权限用户uid集合
* @param array $param
* @return array
*/
public function rightByIds($param = [])
{
// 全公司
if (self::ALL_TRUE == $param['is_all']) {
// 用户列表
$userList = User::instance()->listAllBasic([]);
return array_column($userList, 'memUid');
}
$rightData = $param['right'] ? $param['right'] : [];
if (empty($rightData)) {
return [];
}
// 获取用户UID列表
$userIds = array_values(array_filter(array_column($rightData['user_list'], 'memID'))) ?? [];
// 获取部门ID列表
$dpIds = array_values(array_filter(array_column($rightData['dp_list'], 'dpID'))) ?? [];
// 获取角色ID列表
$roleIds = array_values(array_filter(array_column($rightData['role_list'], 'roleID'))) ?? [];
// 获取岗位ID列表
$jobIds = array_values(array_filter(array_column($rightData['job_list'], 'jobID'))) ?? [];
// 获取标签ID列表
$tagIds = array_values(array_filter(array_column($rightData['tag_list'], 'tagID'))) ?? [];
if (empty($userIds) && empty($dpIds) && empty($roleIds) && empty($jobIds) && empty($tagIds)) {
return [];
}
// 标签
if (!empty($tagIds)) {
$tagLibrary = new Tag();
$tagList = $tagLibrary->listUserByTagId($tagIds);
$tagDpId = array_filter(array_column($tagList['list'], 'dpId'));
$tagUid = array_filter(array_column($tagList['list'], 'memUid'));
$userIds = array_merge($userIds, (array)$tagUid);
$dpIds = array_merge($dpIds, (array)$tagDpId);
}
// 部门ID
$dpUserIds = [];
if (!empty($dpIds)) {
$dpUserIds = User::instance()->listAllBasic([
'dpIdList' => $dpIds,
'departmentChildrenFlag' => 1
]);
$dpUserIds = array_column($dpUserIds, 'memUid');
}
// 岗位
$jobUserIds = [];
if (!empty($jobIds)) {
$jobUserIds = User::instance()->listAllBasic(['jobIdList' => $jobIds]);
$jobUserIds = array_column($jobUserIds, 'memUid');
}
// 角色
$roleUserIds = [];
if (!empty($roleIds)) {
$roleUserIds = User::instance()->listAllBasic(['roleIdList' => $roleIds]);
$roleUserIds = array_column($roleUserIds, 'memUid');
}
// 合并所有uid
$userIds = array_merge($userIds, $dpUserIds, $jobUserIds, $roleUserIds);
return array_values(array_filter(array_unique($userIds)));
}
}