180 lines
		
	
	
		
			4.7 KiB
		
	
	
	
		
			PHP
		
	
	
	
	
	
			
		
		
	
	
			180 lines
		
	
	
		
			4.7 KiB
		
	
	
	
		
			PHP
		
	
	
	
	
	
<?php
 | 
						|
/**
 | 
						|
 *	后台管理系统-管理员
 | 
						|
 */
 | 
						|
namespace app\admin\controller;
 | 
						|
use app\AppApi;
 | 
						|
use think\facade\Db;
 | 
						|
use think\facade\View;
 | 
						|
use think\facade\Cookie;
 | 
						|
use think\facade\Config;
 | 
						|
 | 
						|
use app\admin\model\YzAdminConfig;
 | 
						|
 | 
						|
use think\exception\HttpResponseException;
 | 
						|
use think\facade\Request;
 | 
						|
use think\facade\Route; 
 | 
						|
 | 
						|
class Base{
 | 
						|
	public $adminId = null;
 | 
						|
	public $config = [];
 | 
						|
	public $aUser = [];
 | 
						|
	public function __construct(){
 | 
						|
		date_default_timezone_set('PRC');
 | 
						|
		# 获取配置
 | 
						|
		$YzAdminConfig = new YzAdminConfig();
 | 
						|
		$this->config = $YzAdminConfig->getAll();
 | 
						|
		# 获取账户,账户判断
 | 
						|
		$this->adminId = Cookie::get('admin_id');
 | 
						|
		if(empty($this->adminId)){
 | 
						|
			header('Location:'.$this->config['admin_route'].'Login/index');
 | 
						|
			exit;
 | 
						|
		}
 | 
						|
		$this->aUser = Db::table('yz_admin_user')->where('uid',$this->adminId)->find();
 | 
						|
		
 | 
						|
		if (empty($this->aUser)) {
 | 
						|
			Cookie::delete('admin_id');
 | 
						|
			$this->error('管理员账户不存在');
 | 
						|
		}
 | 
						|
		if ($this->aUser['status'] != 1) {
 | 
						|
			Cookie::delete('admin_id');
 | 
						|
			$this->error('管理员已被禁用');
 | 
						|
		}
 | 
						|
		# 获取用户组权限
 | 
						|
		$group = Db::table('yz_admin_user_group')->where(['group_id'=>$this->aUser['group_id']])->find();
 | 
						|
		if(empty($group)){
 | 
						|
			$this->error('对不起,您没有权限');
 | 
						|
		}
 | 
						|
		# 获取当前链接,查询是否有权限
 | 
						|
		$controller = request()->controller();
 | 
						|
		$action = request()->action();
 | 
						|
		$key = $controller.'/'.$action;
 | 
						|
		
 | 
						|
		// // 演示站专用
 | 
						|
		// if(Request::isPost()){
 | 
						|
		// 	if(
 | 
						|
		// 		$key == 'Yunzer/configvalue' || 
 | 
						|
		// 		$key == 'Yunzer/configadd' || 
 | 
						|
		// 		$key == 'Yunzer/configedit' || 
 | 
						|
		// 		$key == 'Yunzer/configdel' || 
 | 
						|
		// 		$key == 'Yunzer/menuadd' || 
 | 
						|
		// 		$key == 'Yunzer/menuedit' || 
 | 
						|
		// 		$key == 'Yunzer/menudel' || 
 | 
						|
		// 		$key == 'Yunzer/buttonadd' || 
 | 
						|
		// 		$key == 'Yunzer/buttonedit' || 
 | 
						|
		// 		$key == 'Yunzer/buttondel' || 
 | 
						|
		// 		$key == 'Yunzeradmin/groupadd' || 
 | 
						|
		// 		$key == 'Yunzeradmin/groupedit' || 
 | 
						|
		// 		$key == 'Yunzeradmin/groupdel' || 
 | 
						|
		// 		$key == 'Yunzeradmin/useradd' || 
 | 
						|
		// 		$key == 'Yunzeradmin/useredit' || 
 | 
						|
		// 		$key == 'Yunzeradmin/userdel' || 
 | 
						|
		// 		$key == 'Yunzeradmin/admininfo' || 
 | 
						|
		// 		$key == 'Yunzeradmin/test_add' || 
 | 
						|
		// 		$key == 'Yunzeradmin/test_edit' || 
 | 
						|
		// 		$key == 'Yunzeradmin/test_static_add' || 
 | 
						|
		// 		$key == 'Yunzeradmin/test_static_edit' || 
 | 
						|
		// 		$key == 'Index/upload_img' || 
 | 
						|
		// 		$key == 'Index/upload_img_s' || 
 | 
						|
		// 		$key == 'Index/upload_imgs_kin'
 | 
						|
		// 	){
 | 
						|
		// 		$this->returnCode(1,'演示站,不能操作');
 | 
						|
		// 	}
 | 
						|
		// }
 | 
						|
		// // 演示站专用
 | 
						|
		
 | 
						|
		// if($key == 'Index/index' ||  $key == 'Index/welcome'){
 | 
						|
			
 | 
						|
		// }else{
 | 
						|
		// 	$aMenu = Db::table('yz_admin_sys_menu')->where('src',$key)->find();
 | 
						|
		// 	if(empty($aMenu)){
 | 
						|
		// 		$this->error('对不起,您访问的功能不存在');
 | 
						|
		// 	}
 | 
						|
		// 	$rights = json_decode($group['rights']);
 | 
						|
		// 	if(!in_array($aMenu['smid'],$rights)){
 | 
						|
		// 		$this->error('对不起,您没有权限');
 | 
						|
		// 	}
 | 
						|
		// }
 | 
						|
		View::assign([
 | 
						|
			'aUser' => $this->aUser,
 | 
						|
			'config' => $this->config
 | 
						|
		]);
 | 
						|
	}
 | 
						|
	/**
 | 
						|
	 * 返回json对象
 | 
						|
	 */
 | 
						|
	protected function returnCode($code,$data=[],$count=10){
 | 
						|
		header('Content-type:application/json');
 | 
						|
		if($code == 0){
 | 
						|
			$arr = array(
 | 
						|
				'code'=>$code,
 | 
						|
				'msg'=>'成功',
 | 
						|
				'count'=> $count,
 | 
						|
				'data' => $data
 | 
						|
			);
 | 
						|
		}else if($code >= 1 && $code <= 100){
 | 
						|
			$arr = array(
 | 
						|
				'code'	=>	$code,
 | 
						|
				'msg'	=>	$data
 | 
						|
			);
 | 
						|
		}else{
 | 
						|
			$appapi = new AppApi();
 | 
						|
			$arr = array(
 | 
						|
				'code'=>$code,
 | 
						|
				'msg'=>$appapi::errorTip($code)
 | 
						|
			);
 | 
						|
		}
 | 
						|
		echo json_encode($arr);
 | 
						|
		if($code != 0){
 | 
						|
			exit;
 | 
						|
		}
 | 
						|
	}
 | 
						|
 | 
						|
	/**
 | 
						|
     * 操作成功跳转的快捷方法
 | 
						|
     * @access protected
 | 
						|
     * @param  mixed     $msg 提示信息
 | 
						|
     * @return void
 | 
						|
     */
 | 
						|
    protected function success($msg = '')
 | 
						|
    {
 | 
						|
        $result = [
 | 
						|
            'code' => 1,
 | 
						|
            'msg'  => $msg
 | 
						|
        ];
 | 
						|
 | 
						|
        $type = $this->getResponseType();
 | 
						|
        if ($type == 'html'){
 | 
						|
            $response = view(Config::get('app.dispatch_success_tmpl'), $result);
 | 
						|
        } else if ($type == 'json') {
 | 
						|
            $response = json($result);
 | 
						|
        }
 | 
						|
        throw new HttpResponseException($response);
 | 
						|
    }
 | 
						|
 | 
						|
    /**
 | 
						|
     * 操作错误跳转的快捷方法
 | 
						|
     * @access protected
 | 
						|
     * @param  mixed     $msg 提示信息
 | 
						|
     * @return void
 | 
						|
     */
 | 
						|
    protected function error($msg = '')
 | 
						|
    {
 | 
						|
        $result = [
 | 
						|
            'code' => 0,
 | 
						|
            'msg'  => $msg
 | 
						|
        ];
 | 
						|
		$response = view(Config::get('app.dispatch_error_tmpl'), $result);
 | 
						|
        throw new HttpResponseException($response);
 | 
						|
    }
 | 
						|
 | 
						|
    /**
 | 
						|
     * 获取当前的response 输出类型
 | 
						|
     * @access protected
 | 
						|
     * @return string
 | 
						|
     */
 | 
						|
    protected function getResponseType()
 | 
						|
    {
 | 
						|
        return Request::isJson() || Request::isAjax() ? 'json' : 'html';
 | 
						|
    }
 | 
						|
} |