SharedProsperityRecommendConfigDao.php 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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 array
  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. }