UrsTransferFeeConfigDto.php 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. <?php
  2. namespace App\Module\UrsPromotion\Dtos;
  3. use UCore\Dto\BaseDto;
  4. use App\Module\UrsPromotion\Models\UrsTransferFeeConfig;
  5. /**
  6. * URS转出手续费配置数据传输对象
  7. *
  8. * 用于在服务层返回URS转出手续费配置信息,避免直接暴露模型对象
  9. */
  10. class UrsTransferFeeConfigDto extends BaseDto
  11. {
  12. /**
  13. * @var int 配置ID
  14. */
  15. public int $id;
  16. /**
  17. * @var int 房屋等级
  18. */
  19. public int $houseLevel;
  20. /**
  21. * @var int 达人等级
  22. */
  23. public int $talentLevel;
  24. /**
  25. * @var string 转账类型
  26. */
  27. public string $transferType;
  28. /**
  29. * @var float 手续费率
  30. */
  31. public float $feeRate;
  32. /**
  33. * @var string 配置描述
  34. */
  35. public string $description;
  36. /**
  37. * @var int 优先级
  38. */
  39. public int $priority;
  40. /**
  41. * @var int 状态
  42. */
  43. public int $status;
  44. /**
  45. * @var string 创建时间
  46. */
  47. public string $createdAt;
  48. /**
  49. * @var string 更新时间
  50. */
  51. public string $updatedAt;
  52. /**
  53. * 从模型创建DTO
  54. *
  55. * @param UrsTransferFeeConfig $model URS转出手续费配置模型
  56. * @return self
  57. */
  58. public static function fromModel(UrsTransferFeeConfig $model): self
  59. {
  60. $dto = new self();
  61. $dto->id = $model->id;
  62. $dto->houseLevel = $model->house_level;
  63. $dto->talentLevel = $model->talent_level;
  64. $dto->transferType = $model->transfer_type;
  65. $dto->feeRate = (float)$model->fee_rate;
  66. $dto->description = $model->description;
  67. $dto->priority = $model->priority;
  68. $dto->status = $model->status;
  69. $dto->createdAt = $model->created_at->format('Y-m-d H:i:s');
  70. $dto->updatedAt = $model->updated_at->format('Y-m-d H:i:s');
  71. return $dto;
  72. }
  73. /**
  74. * 获取手续费率百分比显示
  75. *
  76. * @return string
  77. */
  78. public function getFeeRatePercentage(): string
  79. {
  80. return number_format($this->feeRate * 100, 2) . '%';
  81. }
  82. /**
  83. * 获取配置的匹配条件描述
  84. *
  85. * @return string
  86. */
  87. public function getMatchConditionDescription(): string
  88. {
  89. $conditions = [];
  90. // 转账类型
  91. $typeMap = [
  92. 'in' => '转入',
  93. 'out' => '转出',
  94. ];
  95. $conditions[] = $typeMap[$this->transferType] ?? '未知';
  96. if ($this->houseLevel > 0) {
  97. $conditions[] = "房屋等级{$this->houseLevel}级";
  98. } else {
  99. $conditions[] = "所有房屋等级";
  100. }
  101. if ($this->talentLevel > 0) {
  102. $conditions[] = "达人等级{$this->talentLevel}级";
  103. } else {
  104. $conditions[] = "所有达人等级";
  105. }
  106. return implode(' + ', $conditions);
  107. }
  108. /**
  109. * 检查配置是否启用
  110. *
  111. * @return bool
  112. */
  113. public function isEnabled(): bool
  114. {
  115. return $this->status === UrsTransferFeeConfig::STATUS_ENABLED;
  116. }
  117. /**
  118. * 检查是否匹配指定的房屋等级和达人等级
  119. *
  120. * @param int $houseLevel 房屋等级
  121. * @param int $talentLevel 达人等级
  122. * @return bool
  123. */
  124. public function matches(int $houseLevel, int $talentLevel): bool
  125. {
  126. $matchesHouse = $this->houseLevel === 0 || $this->houseLevel === $houseLevel;
  127. $matchesTalent = $this->talentLevel === 0 || $this->talentLevel === $talentLevel;
  128. return $matchesHouse && $matchesTalent;
  129. }
  130. }