SharedProsperityRecommendConfigRepository.php 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. <?php
  2. namespace app\common\repositories\shared;
  3. use app\common\dao\shared\SharedProsperityRecommendConfigDao;
  4. use app\common\repositories\BaseRepository;
  5. use app\entity\data\shared\SharedProsperityRecommendConfigEntity;
  6. class SharedProsperityRecommendConfigRepository extends BaseRepository
  7. {
  8. protected $dao;
  9. /**
  10. * SharedProsperityUserRepository constructor.
  11. * @param SharedProsperityRecommendConfigDao $dao
  12. */
  13. public function __construct(SharedProsperityRecommendConfigDao $dao)
  14. {
  15. $this->dao = $dao;
  16. }
  17. public function create($data)
  18. {
  19. return $this->dao->create($data);
  20. }
  21. /**
  22. * @param SharedProsperityRecommendConfigEntity $sharedProsperityRecommendConfigEntity
  23. * @return SharedProsperityRecommendConfigEntity
  24. */
  25. public function createByEntity(SharedProsperityRecommendConfigEntity $sharedProsperityRecommendConfigEntity): SharedProsperityRecommendConfigEntity
  26. {
  27. $result = $this->create($sharedProsperityRecommendConfigEntity->toUnderlineArray())->toArray();
  28. /** @var SharedProsperityRecommendConfigEntity $entity */
  29. $entity = SharedProsperityRecommendConfigEntity::newInstance($result);
  30. return $entity;
  31. }
  32. /**
  33. * @return SharedProsperityRecommendConfigEntity[]
  34. * @author 史晨
  35. * @date 2026/2/5 14:12
  36. */
  37. public function getList(): array
  38. {
  39. return $this->dao->getConfigList();
  40. }
  41. /**
  42. * @param $id
  43. * @return array
  44. * @author 史晨
  45. * @date 2026/2/5 14:12
  46. */
  47. public function getDetail($id)
  48. {
  49. return $this->dao->getDetailById($id);
  50. }
  51. /**
  52. * @param $params
  53. * @return bool
  54. * @author 史晨
  55. * @date 2026/2/5 14:12
  56. */
  57. public function update($params)
  58. {
  59. $id = $params['id'];
  60. unset($params['id']);
  61. if (!is_numeric($params['consume']) || $params['consume'] == 0) {
  62. $params['consume'] = null;
  63. }
  64. $this->dao->update($id, $params);
  65. return true;
  66. }
  67. /**
  68. * @param int $level
  69. * @return SharedProsperityRecommendConfigEntity
  70. */
  71. public function getSharedProsperityRecommendConfigEntityByLevel(int $level): SharedProsperityRecommendConfigEntity
  72. {
  73. $entityList = $this->getSharedProsperityRecommendConfigEntityListByLevelList([$level]);
  74. $entity = array_shift($entityList);
  75. if ($entity instanceof SharedProsperityRecommendConfigEntity) {
  76. return $entity;
  77. } else {
  78. /** @var SharedProsperityRecommendConfigEntity */
  79. return SharedProsperityRecommendConfigEntity::newInstance();
  80. }
  81. }
  82. /**
  83. * @param array $levelList
  84. * @return SharedProsperityRecommendConfigEntity[]
  85. */
  86. public function getSharedProsperityRecommendConfigEntityListByLevelList(array $levelList): array
  87. {
  88. return $this->dao->getSharedProsperityRecommendConfigEntityListByLevelList($levelList);
  89. }
  90. /**
  91. * 获取 最大 推荐奖励占比
  92. * @return SharedProsperityRecommendConfigEntity
  93. */
  94. public function getSharedProsperityRecommendConfigEntityByMaxRewardRatio(): SharedProsperityRecommendConfigEntity
  95. {
  96. return $this->dao->getSharedProsperityRecommendConfigEntityByMaxRewardRatio();
  97. }
  98. }