SharedProsperityRecommendConfigRepository.php 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  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 array
  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 (!$this->dao->update($id, $params)) {
  62. return false;
  63. }
  64. return true;
  65. }
  66. /**
  67. * @param int $level
  68. * @return SharedProsperityRecommendConfigEntity
  69. */
  70. public function getSharedProsperityRecommendConfigEntityByLevel(int $level): SharedProsperityRecommendConfigEntity
  71. {
  72. $entityList = $this->getSharedProsperityRecommendConfigEntityListByLevelList([$level]);
  73. $entity = array_shift($entityList);
  74. if ($entity instanceof SharedProsperityRecommendConfigEntity) {
  75. return $entity;
  76. } else {
  77. /** @var SharedProsperityRecommendConfigEntity */
  78. return SharedProsperityRecommendConfigEntity::newInstance();
  79. }
  80. }
  81. /**
  82. * @param array $levelList
  83. * @return SharedProsperityRecommendConfigEntity[]
  84. */
  85. public function getSharedProsperityRecommendConfigEntityListByLevelList(array $levelList): array
  86. {
  87. return $this->dao->getSharedProsperityRecommendConfigEntityListByLevelList($levelList);
  88. }
  89. }