UserGroup.php 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. <?php
  2. /**
  3. * 用户群组相关
  4. * @author solu
  5. */
  6. class UserGroup extends Model {
  7. protected $tableName = 'user_group';
  8. protected $dbKey = 'dw_chat';
  9. const STATE_APPLY = 0; // 申请中
  10. const STATE_IN_GROUP = 1; // 在群里
  11. const STATE_LEAVE = 2; // 离开群
  12. /**
  13. * 检查是否是管理员
  14. * @author benzhan
  15. * @param $group_id
  16. * @param $user_id
  17. * @return array
  18. */
  19. public function isAdmin($group_id, $user_id) {
  20. $row = $this->objTable->getRow(compact('user_id', 'group_id'));
  21. return $row['is_admin'];
  22. }
  23. /**
  24. * 是否被禁言
  25. * @author solu
  26. * @param $group_id
  27. * @param $user_id
  28. * @return bool
  29. */
  30. public function isBlock($group_id, $user_id) {
  31. $row = $this->objTable->getRow(compact('user_id', 'group_id'));
  32. return !!$row['is_block'];
  33. }
  34. /**
  35. * 设置封禁用户
  36. * @param $group_id
  37. * @param $user_id
  38. * @param int $is_block
  39. */
  40. public function setBlock($group_id, $user_id, $is_block = 1) {
  41. // $this->objTable->updateObject(compact('is_block'), compact('user_id', 'group_id'));
  42. $this->setData($group_id, $user_id, compact('is_block'));
  43. }
  44. /**
  45. * 设置数据
  46. * @param $group_id
  47. * @param $user_id
  48. * @param array $data
  49. */
  50. public function setData($group_id, $user_id, $data = []) {
  51. $data['update_time'] = NOW;
  52. return $this->objTable->updateObject($data, compact('user_id', 'group_id'));
  53. }
  54. /**
  55. * 在群
  56. * @author solu
  57. * @param $groupId
  58. * @param $userId
  59. * @return bool
  60. */
  61. public function inGroup($groupId, $userId) {
  62. return $this->objTable->getCount(['user_id' => $userId, 'group_id' => $groupId, 'state' => self::STATE_IN_GROUP]) > 0;
  63. }
  64. public function getUserIdListSortByAdminAndJoinTime($groupId, $limit = 10) {
  65. return $this->objTable->getCol(['group_id' => $groupId, 'state' => self::STATE_IN_GROUP], [
  66. '_field' => 'user_id',
  67. '_sortKey' => 'is_admin DESC, join_time ASC',
  68. '_limit' => $limit,
  69. ]);
  70. }
  71. }