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

39 lines
830 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. use Illuminate\Support\Facades\Log;
  7. class SupplierEventSubscriber
  8. {
  9. public function onSupplierUpdated($event)
  10. {
  11. //处理流水事务
  12. $supplier = $event->supplier;
  13. //如果交易金有变动
  14. if ($supplier->isDirty('trade_balance')) {
  15. DepositLog::query()->create([
  16. 'price' => bcsub($supplier->trade_balance,$supplier->getOriginal('trade_balance')),
  17. 'type' => StatementTraits::$deposit[0],
  18. 'supplier_id' => $supplier->id
  19. ]);
  20. }
  21. }
  22. /**
  23. * 为订阅者注册监听器
  24. *
  25. * @param Illuminate\Events\Dispatcher $events
  26. */
  27. public function subscribe($events)
  28. {
  29. $events->listen(
  30. DepositUpdate::class,
  31. SupplierEventSubscriber::class . '@onSupplierUpdated'
  32. );
  33. }
  34. }