SharedProsperityGroupUserDao.php 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. <?php
  2. namespace app\common\dao\shared;
  3. use app\common\dao\BaseDao;
  4. use app\common\model\BaseModel;
  5. use app\common\model\shared\SharedProsperityGroupUser;
  6. use app\entity\data\shared\SharedProsperityGroupUserEntity;
  7. use think\db\exception\DbException;
  8. class SharedProsperityGroupUserDao extends BaseDao
  9. {
  10. /**
  11. * @return BaseModel
  12. */
  13. protected function getModel(): string
  14. {
  15. return SharedProsperityGroupUser::class;
  16. }
  17. /**
  18. * 获取按团队分组的有效用户ID列表
  19. * @return array [group_id => [user_id1, user_id2, ...]]
  20. */
  21. public function getValidUsersGroupByGroup(): array
  22. {
  23. try {
  24. $rows = $this->getModel()::where('status', 1)
  25. ->field('group_id, user_id')
  26. ->select()
  27. ->toArray();
  28. $grouped = [];
  29. foreach ($rows as $row) {
  30. $grouped[$row['group_id']][] = $row['user_id'];
  31. }
  32. return $grouped;
  33. } catch (\Exception $e) {
  34. return [];
  35. }
  36. }
  37. /**
  38. * @param $groupId
  39. * @return array
  40. * @author 史晨
  41. * @date 2026/2/27 11:31
  42. * 获取团队用户(分页)
  43. */
  44. public function getUserByLevel($groupId)
  45. {
  46. try {
  47. return $this->getModel()::where('status', 1)
  48. ->where(['group_id' => $groupId])
  49. ->paginate(20)
  50. ->toArray();
  51. } catch (DbException $e) {
  52. return [];
  53. }
  54. }
  55. /**
  56. * @param array $idList
  57. * @return SharedProsperityGroupUserEntity[]
  58. */
  59. public function getSharedProsperityGroupUserEntityListByIdList(array $idList): array
  60. {
  61. $entityList = [];
  62. try {
  63. /** @var SharedProsperityGroupUser $model */
  64. $model = $this->getModel();
  65. $dataRes = $model::getDB()
  66. ->whereIn('id', $idList)
  67. ->select()
  68. ->toArray();
  69. if (!empty($dataRes)) {
  70. $entityList = array_map(function ($data) {
  71. return SharedProsperityGroupUserEntity::newInstance($data);
  72. }, $dataRes);
  73. }
  74. } catch (\Exception $e) {
  75. }
  76. return $entityList;
  77. }
  78. /**
  79. * @param array $userIdList
  80. * @return SharedProsperityGroupUserEntity[]
  81. */
  82. public function getSharedProsperityGroupUserEntityListByUserIdList(array $userIdList): array
  83. {
  84. $entityList = [];
  85. try {
  86. /** @var SharedProsperityGroupUser $model */
  87. $model = $this->getModel();
  88. $dataRes = $model::getDB()
  89. ->whereIn('user_id', $userIdList)
  90. ->select()
  91. ->toArray();
  92. if (!empty($dataRes)) {
  93. $entityList = array_map(function ($data) {
  94. return SharedProsperityGroupUserEntity::newInstance($data);
  95. }, $dataRes);
  96. }
  97. } catch (\Exception $e) {
  98. }
  99. return $entityList;
  100. }
  101. }