<?php
namespace app\admin\controller;
use think\App;
use think\facade\Session;
use think\facade\View;
use think\facade\Db;

class index extends Base{
	
	//admin首页
    public function index(){
		$list=\app\admin\model\AuthRule::admin_index_left(0,1);
		foreach($list as $k=>$c){
			$list[$k]['data']=$this->admin_index_left_array($c['id']);
		}	


		$admin_id = Session::get('admin_id');
		$admin_info=\app\admin\model\Admin::admin_info(1,$admin_id);
		$auth_group_info=\app\admin\model\Common::info($admin_info['auth_id'],'auth_group','rid');
		
		//普通管理根据tq_auth_group设定走
		if($admin_info['is_super']==1){
			foreach($list as $k=>$v){
				$isin=inarray($v['id'],$auth_group_info['rid']);
				if($isin==0){
				unset($list[$k]);
				}
				foreach($v['data'] as $t=>$f){
					$isin1=inarray($f['id'],$auth_group_info['rid']);
					if($isin1==0){
						unset($list[$k]['data'][$t]);
					}
				}
			}
		}
		
		//栏目icon
		$left_icon=config('common.LEFT_ICON');
		
		View::assign(['admin_info'=>$admin_info,'list'=>$list,'admin_info'=>$admin_info,'left_icon'=>$left_icon]);
		return View::fetch();
    }

	function admin_index_left_array($pid){
		$list=\app\admin\model\AuthRule::admin_index_left($pid,1);
		foreach($list as $k=>$c){
			$list[$k]['data']=$this->admin_index_left_array($c['id']);
		}
		return $list;
	}
	
	//内部首页
    public function page(){
		 // 系统信息
        $mysqlVersion = Db::query('SELECT VERSION() AS ver');
        $config       = [
            'url'             => $_SERVER['HTTP_HOST'],
            'document_root'   => $_SERVER['DOCUMENT_ROOT'],
            'server_os'       => PHP_OS,
            'server_port'     => $_SERVER['SERVER_PORT'],
            'server_ip'       => isset($_SERVER['SERVER_ADDR']) ? $_SERVER['SERVER_ADDR'] : '',
            'server_soft'     => $_SERVER['SERVER_SOFTWARE'],
            'php_version'     => PHP_VERSION,
            'mysql_version'   => $mysqlVersion[0]['ver'],
            'max_upload_size' => ini_get('upload_max_filesize'),
            'version'         => app()->version(),
        ];

		
		View::assign(['config'=>$config]);
		return View::fetch();
    }

    // 退出登录
    public function logout(){
        Session::delete('admin_id');
        return redirect('index');
    }


}
