SharedProsperityRecommendConfigDao.php 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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(): 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)) {
  28. $entityList = array_map(function ($data) {
  29. return SharedProsperityRecommendConfigEntity::newInstance($data);
  30. }, $dataRes);
  31. }
  32. } catch (\Exception $e) {
  33. }
  34. return $entityList;
  35. }
  36. /**
  37. * @param $id
  38. * @return mixed
  39. * @author 史晨
  40. * @date 2026/2/5 14:43
  41. * 获取推荐配置详情
  42. */
  43. public function getDetailById($id)
  44. {
  45. /** @var SharedProsperityRecommendConfig $model */
  46. $model = $this->getModel();
  47. return $model::getDB()
  48. ->where(['id' => $id])
  49. ->find();
  50. }
  51. /**
  52. * @param array $levelList
  53. * @return SharedProsperityRecommendConfigEntity[]
  54. */
  55. public function getSharedProsperityRecommendConfigEntityListByLevelList(array $levelList): array
  56. {
  57. $entityList = [];
  58. try {
  59. /** @var SharedProsperityRecommendConfig $model */
  60. $model = $this->getModel();
  61. $dataRes = $model::getDB()
  62. ->whereIn('level', $levelList)
  63. ->select()
  64. ->toArray();
  65. if (!empty($dataRes)) {
  66. $entityList = array_map(function ($data) {
  67. return SharedProsperityRecommendConfigEntity::newInstance($data);
  68. }, $dataRes);
  69. }
  70. } catch (\Exception $e) {
  71. }
  72. return $entityList;
  73. }
  74. }