|
- package svc
-
- import (
- "applet/app/db"
- "applet/app/db/im/model"
- md "applet/app/md/im"
- "errors"
- "fmt"
- )
-
- func GroupList(req md.GroupListReq) (err error, resp md.GroupListResp) {
- sess := db.DbIm.Where("1=1")
- var groupIds []int64
- if req.GroupAdmin != "" {
- var user model.User
- has, err1 := db.DbIm.Where("`phone_number`=?", req.GroupAdmin).Get(&user)
- if err1 != nil {
- return
- }
- if !has {
- return errors.New("群主账号不存在"), resp
- }
- var groupUserList []*model.GroupUser
- err = db.DbIm.Where("`user_id`=? and member_type= 1", user.Id).Find(&groupUserList)
- if err != nil {
- return
- }
- for _, v := range groupUserList {
- groupIds = append(groupIds, v.GroupId)
- }
- }
-
- var mm []*model.Group
- if len(groupIds) > 0 {
- sess.In("id", groupIds)
- }
- resp.Total, err = sess.Limit(req.PageSize, (req.Page-1)*req.PageSize).Asc("id").FindAndCount(&mm)
- if err != nil {
- return
- }
- resp.Page = req.Page
- resp.PageSize = req.PageSize
- for _, v := range mm {
- var tmp = struct {
- Id int64
- Name string
- AvatarUrl string
- Introduction string
- UserNum int32
- IsAllMemberBanned int32
- IsAllAddFriend int32
- Extra string
- CreateTime string
- UpdateTime string
- PhoneNumber string
- Nickname string
- }{
- Id: v.Id,
- Name: v.Name,
- AvatarUrl: v.AvatarUrl,
- Introduction: v.Introduction,
- UserNum: v.UserNum,
- IsAllMemberBanned: v.IsAllMemberBanned,
- IsAllAddFriend: v.IsAllAddFriend,
- Extra: v.Extra,
- CreateTime: v.CreateTime,
- UpdateTime: v.UpdateTime,
- }
- var groupUser model.GroupUser
- has, err1 := db.DbIm.Where("`group_id`=? and member_type= 1", v.Id).Get(&groupUser)
- if err1 != nil {
- return
- }
- if has {
- var user model.User
- has, err = db.DbIm.ID(groupUser.UserId).Get(&user)
- if err != nil {
- return
- }
- if has {
- tmp.PhoneNumber = user.PhoneNumber
- tmp.Nickname = user.Nickname
- }
- }
- resp.List = append(resp.List, tmp)
- }
- return
- }
-
- type GroupUserJoinUser struct {
- model.GroupUser `xorm:"extends"`
- model.User `xorm:"extends"`
- }
-
- func GroupUserList(req md.GroupUserListReq) (err error, resp md.GroupUserListResp) {
- sess := db.DbIm.Table("group_user").Where("1=1")
- sess.Join("LEFT", "user", "group_user.user_id = user.id")
- if req.Phone != "" {
- sess.And("user.phone LIKE ?", "%"+req.Phone+"%")
- }
- if req.Nickname != "" {
- sess.And("user.nickname LIKE ?", "%"+req.Nickname+"%")
- }
- var mm []*GroupUserJoinUser
- resp.Total, err = sess.Limit(req.PageSize, (req.Page-1)*req.PageSize).Asc("group_user.id").FindAndCount(&mm)
- sql, _ := sess.LastSQL()
- fmt.Println("GroupUserList___SQL:::", sql)
- if err != nil {
- return
- }
- resp.Page = req.Page
- resp.PageSize = req.PageSize
- for _, v := range mm {
- resp.List = append(resp.List, struct {
- Id int64
- GroupId int64
- UserId int64
- MemberType int
- Remarks string
- Extra string
- Status int
- CreateTime string
- UpdateTime string
- PhoneNumber string
- Nickname string
- }{
- Id: v.GroupUser.Id,
- GroupId: int64(v.GroupUser.GroupId),
- UserId: v.GroupUser.UserId,
- MemberType: v.GroupUser.MemberType,
- Remarks: v.GroupUser.Remarks,
- Extra: v.GroupUser.Extra,
- Status: v.GroupUser.Status,
- CreateTime: v.GroupUser.CreateTime,
- UpdateTime: v.GroupUser.UpdateTime,
- PhoneNumber: v.User.PhoneNumber,
- Nickname: v.User.Nickname,
- })
- }
- return
- }
|