InfoController.class.php 1.82 KB
<?php
/**
 * 管理员角色详情获取
 * InfoController.class.php
 *
 */
namespace Apicp\Controller\AdminRole;

use VcySDK\Adminer;
use Common\Common\Department;

class InfoController extends AbstractController
{
    public function Index()
    {
        // 当前管理员为分级管理时,无权操作
        $user = $this->_login->user;
        if (!isset($user['eaLevel'])) {
            E('_ERR_ADMIN_MANAGER_EALEVEL_UNDEFINED');
        }
        if ($user['eaLevel'] == Adminer::ADMIN_LEVEL_BRANCH) {
            E('_ERR_ADMIN_BRANCH_CANNOT_OPERATE');
        }

        // 接收数据
        $earId = I('post.earId'); // 管理员角色id

        // 管理员角色ID非空验证
        if (empty($earId)) {
            $this->_set_error('_ERR_ADMIN_ROLE_ID_EMPTY');
            return false;
        }

        // 拼接接口所需数据:管理员角色id
        $condition = array(
            'earId' => $earId
        );

        // 调用UC接口,查询管理员详情
        try {
            $this->_result = $this->_sdkRole->detail($condition);
        } catch (\Exception $e) {
            $this->_result = [];
        }

        $dp_ids = array_unique(array_merge($this->_result['readDpIdList'], $this->_result['writeDpIdList']));
        $dp_list = [];

        // 取部门名称
        if (!empty($dp_ids)) {
            $dpServ = &Department::instance(true, true);
            $dps = $dpServ->listById($dp_ids);

            foreach ($dps as $dp) {
                $dp_list[] = [
                    'dp_id' => $dp['dpId'],
                    'dp_name' => $dp['dpName'],
                ];
            }
        }

        $this->_result['dp_list'] = $dp_list;

        if (! $this->_result) {
            $this->_set_error("_ERR_ADMIN_ROLE_NOT_EXIST");
            return false;
        }

        return true;
    }
}