AuthorityService.class.php
4.52 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
<?php
namespace Common\Service;
use Common\Common\Job;
use Common\Common\Role;
use Common\Model\AuthorityMainModel;
use Common\Model\AuthorityModel;
use Common\Model\SettingModel;
class AuthorityService extends \Com\Service
{
// 构造方法
public function __construct()
{
parent::__construct();
$this->_d = new AuthorityModel();
}
/**
* 人员在各个应用标识下的可见范围 (会根据 过滤筛选类型 筛选)
* @param array $userInfo 人员详情 $this->_login->user
* @param string $pluginKey 应用标识
* @return array
*/
public function userPermissionScope($userInfo, $pluginKey = '')
{
// 获取应用信息
$pluginConds = [];
if (!empty($pluginKey)) {
$pluginConds = ['ap_key' => $pluginKey];
}
$pluginServ = new PluginService();
$pluginList = $pluginServ->list_by_conds($pluginConds);
$pluginList = array_combine_by_key($pluginList, 'ap_id');
$apIds = array_column($pluginList, 'ap_id');
// 获取人员 角色 岗位
$auth = [$userInfo['memUid']];
$auth[] = $userInfo['job']['jobId'];
$auth[] = $userInfo['role']['roleId'];
// 当前排名筛选类型
$rankFilter = $this->getRankFilter();
// 获取对应的可见范围
$permissionScope = $this->_d->getPermissionScopeWithAuthorityId($auth, $apIds, $rankFilter);
// 应用标识 对应 可见范围
$result = [];
// 跳过的应用标识
$skipApKey = [];
foreach ($permissionScope as $item) {
// 应用标识
$apKey = $pluginList[$item['ap_id']]['ap_key'];
// 因为已经获取过人员类型的可见范围, 并且人员可见范围优先级最高, 所以跳过
if (in_array($apKey, $skipApKey)) {
continue;
}
// 人员类型 可见范围优先级最高
if ($item['authority_id_type'] == AuthorityModel::AUTHORITY_ID_TYPE_MEMBER) {
// 获取可见范围 ID
$result[$apKey] = explode(',', $item['visible_range']);
// 标记 不在处理 改应用标识下的可见范围
$skipApKey[] = $apKey;
}
// 获取可见范围 ID
$resultKeyList = $result[$apKey];
// 如果是所有人的情况
if ($item['visible_range'] == AuthorityMainModel::VISIBLE_RANGE_ALL) {
$resultKeyList = $this->getAllJobIdOrRoleId($rankFilter);
}
// 过滤筛选类型
if (!in_array($item['visible_range_type'], [$rankFilter, AuthorityMainModel::VISIBLE_RANGE_TYPE_DEFAULT])) {
continue;
}
$result[$apKey] = array_merge(
empty($resultKeyList) ? [] : $resultKeyList,
explode(',', $item['visible_range']));
}
return $result;
}
/**
* 获取 排名筛选条件
* @return int
*/
public function getRankFilter()
{
$cache = \Common\Common\Cache::instance();
$settingList = $cache->get('Common.AppSetting');
// 排名筛选条件:角色,岗位; (默认角色)
$rank_filter = \Common\Model\SettingModel::FILTER_ROLE;
// 如果缓存中有数据,直接获取
if (!empty($settingList) && array_key_exists(SettingModel::SETTING_KEY_RANK_FILTER, $settingList)) {
$rank_filter = $settingList[SettingModel::SETTING_KEY_RANK_FILTER]['value'];
} else {
// 初始化最新数据
$serv = new \Common\Service\SettingService();
$serv->initSetting();
}
return $rank_filter;
}
/**
* 根据当前 排名筛选类型 查询权限对象
* @param $authorityId
* @param $visibleRangeType
* @return mixed
*/
public function listAuthorityWithVisibleRangeType($authorityId, $visibleRangeType)
{
return $this->_d->listAuthorityWithVisibleRangeType($authorityId, $visibleRangeType);
}
/**
* 获取所有 岗位ID 或者 角色ID
* @param $rankFilter
* @return array
*/
public function getAllJobIdOrRoleId($rankFilter)
{
if ($rankFilter == AuthorityMainModel::VISIBLE_RANGE_TYPE_ROLE) {
return array_column((new Role())->listAll(), 'roleId');
} elseif ($rankFilter == AuthorityMainModel::VISIBLE_RANGE_TYPE_JOB) {
return array_column((new Job())->listAll(), 'jobId');
}
return [];
}
}