VisibleSearchRangeController.class.php
2.76 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
<?php
/**
* 获取管理者可查看的岗位或角色范围
*
* @auther zs_anything
* @date 2017/08/04
*/
namespace Api\Controller\Integral;
use Common\Common\Cache;
use Common\Common\Job;
use Common\Common\Role;
use Common\Model\AuthorityMainModel;
use Common\Model\PluginModel;
use Common\Model\SettingModel;
use Common\Service\SettingService;
class VisibleSearchRangeController extends AbstractController
{
public function Index()
{
$authorRange = $this->checkAuthRange(PluginModel::INTEGRAL_CENTER);
// 查询系统当前配置的积分排名筛选类型
$visibleRangeType = AuthorityMainModel::VISIBLE_RANGE_TYPE_JOB;
$settings = Cache::instance()->get('Common.AppSetting');
if (!empty($settings) && array_key_exists("rank_filter", $settings)) {
$visibleRangeType = $settings['rank_filter']['value'];
}
$this->formatResultData(intval($visibleRangeType), $authorRange);
return true;
}
/**
* @param $visibleRangeType
* @param $authorRange
*/
private function formatResultData($visibleRangeType, $authorRange)
{
// 当前用户没有配置可见的岗位或角色筛选条件
if (empty($authorRange[PluginModel::INTEGRAL_CENTER])) {
$this->_result = [
'list' => [],
'type' => $visibleRangeType
];
}
// 按岗位筛选
if (AuthorityMainModel::VISIBLE_RANGE_TYPE_JOB == $visibleRangeType) {
$jobUtil = new Job();
$jobList = $jobUtil->listById($authorRange[PluginModel::INTEGRAL_CENTER]);
$resJobList = $this->formatJobOrRole($jobList, 'jobId', 'jobName');
$this->_result = [
'list' => $resJobList,
'type' => $visibleRangeType
];
}
// 按角色筛选
if (AuthorityMainModel::VISIBLE_RANGE_TYPE_ROLE == $visibleRangeType) {
$roleUtil = new Role();
$roleList = $roleUtil->listById($authorRange[PluginModel::INTEGRAL_CENTER]);
$resRoleList = $this->formatJobOrRole($roleList, 'roleId', 'roleName');
$this->_result = [
'list' => $resRoleList,
'type' => $visibleRangeType
];
}
}
/**
* 格式化岗位或角色返回信息
* @param $list
* @param $id
* @param $name
* @return array
*/
private function formatJobOrRole($list, $id, $name)
{
$resList = [];
if (empty($list)) {
return $resList;
}
foreach ($list as $item) {
$resList[] = [
'id' => $item[$id],
'name' => $item[$name],
];
}
return $resList;
}
}