SharedProsperityRecommendConfigRepository.php 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  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. if (!$this->dao->update($id, $params)) {
  65. return false;
  66. }
  67. return true;
  68. }
  69. /**
  70. * @param int $level
  71. * @return SharedProsperityRecommendConfigEntity
  72. */
  73. public function getSharedProsperityRecommendConfigEntityByLevel(int $level): SharedProsperityRecommendConfigEntity
  74. {
  75. $entityList = $this->getSharedProsperityRecommendConfigEntityListByLevelList([$level]);
  76. $entity = array_shift($entityList);
  77. if ($entity instanceof SharedProsperityRecommendConfigEntity) {
  78. return $entity;
  79. } else {
  80. /** @var SharedProsperityRecommendConfigEntity */
  81. return SharedProsperityRecommendConfigEntity::newInstance();
  82. }
  83. }
  84. /**
  85. * @param array $levelList
  86. * @return SharedProsperityRecommendConfigEntity[]
  87. */
  88. public function getSharedProsperityRecommendConfigEntityListByLevelList(array $levelList): array
  89. {
  90. return $this->dao->getSharedProsperityRecommendConfigEntityListByLevelList($levelList);
  91. }
  92. /**
  93. * 获取 最大 推荐奖励占比
  94. * @return SharedProsperityRecommendConfigEntity
  95. */
  96. public function getSharedProsperityRecommendConfigEntityByMaxRewardRatio(): SharedProsperityRecommendConfigEntity
  97. {
  98. return $this->dao->getSharedProsperityRecommendConfigEntityByMaxRewardRatio();
  99. }
  100. }