TradeResultDto.php 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. <?php
  2. namespace App\Module\Point\Dto;
  3. use App\Module\Point\Enums\LOG_TYPE;
  4. /**
  5. * 积分交易结果DTO类
  6. *
  7. * 用于传输积分交易结果相关数据
  8. */
  9. class TradeResultDto
  10. {
  11. public int $user_id;
  12. public int $point_id;
  13. public int $amount;
  14. public LOG_TYPE $log_type;
  15. public string $operate_id;
  16. public string $remark;
  17. public bool $success;
  18. public function __construct(array $data = [])
  19. {
  20. $this->user_id = $data['user_id'] ?? 0;
  21. $this->point_id = $data['point_id'] ?? 0;
  22. $this->amount = $data['amount'] ?? 0;
  23. $this->log_type = $data['log_type'] ?? LOG_TYPE::TEST;
  24. $this->operate_id = $data['operate_id'] ?? '';
  25. $this->remark = $data['remark'] ?? '';
  26. $this->success = $data['success'] ?? false;
  27. }
  28. /**
  29. * 转换为数组
  30. *
  31. * @return array
  32. */
  33. public function toArray(): array
  34. {
  35. return [
  36. 'user_id' => $this->user_id,
  37. 'point_id' => $this->point_id,
  38. 'amount' => $this->amount,
  39. 'log_type' => $this->log_type->value,
  40. 'operate_id' => $this->operate_id,
  41. 'remark' => $this->remark,
  42. 'success' => $this->success,
  43. ];
  44. }
  45. }