TransferOrderCreated.php 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. <?php
  2. namespace App\Module\Transfer\Events;
  3. use App\Module\Transfer\Models\TransferOrder;
  4. use Illuminate\Broadcasting\InteractsWithSockets;
  5. use Illuminate\Foundation\Events\Dispatchable;
  6. use Illuminate\Queue\SerializesModels;
  7. /**
  8. * 划转订单创建事件
  9. */
  10. class TransferOrderCreated
  11. {
  12. use Dispatchable, InteractsWithSockets, SerializesModels;
  13. public TransferOrder $order;
  14. public array $context;
  15. /**
  16. * 创建事件实例
  17. */
  18. public function __construct(TransferOrder $order, array $context = [])
  19. {
  20. $this->order = $order;
  21. $this->context = $context;
  22. }
  23. /**
  24. * 获取订单信息
  25. */
  26. public function getOrder(): TransferOrder
  27. {
  28. return $this->order;
  29. }
  30. /**
  31. * 获取上下文信息
  32. */
  33. public function getContext(): array
  34. {
  35. return $this->context;
  36. }
  37. /**
  38. * 判断是否为转入订单
  39. */
  40. public function isTransferIn(): bool
  41. {
  42. return $this->order->isTransferIn();
  43. }
  44. /**
  45. * 判断是否为转出订单
  46. */
  47. public function isTransferOut(): bool
  48. {
  49. return $this->order->isTransferOut();
  50. }
  51. /**
  52. * 获取事件数据
  53. */
  54. public function toArray(): array
  55. {
  56. return [
  57. 'order_id' => $this->order->id,
  58. 'transfer_app_id' => $this->order->transfer_app_id,
  59. 'user_id' => $this->order->user_id,
  60. 'type' => $this->order->type->value,
  61. 'amount' => $this->order->amount,
  62. 'out_amount' => $this->order->out_amount,
  63. 'status' => $this->order->status->value,
  64. 'created_at' => $this->order->created_at->toDateTimeString(),
  65. 'context' => $this->context,
  66. ];
  67. }
  68. }