SearchController.class.php
2.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
<?php
/**
* Created by PhpStorm.
* User: liyifei2012it
* Date: 16/9/17
* Time: 23:20
*/
namespace Apicp\Controller\Department;
use Common\Common\AdminerRole;
use VcySDK\Service;
use VcySDK\Department;
class SearchController extends AbstractController
{
/**
* 【通讯录】搜索部门
* @author liyifei
* @time 2016-09-19 14:50:22
*/
public function Index_post()
{
// 接收参数
$keyword = I('post.keyword');
// 调用架构接口,搜索部门列表
$departmentServ = new Department(Service::instance());
$conds = [];
if (!empty($keyword)) {
$conds = [
'dpName' => $keyword,
];
}
$result = $departmentServ->listAll($conds, 1, 99999);
// 处理扩展属性
$result['list'] = array_combine_by_key($result['list'], 'dpId');
\Common\Common\Department::parseExt($result['list'], $result['extList']);
$list = [];
$adminerRoleUtil = new AdminerRole();
foreach ($result['list'] as $v) {
// 获取部门管理员权限
if (false === ($auth = $adminerRoleUtil->childrenDepInAuth($this->_login->role, $v['dpId']))) {
// 部门 以及 部门所有子部门 没有权限, 直接不显示
continue;
};
$v['write'] = $auth[0];
$v['read'] = $auth[1];
$this->changeField($v, [
'departmentMemberCount' => 'user_total',
'dpLevel' => 'dept_level',
]);
$list[] = $v;
}
$this->_result = [
'list' => $list
];
}
/**
* 变更数组字段名
* @param $depData
* @param $fieldChange
* @return bool
*/
private function changeField(&$depData, $fieldChange)
{
foreach ($fieldChange as $fieldName => $changeTo) {
$depData[$changeTo] = $depData[$fieldName];
unset($depData[$fieldName]);
}
return true;
}
}