| 
					
					
						
							
						
					
					
				 | 
				@ -11,6 +11,7 @@ use Illuminate\Contracts\Queue\ShouldQueue; | 
			
		
		
	
		
			
				 | 
				 | 
				use Illuminate\Foundation\Bus\Dispatchable; | 
				 | 
				 | 
				use Illuminate\Foundation\Bus\Dispatchable; | 
			
		
		
	
		
			
				 | 
				 | 
				use Illuminate\Queue\InteractsWithQueue; | 
				 | 
				 | 
				use Illuminate\Queue\InteractsWithQueue; | 
			
		
		
	
		
			
				 | 
				 | 
				use Illuminate\Queue\SerializesModels; | 
				 | 
				 | 
				use Illuminate\Queue\SerializesModels; | 
			
		
		
	
		
			
				 | 
				 | 
				 | 
				 | 
				 | 
				use Illuminate\Support\Facades\DB; | 
			
		
		
	
		
			
				 | 
				 | 
				
 | 
				 | 
				 | 
				
 | 
			
		
		
	
		
			
				 | 
				 | 
				class ProductSpecSync implements ShouldQueue | 
				 | 
				 | 
				class ProductSpecSync implements ShouldQueue | 
			
		
		
	
		
			
				 | 
				 | 
				{ | 
				 | 
				 | 
				{ | 
			
		
		
	
	
		
			
				| 
					
						
							
						
					
					
						
							
						
					
					
				 | 
				@ -65,7 +66,11 @@ class ProductSpecSync implements ShouldQueue | 
			
		
		
	
		
			
				 | 
				 | 
								foreach ($product_specs as $spec) { | 
				 | 
				 | 
								foreach ($product_specs as $spec) { | 
			
		
		
	
		
			
				 | 
				 | 
									AgentProductSpec::query() | 
				 | 
				 | 
									AgentProductSpec::query() | 
			
		
		
	
		
			
				 | 
				 | 
										->where([['product_spec_id', '=', $spec->id], ['price', '<', $spec->price]]) | 
				 | 
				 | 
										->where([['product_spec_id', '=', $spec->id], ['price', '<', $spec->price]]) | 
			
		
		
	
		
			
				 | 
				 | 
										->update(['price' => $spec->price]); | 
				 | 
				 | 
				 | 
			
		
		
	
		
			
				 | 
				 | 
				 | 
				 | 
				 | 
										->update([ | 
			
		
		
	
		
			
				 | 
				 | 
				 | 
				 | 
				 | 
											'price' => $spec->price, | 
			
		
		
	
		
			
				 | 
				 | 
				 | 
				 | 
				 | 
											'stock' => DB::raw("IF(`stock` > {$spec->stock}, {$spec->stock}, `stock`)"), | 
			
		
		
	
		
			
				 | 
				 | 
				 | 
				 | 
				 | 
											'original_price' => DB::raw("IF(`original_price` < {$spec->original_price}, {$spec->original_price}, `original_price`)"), | 
			
		
		
	
		
			
				 | 
				 | 
				 | 
				 | 
				 | 
										]); | 
			
		
		
	
		
			
				 | 
				 | 
								} | 
				 | 
				 | 
								} | 
			
		
		
	
		
			
				 | 
				 | 
				
 | 
				 | 
				 | 
				
 | 
			
		
		
	
		
			
				 | 
				 | 
								//供应商新增,但代理商还没有的规格,同步给代理商
 | 
				 | 
				 | 
								//供应商新增,但代理商还没有的规格,同步给代理商
 | 
			
		
		
	
	
		
			
				| 
					
					
					
						
							
						
					
				 | 
				@ -91,6 +96,18 @@ class ProductSpecSync implements ShouldQueue | 
			
		
		
	
		
			
				 | 
				 | 
												]; | 
				 | 
				 | 
												]; | 
			
		
		
	
		
			
				 | 
				 | 
											}, $agent_no_spec_ids) | 
				 | 
				 | 
											}, $agent_no_spec_ids) | 
			
		
		
	
		
			
				 | 
				 | 
										); | 
				 | 
				 | 
										); | 
			
		
		
	
		
			
				 | 
				 | 
				 | 
				 | 
				 | 
				
 | 
			
		
		
	
		
			
				 | 
				 | 
				 | 
				 | 
				 | 
									//设置产品的销售价(列表页显示的价格)
 | 
			
		
		
	
		
			
				 | 
				 | 
				 | 
				 | 
				 | 
									$psArr = $product_specs->toArray(); | 
			
		
		
	
		
			
				 | 
				 | 
				 | 
				 | 
				 | 
									$ap->price = min(array_column($psArr, 'price')); | 
			
		
		
	
		
			
				 | 
				 | 
				 | 
				 | 
				 | 
									$ap->original_price = min(array_column($psArr, 'original_price')); | 
			
		
		
	
		
			
				 | 
				 | 
				 | 
				 | 
				 | 
				
 | 
			
		
		
	
		
			
				 | 
				 | 
				 | 
				 | 
				 | 
									//如果代理商库存大于供应商库存,将代理商库存修改为供应商的库存
 | 
			
		
		
	
		
			
				 | 
				 | 
				 | 
				 | 
				 | 
									$pStock = array_sum(array_column($psArr, 'stock')); | 
			
		
		
	
		
			
				 | 
				 | 
				 | 
				 | 
				 | 
									if ($ap->stock > $pStock) { | 
			
		
		
	
		
			
				 | 
				 | 
				 | 
				 | 
				 | 
										$ap->stock = $pStock; | 
			
		
		
	
		
			
				 | 
				 | 
				 | 
				 | 
				 | 
									} | 
			
		
		
	
		
			
				 | 
				 | 
				 | 
				 | 
				 | 
									$ap->save(); | 
			
		
		
	
		
			
				 | 
				 | 
								} | 
				 | 
				 | 
								} | 
			
		
		
	
		
			
				 | 
				 | 
							}); | 
				 | 
				 | 
							}); | 
			
		
		
	
		
			
				 | 
				 | 
				    } | 
				 | 
				 | 
				    } | 
			
		
		
	
	
		
			
				| 
					
					
					
				 | 
				
  |