|
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768 |
- 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) {
- var users []md.UserInfo
- session := engine.SQL("SELECT a.*, user_tag_records.tag_id AS tag_id, b.phone AS parent_phone, b.system_invite_code AS parent_system_invite_code, b.custom_invite_code AS parent_custom_invite_code FROM `user` AS a, `user` AS b, `user_tag_records`" +
- "WHERE a.parent_uid = b.id AND 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).FindAndCount(&users)
- if err != nil {
- return nil, 0, err
- }
- return &users, total, nil
- }
|