| 
						
						
							
								
							
						
						
					 | 
				
				 | 
				
					@ -41,14 +41,16 @@ class OrderTimeout extends Command | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
						 */ | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					    public function handle() | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
						{ | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
							//需要处理的订单状态
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
							$status_arr = [OrderStatus::UNPAID, OrderStatus::PAY_EARNEST]; | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
							//记录最小ID,下次查询时按ID正序查询,只处理大于该ID的订单,避免重复扫描数据库
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
							$min_id = Order::query()->where('status', OrderStatus::UNPAID)->min('id'); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
							$min_id = Order::query()->whereIn('status', $status_arr)->min('id'); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					    	while (true) { | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
								Order::query() | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
									->where([ | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
										['status', '=', OrderStatus::UNPAID], | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
										['id', '>=', $min_id], | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
									]) | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
									->where('id', '>=', $min_id) | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
									->whereIn('status', $status_arr) | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
									->whereNotNull('timeout') | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
									->orderBy('id') | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
									->chunk(100, function ($order) use (&$min_id) { | 
				
			
			
		
	
	
		
			
				
					| 
						
						
						
							
								
							
						
					 | 
				
				 | 
				
					@ -66,6 +68,7 @@ class OrderTimeout extends Command | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
													DB::commit(); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
												} catch (\Exception $exception) { | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
													DB::rollBack(); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
													$this->line("订单ID {$v->id} 错误:" . $exception->getMessage()); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
												} | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
											} | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
											$min_id = $v->id; | 
				
			
			
		
	
	
		
			
				
					| 
						
							
								
							
						
						
						
					 | 
				
				 | 
				
					
  |