| 
						
						
							
								
							
						
						
					 | 
				
				 | 
				
					@ -89,12 +89,20 @@ class AgentProduct extends BaseModel | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
						} | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
						//列表查询统一查询条件
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
						public function scopeList($query, $agent_id) | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
						public static function list($agent_id) | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
						{ | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
							return static::withoutGlobalScope('orderById') | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
								->whereDoesntHave('agentProductItem', function ($query) { | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
									return $query->whereHas('product', function ($query) { | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
									return $query->where('status', ProductStatus::ON_SALE)->where('stock', '>', 0); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
										return $query->where('stock', '<=', 0)->orWhere('status', '<>', ProductStatus::ON_SALE); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
									}); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
								}) | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
								->where(['agent_id' => $agent_id, 'status' => ProductStatus::ON_SALE])->where('stock', '>', 0) | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
								->select('id', 'sale', 'product_id', 'price', 'original_price', 'title', 'pictures'); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
						} | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
						public function agentProductItem() | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
						{ | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
							return $this->hasOne(AgentProductItem::class); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
						} | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					} |