AbstractService.class.php
5.02 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
<?php
/**
* AbstractService.class.php
* Service 层基类
* @author: tangxingguo
* @version: $Id$
* @copyright: vchangyi.com
*/
namespace Common\Service;
use Common\Common\Department;
use Common\Common\Job;
use Common\Common\User;
use Common\Model\RightModel;
use Common\Common\Cache;
use Common\Common\Role;
use Common\Common\Tag;
abstract class AbstractService extends \Com\Service
{
protected $_d_right;
// 构造方法
public function __construct()
{
$this->_d_right = new RightModel();
parent::__construct();
}
/**
* 获取格式化后的权限数据
*
* @author 何岳龙
* @param array $conds 权限筛选条件
*
* @return array
* + array dp_list 部门信息
* + string dp_id 部门ID
* + string dp_name 部门名称
* + array tag_list 标签信息
* + string tag_id 标签ID
* + string tag_name 标签名称
* + array user_list 人员信息
* + string uid 用户ID
* + string username 用户姓名
* + string face 头像
*/
public function get_auth($conds = [])
{
$list = $this->_d_right->list_by_conds($conds);
$rights_db = $this->format_db_data($list);
$data = [
'user_list' => [],
'dp_list' => [],
'job_list' => [],
'role_list' => [],
'tag_list' => []
];
$dpServ = &Department::instance();
$userServ = &User::instance();
$roleServ = &Role::instance();
$jobServ = &Job::instance();
$tagServ = &Tag::instance();
foreach ($rights_db as $k => $v) {
switch ($k) {
// 部门
case 'dp_ids':
if (!empty($v)) {
sort($v);
$dps = $dpServ->listById($v);
foreach ($dps as $dp) {
$data['dp_list'][] = [
'dpID' => $dp['dpId'],
'dpName' => $dp['dpName'],
];
}
}
break;
// 人员
case 'uids':
if (!empty($v)) {
sort($v);
$users = $userServ->listAll(['memUids' => $v]);
foreach ($users as $user) {
$data['user_list'][] = [
'memID' => $user['memUid'],
'memUsername' => $user['memUsername'],
'memFace' => $user['memFace'],
];
}
}
break;
// 岗位
case 'job_ids':
if (!empty($v)) {
$jobs = $jobServ->listById($v);
foreach ($jobs as $job) {
$data['job_list'][] = [
'jobID' => $job['jobId'],
'jobName' => $job['jobName'],
];
}
}
break;
// 角色
case 'role_ids':
if (!empty($v)) {
$roles = $roleServ->listById($v);
foreach ($roles as $role) {
$data['role_list'][] = [
'roleID' => $role['roleId'],
'roleName' => $role['roleName'],
];
}
}
break;
// 标签
case 'tag_ids':
sort($v);
if (!empty($v)) {
$tags = $tagServ->listAll($v);
foreach ($tags as $tag) {
$data['tag_list'][] = [
'tagID' => $tag['tagId'],
'tagName' => $tag['tagName'],
];
}
}
break;
}
}
return $data;
}
/**
* 格式化数据库中的权限数据
*
* @author houyingcai
* @param array $rights 权限数据
*
* @return array
*/
public function format_db_data($rights)
{
$data = [];
// 数据分组
$data['uids'] = array_filter(array_column($rights, 'uid'));
$data['dp_ids'] = array_filter(array_column($rights, 'cd_id'));
$data['job_ids'] = array_filter(array_column($rights, 'job_id'));
$data['role_ids'] = array_filter(array_column($rights, 'role_id'));
$data['tag_ids'] = array_filter(array_column($rights, 'tag_id'));
return $data;
}
}