蛋蛋星球 后台端
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

141 line
3.8 KiB

  1. package svc
  2. import (
  3. "applet/app/db"
  4. "applet/app/db/im/model"
  5. md "applet/app/md/im"
  6. "errors"
  7. "fmt"
  8. )
  9. func GroupList(req md.GroupListReq) (err error, resp md.GroupListResp) {
  10. sess := db.DbIm.Where("1=1")
  11. var groupIds []int64
  12. if req.GroupAdmin != "" {
  13. var user model.User
  14. has, err1 := db.DbIm.Where("`phone_number`=?", req.GroupAdmin).Get(&user)
  15. if err1 != nil {
  16. return
  17. }
  18. if !has {
  19. return errors.New("群主账号不存在"), resp
  20. }
  21. var groupUserList []*model.GroupUser
  22. err = db.DbIm.Where("`user_id`=? and member_type= 1", user.Id).Find(&groupUserList)
  23. if err != nil {
  24. return
  25. }
  26. for _, v := range groupUserList {
  27. groupIds = append(groupIds, v.GroupId)
  28. }
  29. }
  30. var mm []*model.Group
  31. if len(groupIds) > 0 {
  32. sess.In("id", groupIds)
  33. }
  34. resp.Total, err = sess.Limit(req.PageSize, (req.Page-1)*req.PageSize).Asc("id").FindAndCount(&mm)
  35. if err != nil {
  36. return
  37. }
  38. resp.Page = req.Page
  39. resp.PageSize = req.PageSize
  40. for _, v := range mm {
  41. var tmp = struct {
  42. Id int64 // 群组id
  43. Name string // 组名
  44. AvatarUrl string // 头像
  45. Introduction string // 群简介
  46. UserNum int32 // 群组人数
  47. IsAllMemberBanned int32 // 是否全员禁言(1:是 2:否)
  48. IsAllAddFriend int32 // 是否允许加好友(1:是 2:否)
  49. Extra string // 附加字段
  50. CreateTime string // 创建时间
  51. UpdateTime string // 更新时间
  52. PhoneNumber string // 群主账号
  53. Nickname string // 群主昵称
  54. }{
  55. Id: v.Id,
  56. Name: v.Name,
  57. AvatarUrl: v.AvatarUrl,
  58. Introduction: v.Introduction,
  59. UserNum: v.UserNum,
  60. IsAllMemberBanned: v.IsAllMemberBanned,
  61. IsAllAddFriend: v.IsAllAddFriend,
  62. Extra: v.Extra,
  63. CreateTime: v.CreateTime,
  64. UpdateTime: v.UpdateTime,
  65. }
  66. var groupUser model.GroupUser
  67. has, err1 := db.DbIm.Where("`group_id`=? and member_type= 1", v.Id).Get(&groupUser)
  68. if err1 != nil {
  69. return
  70. }
  71. if has {
  72. var user model.User
  73. has, err = db.DbIm.ID(groupUser.UserId).Get(&user)
  74. if err != nil {
  75. return
  76. }
  77. if has {
  78. tmp.PhoneNumber = user.PhoneNumber
  79. tmp.Nickname = user.Nickname
  80. }
  81. }
  82. }
  83. return
  84. }
  85. type GroupUserJoinUser struct {
  86. model.GroupUser `xorm:"extends"`
  87. model.User `xorm:"extends"`
  88. }
  89. func GroupUserList(req md.GroupUserListReq) (err error, resp md.GroupUserListResp) {
  90. sess := db.DbIm.Table("group_user").Where("1=1")
  91. sess.Join("LEFT", "user", "group_user.user_id = user.id")
  92. if req.Phone != "" {
  93. sess.And("user.phone LIKE ?", "%"+req.Phone+"%")
  94. }
  95. if req.Nickname != "" {
  96. sess.And("user.nickname LIKE ?", "%"+req.Nickname+"%")
  97. }
  98. var mm []*GroupUserJoinUser
  99. resp.Total, err = sess.Limit(req.PageSize, (req.Page-1)*req.PageSize).Asc("group_user.id").FindAndCount(&mm)
  100. sql, _ := sess.LastSQL()
  101. fmt.Println("GroupUserList___SQL:::", sql)
  102. if err != nil {
  103. return
  104. }
  105. resp.Page = req.Page
  106. resp.PageSize = req.PageSize
  107. for _, v := range mm {
  108. resp.List = append(resp.List, struct {
  109. Id int64 // 自增主键
  110. GroupId int64 // 群组id
  111. UserId int64 // 用户id
  112. MemberType int // 群组类型
  113. Remarks string // 备注
  114. Extra string // 附加属性
  115. Status int // 状态
  116. CreateTime string // 创建时间
  117. UpdateTime string // 更新时间
  118. PhoneNumber string // 账号
  119. Nickname string // 昵称
  120. }{
  121. Id: v.GroupUser.Id,
  122. GroupId: int64(v.GroupUser.GroupId),
  123. UserId: v.GroupUser.UserId,
  124. MemberType: v.GroupUser.MemberType,
  125. Remarks: v.GroupUser.Remarks,
  126. Extra: v.GroupUser.Extra,
  127. Status: v.GroupUser.Status,
  128. CreateTime: v.GroupUser.CreateTime,
  129. UpdateTime: v.GroupUser.UpdateTime,
  130. PhoneNumber: v.User.PhoneNumber,
  131. Nickname: v.User.Nickname,
  132. })
  133. }
  134. return
  135. }