<?php


namespace App\Http\Middleware;

use Closure;

class CheckRole
{
    /**
     * @param \Illuminate\Http\Request $request
     * @param Closure $next
     */
    public function handle($request, Closure $next)
    {

        $admin = $request->session()->get('admin');
        //获取当前管理员角色
        $roles = $admin->roles;
        if ($roles->isEmpty()) {
            return redirect('403');
        }
        // 二挡子账号ID - 客服 - 普通管理员
        $whiteListId = [11];
        $hidden = $roles->each(function ($role) use ($whiteListId, $request) {
            if (in_array($role->id, $whiteListId)) {
                switch ($role->id) {
                    case 11:
                        $request->session()->put('hidden', ['is_hidden' => 'service']);
                        break;
                }

            }
        });

        // 账号ID限制 -- 管理员限制渠道
        $adminIds = [1,1020];
        if (in_array($admin->id, $adminIds)) {
            $request->session()->put('admin_hidden', ['is_hidden' => 'admin_channel']);
        }
        return $next($request);

    }
}
