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.
38 lines
794 B
38 lines
794 B
<?php
|
|
|
|
namespace App\Listeners;
|
|
|
|
use App\Events\DepositUpdate;
|
|
use App\Models\DepositLog;
|
|
use App\Traits\StatementTraits;
|
|
|
|
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'
|
|
);
|
|
}
|
|
}
|