UrsUserTalentDto.php 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. <?php
  2. namespace App\Module\UrsPromotion\Dtos;
  3. use App\Module\UrsPromotion\Models\UrsUserTalent;
  4. use UCore\Dto\BaseDto;
  5. /**
  6. * URS用户达人等级数据传输对象
  7. *
  8. * 用于在服务层返回URS用户达人等级信息,避免直接暴露模型对象
  9. */
  10. class UrsUserTalentDto extends BaseDto
  11. {
  12. /**
  13. * @var int 达人等级ID
  14. */
  15. public int $id;
  16. /**
  17. * @var int URS用户ID
  18. */
  19. public int $ursUserId;
  20. /**
  21. * @var int 达人等级
  22. */
  23. public int $talentLevel;
  24. /**
  25. * @var string 等级名称
  26. */
  27. public string $talentName;
  28. /**
  29. * @var int 直推人数
  30. */
  31. public int $directCount;
  32. /**
  33. * @var int 间推人数
  34. */
  35. public int $indirectCount;
  36. /**
  37. * @var int 三推人数
  38. */
  39. public int $thirdCount;
  40. /**
  41. * @var int 团队总人数
  42. */
  43. public int $promotionCount;
  44. /**
  45. * @var string|null 最后等级更新时间
  46. */
  47. public ?string $lastLevelUpdateTime;
  48. /**
  49. * @var string 创建时间
  50. */
  51. public string $createdAt;
  52. /**
  53. * @var string 更新时间
  54. */
  55. public string $updatedAt;
  56. /**
  57. * @var array|null 当前等级配置
  58. */
  59. public ?array $currentConfig = null;
  60. /**
  61. * @var array|null 下一等级配置
  62. */
  63. public ?array $nextConfig = null;
  64. /**
  65. * 从模型创建DTO
  66. *
  67. * @param UrsUserTalent $model URS用户达人等级模型
  68. * @param array|null $currentConfig 当前等级配置(可选)
  69. * @param array|null $nextConfig 下一等级配置(可选)
  70. * @return self
  71. */
  72. public static function fromModel(UrsUserTalent $model, ?array $currentConfig = null, ?array $nextConfig = null): self
  73. {
  74. $dto = new self();
  75. $dto->id = $model->id;
  76. $dto->ursUserId = $model->user_id;
  77. $dto->talentLevel = $model->talent_level;
  78. $dto->talentName = $currentConfig['name'] ?? '普通用户';
  79. $dto->directCount = $model->direct_count;
  80. $dto->indirectCount = $model->indirect_count;
  81. $dto->thirdCount = $model->third_count;
  82. $dto->promotionCount = $model->promotion_count;
  83. $dto->lastLevelUpdateTime = $model->last_level_update_time ? $model->last_level_update_time->toDateTimeString() : null;
  84. $dto->createdAt = $model->created_at ? $model->created_at->toDateTimeString() : '';
  85. $dto->updatedAt = $model->updated_at ? $model->updated_at->toDateTimeString() : '';
  86. $dto->currentConfig = $currentConfig;
  87. $dto->nextConfig = $nextConfig;
  88. return $dto;
  89. }
  90. }