SharedProsperityRecommendConfigDao.php 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. <?php
  2. namespace app\common\dao\shared;
  3. use app\common\dao\BaseDao;
  4. use app\common\model\shared\SharedProsperityRecommendConfig;
  5. use app\entity\data\shared\SharedProsperityRecommendConfigEntity;
  6. class SharedProsperityRecommendConfigDao extends BaseDao
  7. {
  8. protected function getModel(): string
  9. {
  10. return SharedProsperityRecommendConfig::class;
  11. }
  12. /**
  13. * @return SharedProsperityRecommendConfigEntity[]
  14. * @author 史晨
  15. * @date 2026/2/5 14:43
  16. * 获取推荐配置
  17. */
  18. public function getConfigList($idEntity = true): array
  19. {
  20. $entityList = [];
  21. try {
  22. /** @var SharedProsperityRecommendConfig $model */
  23. $model = $this->getModel();
  24. $dataRes = $model::getDB()
  25. ->select()
  26. ->toArray();
  27. if (!empty($dataRes) && $idEntity) {
  28. $entityList = array_map(function ($data) {
  29. return SharedProsperityRecommendConfigEntity::newInstance($data);
  30. }, $dataRes);
  31. }else{
  32. $entityList = $dataRes;
  33. }
  34. } catch (\Exception $e) {
  35. }
  36. return $entityList;
  37. }
  38. /**
  39. * @param $id
  40. * @return mixed
  41. * @author 史晨
  42. * @date 2026/2/5 14:43
  43. * 获取推荐配置详情
  44. */
  45. public function getDetailById($id)
  46. {
  47. /** @var SharedProsperityRecommendConfig $model */
  48. $model = $this->getModel();
  49. return $model::getDB()
  50. ->where(['id' => $id])
  51. ->find();
  52. }
  53. /**
  54. * @param array $levelList
  55. * @return SharedProsperityRecommendConfigEntity[]
  56. */
  57. public function getSharedProsperityRecommendConfigEntityListByLevelList(array $levelList): array
  58. {
  59. $entityList = [];
  60. try {
  61. /** @var SharedProsperityRecommendConfig $model */
  62. $model = $this->getModel();
  63. $dataRes = $model::getDB()
  64. ->whereIn('level', $levelList)
  65. ->select()
  66. ->toArray();
  67. if (!empty($dataRes)) {
  68. $entityList = array_map(function ($data) {
  69. return SharedProsperityRecommendConfigEntity::newInstance($data);
  70. }, $dataRes);
  71. }
  72. } catch (\Exception $e) {
  73. }
  74. return $entityList;
  75. }
  76. /**
  77. * 获取 配置实体 根据 最大的 直推奖比例
  78. * @return SharedProsperityRecommendConfigEntity
  79. */
  80. public function getSharedProsperityRecommendConfigEntityByMaxRewardRatio(): SharedProsperityRecommendConfigEntity
  81. {
  82. $entity = SharedProsperityRecommendConfigEntity::newInstance();
  83. try {
  84. /** @var SharedProsperityRecommendConfig $model */
  85. $model = $this->getModel();
  86. $dataRes = $model::getDB()
  87. ->order('reward_ratio', 'desc')
  88. ->limit(1)
  89. ->select()
  90. ->toArray();
  91. if (!empty($dataRes)) {
  92. $entity = SharedProsperityRecommendConfigEntity::newInstance($dataRes[0]);
  93. }
  94. } catch (\Exception $e) {
  95. }
  96. return $entity;
  97. }
  98. }