蛋蛋星球 后台端
25'ten fazla konu seçemezsiniz Konular bir harf veya rakamla başlamalı, kısa çizgiler ('-') içerebilir ve en fazla 35 karakter uzunluğunda olabilir.
 
 
 
 

142 satır
3.9 KiB

  1. package svc
  2. import (
  3. "applet/app/db"
  4. "applet/app/db/im/model"
  5. md "applet/app/md/im"
  6. "fmt"
  7. )
  8. func GroupList(req md.GroupListReq) (err error, resp md.GroupListResp) {
  9. sess := db.DbIm.Where("1=1")
  10. var groupIds []int64
  11. if req.GroupAdmin != "" {
  12. var user model.User
  13. has, err1 := db.DbIm.Where("`phone_number`=?", req.GroupAdmin).Get(&user)
  14. if err1 != nil {
  15. return
  16. }
  17. if !has {
  18. //return errors.New("群主账号不存在"), resp
  19. return nil, 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. resp.List = append(resp.List, tmp)
  83. }
  84. return
  85. }
  86. type GroupUserJoinUser struct {
  87. model.GroupUser `xorm:"extends"`
  88. model.User `xorm:"extends"`
  89. }
  90. func GroupUserList(req md.GroupUserListReq) (err error, resp md.GroupUserListResp) {
  91. sess := db.DbIm.Table("group_user").Where("1=1")
  92. sess.Join("LEFT", "user", "group_user.user_id = user.id")
  93. if req.Phone != "" {
  94. sess.And("user.phone LIKE ?", "%"+req.Phone+"%")
  95. }
  96. if req.Nickname != "" {
  97. sess.And("user.nickname LIKE ?", "%"+req.Nickname+"%")
  98. }
  99. var mm []*GroupUserJoinUser
  100. resp.Total, err = sess.Limit(req.PageSize, (req.Page-1)*req.PageSize).Asc("group_user.id").FindAndCount(&mm)
  101. sql, _ := sess.LastSQL()
  102. fmt.Println("GroupUserList___SQL:::", sql)
  103. if err != nil {
  104. return
  105. }
  106. resp.Page = req.Page
  107. resp.PageSize = req.PageSize
  108. for _, v := range mm {
  109. resp.List = append(resp.List, struct {
  110. Id int64 // 自增主键
  111. GroupId int64 // 群组id
  112. UserId int64 // 用户id
  113. MemberType int // 群组类型
  114. Remarks string // 备注
  115. Extra string // 附加属性
  116. Status int // 状态
  117. CreateTime string // 创建时间
  118. UpdateTime string // 更新时间
  119. PhoneNumber string // 账号
  120. Nickname string // 昵称
  121. }{
  122. Id: v.GroupUser.Id,
  123. GroupId: int64(v.GroupUser.GroupId),
  124. UserId: v.GroupUser.UserId,
  125. MemberType: v.GroupUser.MemberType,
  126. Remarks: v.GroupUser.Remarks,
  127. Extra: v.GroupUser.Extra,
  128. Status: v.GroupUser.Status,
  129. CreateTime: v.GroupUser.CreateTime,
  130. UpdateTime: v.GroupUser.UpdateTime,
  131. PhoneNumber: v.User.PhoneNumber,
  132. Nickname: v.User.Nickname,
  133. })
  134. }
  135. return
  136. }