user_id = is_session_login('user'); if ($this->user_id <= 0) { abort(redirect(url('/signin'))->remember()); } $this->administrator = is_administrator(); $role_id = Session::get('user_auth.role_id'); $base_role = Loader::model('UserRole')->getRow(['id' => $role_id]); $menu_list = $this->getMenuList($base_role['yesorno'], $base_role['rbac_acl'], $this->module, $this->controller, $this->action); //echo "
=="; print_r($menu_list); die;
        $this->view->assign('menu_list', $menu_list);
        $this->view->assign('user_id', $this->user_id);
        $this->view->assign('administrator', $this->administrator);
        $this->adminlang = $this->request->langset();
        $this->view->assign('adminlang', $this->adminlang);
        $this->country_code = session('cit') != '' ? strtoupper(session('cit')) : 'ZH';
        
        
        $product_country_code = "products_".strtolower($this->country_code)."_color";
        $productColor = config($product_country_code);
        $this->view->assign('productColor', $productColor);
        
        
        $this->view->assign('country_code', $this->country_code);
        
        
        
    }

    protected function getMenuList($yesorno, $act_list, $module, $controller, $action) {
        //无需验证的操作
        $uncheck = array('login', 'logout', 'register');
        if (strpos($controller, 'ajax') !== false || in_array($action, $uncheck)) {
            //所有ajax请求不需要验证权限
            return '';
        }
        //$menu_list = $this->cacheGet('menu_list');
        // $menu_list = [];
        if (empty($menu_list)) {
            $menu_list = Loader::model('Dept')->getMenu(['pid' => 0, 'stat' => 0,], ['sort' => 'asc', 'id' => 'desc']);
            $this->cacheTag('DeptTag')->set('menu_list', $menu_list);
        }

        foreach($menu_list as $kn => $items) {
            $menu_list[$kn]['ctrls'] = array();
            if(sizeof($items)){ 
                $ctrls = array();
                foreach($items['child'] as $kd => $item) {
                    $ctrls[] = strtolower($item['ctrl']);
                }
                $menu_list[$kn]['ctrls'] = array_unique($ctrls);                
            }

        }

        //echo "
++++++++++"; print_r($menu_list); die;
        if ($act_list == 'all') {
            if ($this->request->isAjax())
                return '';
            $menu = '' . "\n";
        } else {
            $access = $this->cacheGet($act_list);
            // $access = [];
            if (empty($access)) {
                $access = Loader::model('AuthAccess')->getList(['id' => [$yesorno ? 'in' : 'not in', $act_list], 'module' => $module], null, ['access']);
                $this->cacheTag('AuthAccessTag')->set($act_list, $access);
            }
            $role_right = '';
            // $permission = [];
            foreach ($access as $val) {
                $role_right .= $val['access'] . ',';
            }

            $permission = explode(',', trim($role_right, ','));
            $permission[] = 'Index@index';

            //检查是否拥有此操作权限
            
        
            if (!in_array($controller . '@' . $action, $permission)) {
                $this->error(_lang_('no permission to operate') . '[' . ($controller . '@' . $action) . ']', url('/admin/Index/index'));
            }
            if ($this->request->isAjax())
                return '';

            //$this->getForMenuList($menu_list, $permission, $module);
            $menu = '' . "\n";
        }
        return $menu;
    }

    protected function getHtmlMenuList($list, $permission, $module, $controller) {
        // tiaoshi($permission);
        // tiaoshi($module);
        // tiaoshi($list[2]);die;
        // 
        
        $menu = '';
        if(is_array($list) && sizeof($list)) {
            foreach ($list as $k1 => $list1) {
                // tiaoshi($list[$k1]['child']);die;
                switch ($list1['functype']) {
                    case 0:
                        if (!in_array($list1['url'], $permission)) {
                            continue;
                        }
                        if ($list1['hidden']) {
                            continue;
                        }
    
                        if ($list1['haschild'] && !empty($list1['child'])) {
                            $active = in_array(strtolower($controller), $list1['ctrls']) ? "active" : "";
                            $menu .= '
  • ' . $list1['name'] . ' ' . "\n"; $menu .= '
      '; $menu .= $this->getHtmlMenuList($list[$k1]['child'], $permission, $module, $controller); $menu .= '
    ' . "\n" . '
  • ' . "\n"; } else { $menu .= '
  • ' . $list1['name'] . ' temp
  • ' . "\n"; } break; case 1: if (!in_array($list1['ctrl'] . '@' . $list1['action'], $permission)) { continue; } if ($list1['hidden']) { continue; } $menu .= '
  • ' . $list1['name'] . '
  • ' . "\n"; break; case 2: if (!in_array($list1['url'], $permission)) { continue; } if ($list1['hidden']) { continue; } $menu .= '
  • ' . $list1['name'] . '
  • '; break; default: continue; break; } } return $menu; } } protected function getAllHtmlMenuList(&$list, &$permission, $module, $controller) { $menu = ''; foreach ($list as $k1 => $list1) { switch ($list1['functype']) { case 0: if ($list1['hidden']) { continue; } if ($list1['haschild'] && !empty($list1['child'])) { $active = in_array(strtolower($controller), $list1['ctrls']) ? "active" : ""; $menu .= '
  • ' . $list1['name'] . ' ' . "\n"; $menu .= '
      '; $menu .=$this->getAllHtmlMenuList($list[$k1]['child'], $permission, $module, $controller); $menu .= '
    ' . "\n" . '
  • ' . "\n"; } else { $menu .= '
  • ' . $list1['name'] . ' temp
  • ' . "\n"; } break; case 1: if ($list1['hidden']) { continue; } $menu .= '
  • ' . $list1['name'] . '
  • ' . "\n"; break; case 2: if ($list1['hidden']) { continue; } $menu .= '
  • ' . $list1['name'] . '
  • '; break; default: continue; break; } } return $menu; } }