| 
						
						
							
								
							
						
						
					 | 
				
				 | 
				
					@ -3,8 +3,11 @@ | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					namespace App\Console\Commands; | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					use App\Common\OrderStatus; | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					use App\Models\AgentProduct; | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					use App\Models\AgentProductSpec; | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					use App\Models\Order; | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					use App\Models\Product; | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					use App\Models\ProductSpec; | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					use Illuminate\Console\Command; | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					use Illuminate\Support\Facades\DB; | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					
 | 
				
			
			
		
	
	
		
			
				
					| 
						
							
								
							
						
						
							
								
							
						
						
					 | 
				
				 | 
				
					@ -52,7 +55,7 @@ class OrderTimeout extends Command | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
							$min_id = 0; | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					    	while (true) { | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
								Order::query() | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
								Order::with('orderProductItem') | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					//				->where('id', '>=', $min_id)
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
									->whereIn('status', $status_arr) | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
									->whereNotNull('timeout') | 
				
			
			
		
	
	
		
			
				
					| 
						
						
						
							
								
							
						
					 | 
				
				 | 
				
					@ -66,9 +69,24 @@ class OrderTimeout extends Command | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
													$v->status = OrderStatus::CANCEL; | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
													$v->save(); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
													//加回库存
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
													//供应商产品加库存
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
													Product::whereIn('id', explode(',', $v->product_ids))->increment('stock', $v->num); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
													//代理商产品加库存
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
													AgentProduct::where('id', $v->agent_product_id)->increment('stock', $v->num); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
													if (!$v->orderProductItem->isEmpty()) { | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
														$item = $v->orderProductItem->toArray(); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
														//供应商产品规格加库存
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
														$ids = array_column($item, 'product_spec_id'); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
														ProductSpec::whereIn('id', $ids)->increment('stock', $v->num); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
														//代理商产品规格加库存
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
														$ids = array_column($item, 'agent_product_spec_id'); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
														AgentProductSpec::whereIn('id', $ids)->increment('stock', $v->num); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
													} | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
													DB::commit(); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
													$min_id = $v->id; | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
												} catch (\Exception $exception) { | 
				
			
			
		
	
	
		
			
				
					| 
						
						
						
							
								
							
						
					 | 
				
				 | 
				
					@ -82,7 +100,7 @@ class OrderTimeout extends Command | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
								//TODO 产品规格表加库存
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
								$this->line('[' . date('Y-m-d H:i:s') . "] ID游标:$min_id ,等待下一个任务"); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
								sleep(3); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
								sleep(5); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
							} | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
							return 0; | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					    } | 
				
			
			
		
	
	
		
			
				
					| 
						
						
						
					 | 
				
				 | 
				
					
  |