AbstractController.class.php
2.93 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
<?php
/**
* Created by PhpStorm.
* User: liyifei
* Date: 16/9/13
* Time: 下午14:10
*/
namespace Api\Controller;
use Common\Common\Cache;
use Common\Common\Department;
use Common\Common\User;
use \Common\Controller\Api;
use Common\Service\InviteSettingService;
abstract class AbstractController extends Api\AbstractController
{
public function before_action($action = '')
{
if (!parent::before_action($action)) {
return false;
}
return true;
}
public function after_action($action = '')
{
return parent::after_action();
}
/**
* 检查邀请权限
* @param $user
* @return bool
*/
public function checkCurrentInvitePower($user)
{
if (empty($user) || empty($user['memUid'])) {
E('_ERR_NOT_LOGIN');
}
// 人员权限
$powers = array($user['memUid']);
if (!empty($user['job'])) {
$powers[] = $user['job']['jobId'];
}
if (!empty($user['role'])) {
$powers[] = $user['role']['roleId'];
}
// 获取设置的权限
$settingService = new InviteSettingService();
$setting = $settingService->get_by_conds([]);
$auths = array();
if (!empty($setting['invite_udpids'])) {
$auths = unserialize($setting['invite_udpids']);
}
// 是否有权
if (empty($auths['auths']) || !array_intersect($powers, $auths['auths'])) {
E('_ERR_NO_INVITE_RIGHT');
}
return true;
}
/**
* 判断管理权限
* @param $user
* @return bool
*/
public function checkCurrentManagePower($user)
{
if (empty($user) || empty($user['memUid'])) {
E('1007:请先登录');
return false;
}
$powers = array($user['memUid']);
if (!empty($user['job'])) {
$powers[] = $user['job']['jobId'];
}
if (!empty($user['role'])) {
$powers[] = $user['role']['roleId'];
}
if (!empty($user['dpName'])) {
$department = Department::instance();
foreach ($user['dpName'] as $item) {
$parentDpIds[$item['dpId']] = $item['dpId'];
$department->list_parent_cdids($item['dpId'], $parentDpIds);
$powers = array_merge($powers, array_values($parentDpIds));
}
}
$settings = Cache::instance()->get('Common.AppSetting');
// 查看是否已经配置了管理权限
if (empty($settings['manageAuths']) || empty($settings['manageAuths']['value']['auths'])) {
E('1009:管理员还未配置管理权限');
return false;
}
$auths = $settings['manageAuths']['value']['auths'];
if (empty($auths) || !array_intersect($powers, $auths)) {
E('1008:您无权限管理员工');
return false;
}
return true;
}
}