海南旅游SAAS
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

4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
  1. <?php
  2. namespace App\Listeners;
  3. use App\Events\DepositUpdate;
  4. use App\Models\DepositLog;
  5. use App\Traits\StatementTraits;
  6. class SupplierEventSubscriber
  7. {
  8. public function onSupplierUpdated($event)
  9. {
  10. //处理流水事务
  11. $supplier = $event->supplier;
  12. //如果交易金有变动
  13. if ($supplier->isDirty('trade_balance')) {
  14. DepositLog::query()->create([
  15. 'price' => bcsub($supplier->trade_balance,$supplier->getOriginal('trade_balance')),
  16. 'type' => StatementTraits::$deposit[0],
  17. 'supplier_id' => $supplier->id
  18. ]);
  19. }
  20. }
  21. /**
  22. * 为订阅者注册监听器
  23. *
  24. * @param Illuminate\Events\Dispatcher $events
  25. */
  26. public function subscribe($events)
  27. {
  28. $events->listen(
  29. DepositUpdate::class,
  30. SupplierEventSubscriber::class . '@onSupplierUpdated'
  31. );
  32. }
  33. }