FundDto.php 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. <?php
  2. namespace App\Module\Fund\Dto;
  3. class FundDto
  4. {
  5. /**
  6. * @var int 用户ID
  7. */
  8. public int $userId;
  9. /**
  10. * @var int 资金类型ID
  11. */
  12. public int $fundId;
  13. /**
  14. * @var float 金额
  15. */
  16. public float $amount;
  17. /**
  18. * @var string|null 备注
  19. */
  20. public ?string $remark;
  21. /**
  22. * @var int|null 操作类型
  23. */
  24. public ?int $type;
  25. /**
  26. * @param array $data
  27. */
  28. public function __construct(array $data)
  29. {
  30. $this->userId = $data['user_id'] ?? 0;
  31. $this->fundId = $data['fund_id'] ?? 0;
  32. $this->amount = $data['amount'] ?? 0.00;
  33. $this->remark = $data['remark'] ?? null;
  34. $this->type = $data['type'] ?? null;
  35. }
  36. /**
  37. * 转换为数组
  38. */
  39. public function toArray(): array
  40. {
  41. return [
  42. 'user_id' => $this->userId,
  43. 'fund_id' => $this->fundId,
  44. 'amount' => $this->amount,
  45. 'remark' => $this->remark,
  46. 'type' => $this->type,
  47. ];
  48. }
  49. }