SharedProsperityGroupUserDao.php 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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 think\db\exception\DbException;
  7. class SharedProsperityGroupUserDao extends BaseDao
  8. {
  9. /**
  10. * @return BaseModel
  11. */
  12. protected function getModel(): string
  13. {
  14. return SharedProsperityGroupUser::class;
  15. }
  16. /**
  17. * 获取按团队分组的有效用户ID列表
  18. * @return array [group_id => [user_id1, user_id2, ...]]
  19. */
  20. public function getValidUsersGroupByGroup(): array
  21. {
  22. try {
  23. $rows = $this->getModel()::where('status', 1)
  24. ->field('group_id, user_id')
  25. ->select()
  26. ->toArray();
  27. $grouped = [];
  28. foreach ($rows as $row) {
  29. $grouped[$row['group_id']][] = $row['user_id'];
  30. }
  31. return $grouped;
  32. } catch (\Exception $e) {
  33. return [];
  34. }
  35. }
  36. /**
  37. * @param $groupId
  38. * @return array
  39. * @author 史晨
  40. * @date 2026/2/27 11:31
  41. * 获取团队用户(分页)
  42. */
  43. public function getUserByLevel($groupId)
  44. {
  45. try {
  46. return $this->getModel()::where('status', 1)
  47. ->where(['group_id' => $groupId])
  48. ->paginate(20)
  49. ->toArray();
  50. } catch (DbException $e) {
  51. return [];
  52. }
  53. }
  54. }