DepartmentsController.class.php 1.02 KB
<?php

/**
 * 获取用户所在部门及其子部门.
 *
 * @auther zs_anything
 * @date 2017/08/03
 */
namespace Api\Controller\Integral;

use Common\Common\Department;
use Common\Model\PluginModel;

class DepartmentsController extends AbstractController
{

    public function Index()
    {

        $this->checkAuthRange(PluginModel::INTEGRAL_CENTER);

        $memUid = $this->_login->user['memUid'];

        $deptUtil = new Department();

        // 根据用户id获取当前部门
        $myDpIds = $deptUtil->list_dpId_by_uid($memUid);

        // 所有部门及子部门
        $dpIds = $deptUtil->list_childrens_by_cdid($myDpIds, true);

        // 获取部门id及部门名称
        $depts = $deptUtil->listById($dpIds, array('dpId', 'dpName'));

        // 根据部门排序字段、部门等级来升序排序
        array_multisort(array_column($depts, 'dpLevel'), SORT_ASC,
            array_column($depts, 'dpDisplayorder'), SORT_ASC, $depts);

        $this->_result = array_values($depts);

        return true;
    }
}