| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153 |
- <?php
- namespace App\Module\UrsPromotion\Dtos;
- use UCore\Dto\BaseDto;
- use App\Module\UrsPromotion\Models\UrsTransferFeeConfig;
- /**
- * URS转出手续费配置数据传输对象
- *
- * 用于在服务层返回URS转出手续费配置信息,避免直接暴露模型对象
- */
- class UrsTransferFeeConfigDto extends BaseDto
- {
- /**
- * @var int 配置ID
- */
- public int $id;
- /**
- * @var int 房屋等级
- */
- public int $houseLevel;
- /**
- * @var int 达人等级
- */
- public int $talentLevel;
- /**
- * @var string 转账类型
- */
- public string $transferType;
- /**
- * @var float 手续费率
- */
- public float $feeRate;
- /**
- * @var string 配置描述
- */
- public string $description;
- /**
- * @var int 优先级
- */
- public int $priority;
- /**
- * @var int 状态
- */
- public int $status;
- /**
- * @var string 创建时间
- */
- public string $createdAt;
- /**
- * @var string 更新时间
- */
- public string $updatedAt;
- /**
- * 从模型创建DTO
- *
- * @param UrsTransferFeeConfig $model URS转出手续费配置模型
- * @return self
- */
- public static function fromModel(UrsTransferFeeConfig $model): self
- {
- $dto = new self();
- $dto->id = $model->id;
- $dto->houseLevel = $model->house_level;
- $dto->talentLevel = $model->talent_level;
- $dto->transferType = $model->transfer_type;
- $dto->feeRate = (float)$model->fee_rate;
- $dto->description = $model->description;
- $dto->priority = $model->priority;
- $dto->status = $model->status;
- $dto->createdAt = $model->created_at->format('Y-m-d H:i:s');
- $dto->updatedAt = $model->updated_at->format('Y-m-d H:i:s');
- return $dto;
- }
- /**
- * 获取手续费率百分比显示
- *
- * @return string
- */
- public function getFeeRatePercentage(): string
- {
- return number_format($this->feeRate * 100, 2) . '%';
- }
- /**
- * 获取配置的匹配条件描述
- *
- * @return string
- */
- public function getMatchConditionDescription(): string
- {
- $conditions = [];
- // 转账类型
- $typeMap = [
- 'in' => '转入',
- 'out' => '转出',
- ];
- $conditions[] = $typeMap[$this->transferType] ?? '未知';
- if ($this->houseLevel > 0) {
- $conditions[] = "房屋等级{$this->houseLevel}级";
- } else {
- $conditions[] = "所有房屋等级";
- }
- if ($this->talentLevel > 0) {
- $conditions[] = "达人等级{$this->talentLevel}级";
- } else {
- $conditions[] = "所有达人等级";
- }
- return implode(' + ', $conditions);
- }
- /**
- * 检查配置是否启用
- *
- * @return bool
- */
- public function isEnabled(): bool
- {
- return $this->status === UrsTransferFeeConfig::STATUS_ENABLED;
- }
- /**
- * 检查是否匹配指定的房屋等级和达人等级
- *
- * @param int $houseLevel 房屋等级
- * @param int $talentLevel 达人等级
- * @return bool
- */
- public function matches(int $houseLevel, int $talentLevel): bool
- {
- $matchesHouse = $this->houseLevel === 0 || $this->houseLevel === $houseLevel;
- $matchesTalent = $this->talentLevel === 0 || $this->talentLevel === $talentLevel;
-
- return $matchesHouse && $matchesTalent;
- }
- }
|