You can not select more than 25 topics
			Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
		
		
		
		
		
			
		
			
				
					
					
						
							37 lines
						
					
					
						
							753 B
						
					
					
				
			
		
		
		
			
			
			
				
					
				
				
					
				
			
		
		
	
	
							37 lines
						
					
					
						
							753 B
						
					
					
				
								<?php
							 | 
						|
								
							 | 
						|
								namespace App\Http\Middleware;
							 | 
						|
								use App\Models\Agent;
							 | 
						|
								use Closure;
							 | 
						|
								use Illuminate\Http\Request;
							 | 
						|
								use Illuminate\Support\Facades\Cache;
							 | 
						|
								
							 | 
						|
								class ApiBase
							 | 
						|
								{
							 | 
						|
									public function handle(Request $request, Closure $next)
							 | 
						|
									{
							 | 
						|
										$appid = request()->header('appid');
							 | 
						|
								
							 | 
						|
										if (empty($appid)) {
							 | 
						|
											return response()->json([
							 | 
						|
												'code' => -1,
							 | 
						|
												'msg' => '商户信息缺失',
							 | 
						|
												'data' => [],
							 | 
						|
												'status' => 500,
							 | 
						|
											]);
							 | 
						|
										}
							 | 
						|
								
							 | 
						|
										//检查代理商
							 | 
						|
										$agent_id = Agent::query()->where(['appid' => $appid, 'status' => 1])->value('id');
							 | 
						|
										if (empty($agent_id)) {
							 | 
						|
											return response()->json([
							 | 
						|
												'code' => -1,
							 | 
						|
												'msg' => '商户不存在或已被禁用',
							 | 
						|
												'data' => [],
							 | 
						|
												'status' => 403,
							 | 
						|
											]);
							 | 
						|
										}
							 | 
						|
										Cache::put($appid, $agent_id);
							 | 
						|
										return $next($request);
							 | 
						|
									}
							 | 
						|
								}
							 |