AuthorityController.class.php
2.92 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
<?php
/**
* 管理者助手权限
* 1. 员工管理
* 2. 邀请员工
* 3. 通讯录是否安装
* 4. 员工积分排行
*/
namespace Api\Controller\Index;
use Common\Model\SettingModel;
use Common\Service\AuthorityMainService;
use Common\Service\AuthorityService;
class AuthorityController extends AbstractController
{
public function Index()
{
list(
// 1. 员工管理
$contact,
// 2. 邀请员工
$invite,
// 3. 通讯录是否安装
$contactInstalled) = \Com\Rpc::phprpc(
rpcUrl('/Contact/Rpc/Competence/Authority')
)->invoke('Index', $this->_login->user);
if ($contact) {
$this->_result[] = 'contact';
}
if ($invite) {
$this->_result[] = 'invite';
}
if ($contactInstalled) {
$this->_result[] = 'contactInstalled';
}
// 4. 员工积分排行
if ($this->getIntegralRankingAuth()) {
$this->_result[] = 'integral_ranking';
}
return true;
}
/**
* 员工积分排行
* @return bool
*/
protected function getIntegralRankingAuth()
{
// 获取用户
$authorityServ = new AuthorityService();
$authorityId = [$this->uid];
if (!empty($this->_login->user['job']['jobId'])) {
$authorityId[] = $this->_login->user['job']['jobId'];
}
if (!empty($this->_login->user['role']['roleId'])) {
$authorityId[] = $this->_login->user['role']['roleId'];
}
$visibleRangeList = $authorityServ->list_by_conds(['authority_id' => $authorityId]);
$amIds = array_column($visibleRangeList, 'am_id');
if (empty($amIds)) {
return false;
}
// 获取权限设置
$authorityMainServ = new AuthorityMainService();
$authorityMainList = $authorityMainServ->list_by_conds([
'am_id' => $amIds,
'visible_range_type' => $this->getRankFilter(),
]);
if (empty($authorityMainList)) {
return false;
}
return true;
}
/**
* 获取 排名筛选条件
* @return int
*/
protected 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;
}
}