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.
55 lines
1.3 KiB
55 lines
1.3 KiB
<?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('deposit_normal')) {
|
|
DepositLog::query()->create([
|
|
'price' => bcsub($supplier->deposit_normal,$supplier->getOriginal('deposit_normal')),
|
|
'type' => StatementTraits::$deposit[0],
|
|
'supplier_id' => $supplier->id
|
|
]);
|
|
}
|
|
|
|
if ($supplier->isDirty('deposit_frozen')) {
|
|
DepositLog::query()->create([
|
|
'price' => bcsub($supplier->deposit_frozen,$supplier->getOriginal('deposit_frozen')),
|
|
'type' => StatementTraits::$deposit[1],
|
|
'supplier_id' => $supplier->id
|
|
]);
|
|
}
|
|
|
|
if ($supplier->isDirty('deposit_used')) {
|
|
DepositLog::query()->create([
|
|
'price' => bcsub($supplier->deposit_used,$supplier->getOriginal('deposit_used')),
|
|
'type' => StatementTraits::$deposit[2],
|
|
'supplier_id' => $supplier->id
|
|
]);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 为订阅者注册监听器
|
|
*
|
|
* @param Illuminate\Events\Dispatcher $events
|
|
*/
|
|
public function subscribe($events)
|
|
{
|
|
$events->listen(
|
|
DepositUpdate::class,
|
|
SupplierEventSubscriber::class . '@onSupplierUpdated'
|
|
);
|
|
}
|
|
}
|