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.
		
		
		
		
		
			
		
			
				
					
					
						
							39 lines
						
					
					
						
							830 B
						
					
					
				
			
		
		
		
			
			
			
				
					
				
				
					
				
			
		
		
	
	
							39 lines
						
					
					
						
							830 B
						
					
					
				
								<?php
							 | 
						|
								
							 | 
						|
								namespace App\Listeners;
							 | 
						|
								
							 | 
						|
								use App\Events\DepositUpdate;
							 | 
						|
								use App\Models\DepositLog;
							 | 
						|
								use App\Traits\StatementTraits;
							 | 
						|
								use Illuminate\Support\Facades\Log;
							 | 
						|
								
							 | 
						|
								class SupplierEventSubscriber
							 | 
						|
								{
							 | 
						|
								    public function onSupplierUpdated($event)
							 | 
						|
									{
							 | 
						|
										//处理流水事务
							 | 
						|
										$supplier = $event->supplier;
							 | 
						|
								
							 | 
						|
										//如果交易金有变动
							 | 
						|
										if ($supplier->isDirty('trade_balance')) {
							 | 
						|
											DepositLog::query()->create([
							 | 
						|
												'price' => bcsub($supplier->trade_balance,$supplier->getOriginal('trade_balance')),
							 | 
						|
												'type' => StatementTraits::$deposit[0],
							 | 
						|
												'supplier_id' => $supplier->id
							 | 
						|
											]);
							 | 
						|
										}
							 | 
						|
									}
							 | 
						|
								
							 | 
						|
									/**
							 | 
						|
									 * 为订阅者注册监听器
							 | 
						|
									 *
							 | 
						|
									 * @param  Illuminate\Events\Dispatcher $events
							 | 
						|
									 */
							 | 
						|
									public function subscribe($events)
							 | 
						|
									{
							 | 
						|
										$events->listen(
							 | 
						|
											DepositUpdate::class,
							 | 
						|
											SupplierEventSubscriber::class . '@onSupplierUpdated'
							 | 
						|
										);
							 | 
						|
									}
							 | 
						|
								}
							 |