package svc import ( md "applet/app/md/institutional_management/member_center" "xorm.io/xorm" ) func UserManagementGetUsers(engine *xorm.Engine, req *md.UserManagementGetUserListReq) (*[]md.UserInfo, int64, error) { users := make([]md.UserInfo, 0) session := engine.Table("user").Alias("a"). Join("LEFT OUTER", []string{"user", "b"}, "a.parent_uid = b.id"). Join("LEFT OUTER", "user_tag_records", "user_tag_records.uid = a.id") if req.ID != 0 { session = session.Where("a.id = ?", req.ID) } if req.Nickname != "" { session = session.Where("a.nickname = ?", req.Nickname) } if req.RecommendID != 0 { session = session.Where("a.parent_uid = ?", req.RecommendID) } if req.Tag != 0 { session = session.Where("a.tag_id = ?", req.Tag) } if req.Phone != "" { session = session.Where("a.phone = ?", req.Phone) } if req.InviteCode != "" { session = session.Where("a.system_invite_code = ? or a.custom_invite_code = ?", req.InviteCode, req.InviteCode) } if req.ParentPhone != "" { session = session.Where("b.phone= ?", req.ParentPhone) } if req.ParentInviteCode != "" { session = session.Where("b.system_invite_code = ? or b.custom_invite_code = ?", req.ParentInviteCode, req.ParentInviteCode) } if req.Sex != 0 { session = session.Where("a.sex = ?") } if req.UnionId != "" { session = session.Where("a.union_id = ?", req.UnionId) } if req.Level != 0 { session = session.Where("a.level = ?", req.Level) } if req.RegisterType != 0 { session = session.Where("a.register_type = ?", req.RegisterType) } if req.State != 0 { session = session.Where("a.state = ?", req.State) } if req.IsRealName != 0 { session = session.Where("a.is_real_name = ?", req.IsRealName) } if req.Memo != "" { session = session.Where("a.memo = ?", req.Memo) } if req.RegisterBefore != "" && req.RegisterAfter != "" { session = session.Where("a.create_at > ? and a.create_at < ?", req.RegisterBefore, req.RegisterAfter) } if req.LoginBefore != "" && req.LoginAfter != "" { session = session.Where("a.update_at > ? and a.update_at < ?", req.LoginBefore, req.LoginAfter) } total, err := session.Limit(req.Limit, (req.Page-1)*req.Limit).Asc("a.id").FindAndCount(&users) if err != nil { return nil, 0, err } return &users, total, nil }