12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061 |
- <?php
- namespace App\Http\Middleware\Permission;
- use App\Servers\AdminLogsServer;
- use App\Servers\PermissionServer;
- use Closure;
- class Permission
- {
- /**
- * Handle an incoming request.
- *
- * @param \Illuminate\Http\Request $request
- * @param \Closure $next
- * @return mixed
- *
- * 后台权限限制
- */
- public function handle($request, Closure $next)
- {
- // 获取当前会员信息
- $user = app('auth')->user();
- AdminLogsServer::write(empty($user->id)?0:$user->id,'后台访问日志记录');
- // // 判断当前会员是否具有权限
- $clientRoute = request()->route()->getName();
- // $p_num=\App\Models\Permission::where('routes',$clientRoute)->count();
- // if($p_num<=0){
- // \App\Models\Permission::create(['routes'=>$clientRoute,'name'=>$clientRoute,'sort'=>1,'p_id'=>1,'type'=>'3']);
- // }
- if(in_array($clientRoute,['login','admin.index.ajax','admin.not.permission','admin.index','admin.ajaxIndex','admin.switch','admin.u_sort']) || $user->{"id"}==1){
- return $next($request);
- }
- $date_time=date('Hi');
- // if( $date_time<800){
- // echo 'end';exit;
- // return redirect()->route('admin.not.permission');
- // }
- // dd($clientRoute);
- $ret=PermissionServer::verifyPermission($user->{'id'},$clientRoute);
- if ( empty($ret) ) {
- $is_ajax=request()->ajax();
- if($is_ajax){
- return response()->json([
- 'status' => 'error',
- 'message' => '暂无权限',
- 'redirect' => '',
- 'callback' => '',
- 'data' => []
- ]);
- }else{
- // 当前会员没有权限
- return redirect()->route('admin.not.permission');
- }
- }
- return $next($request);
- }
- }
|