AbstractController.class.php 1.6 KB
<?php
/**
 * 管理员角色基类
 * AbstractController.class.php
 * $author$
 */

namespace Apicp\Controller\AdminRole;

use VcySDK\Service;
use VcySDK\AdminerRole;
use Common\Common\Department;

abstract class AbstractController extends \Common\Controller\Apicp\AbstractController
{

    /**
     * @type AdminerRole
     */
    protected $_sdkRole = null;

    protected $needCheckThePayment = false;

    public function before_action($action = '')
    {

        if (! parent::before_action($action)) {
            return false;
        }

        // 调用UC接口,查询管理员角色详情
        $this->_sdkRole = new AdminerRole(Service::instance());
        return true;
    }

    /**
     * 判断是否为保护角色名称
     *
     * @param string $name 角色名称
     *
     * @return bool
     */
    protected function _isProtectName($name)
    {

        return cfg('ADMIN_ROLE_PROTECT_NAME') == $name;
    }

    /**
     * 过滤父级部门
     * @param array $dp_ids 部门ID
     * @return array
     */
    protected function _filterDp($dp_ids)
    {
        if (!is_array($dp_ids) || empty($dp_ids)) {
            return [];
        }

        $dp_ids = array_unique($dp_ids);
        $dpServ = &Department::instance();

        foreach ($dp_ids as $k => $dp_id) {
            // 获取所有子级部门ID
            $children = $dpServ->list_childrens_by_cdid($dp_id);

            // 判断子级部门ID是否存在于数组中
            if (array_intersect($children, $dp_ids)) {
                unset($dp_ids[$k]);
            }
        }

        return array_values($dp_ids);
    }

}