<?php
/**
 * Created by PhpStorm.
 * User: tandunzhao
 * Date: 2017/12/22
 * Time: 下午1:41
 */

namespace App\Http\Controllers\Manage;

use App\Http\Controllers\Controller;

class BaseController extends Controller
{


    //获取当前登录用户ID
    function getLoginUserId() {
        if(empty(session('manage_user'))) {
            if(env('APP_ENV') =='local') return 1;
        }

        $user = unserialize(session('manage_user'));
        return $user->id;
    }

    //获取当前登录用户角色
    function getLoginUserRole() {
        if(empty(session('manage_user'))) {
            if(env('APP_ENV') =='local') return 'admin';
        }

        $user = unserialize(session('manage_user'));
        return $user->role;
    }
    
    //获取当前登录用户
    function getLoginUserAccount() {
    	if(empty(session('manage_user'))) {
    		if(env('APP_ENV') =='local') return 'admin';
    	}
    
    	$user = unserialize(session('manage_user'));
    	return $user->account;
    }

    function getLoginUser() {
        if(empty(session('manage_user'))) {
            if(env('APP_ENV') =='local') return '';
        }

        $user = unserialize(session('manage_user'));
        return $user;
    }
    
    // 编辑权限
    function  checkEditRole(){
    	// check 当前是老司机才有权限
    	$account = $this->getLoginUserAccount();
    	
    	if($account == 'zsy_sjj' || $account == 'zsy_zlj' || $account == 'zsy_gdy'){
    		return true;
    	}
    	return false;
    }
}