<?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; } }