From cff192c47132f9404b153dc810dd1fb665e19e5f Mon Sep 17 00:00:00 2001 From: dengbiao Date: Mon, 9 Dec 2024 19:46:36 +0800 Subject: [PATCH] update --- app/hdl/member_center/hdl_user_management.go | 12 ++++---- app/svc/member_center/svc_user_management.go | 30 ++++++++++++++------ 2 files changed, 27 insertions(+), 15 deletions(-) diff --git a/app/hdl/member_center/hdl_user_management.go b/app/hdl/member_center/hdl_user_management.go index 157ea91..9950bf6 100644 --- a/app/hdl/member_center/hdl_user_management.go +++ b/app/hdl/member_center/hdl_user_management.go @@ -75,13 +75,13 @@ func UserManagementGetUserList(c *gin.Context) { }, } - users, total, err3 := svc.UserManagementGetUsers(db.Db, req) + users, total, err3 := svc.UserManagementGetUsers(req) if err3 != nil { e.OutErr(c, e.ERR_DB_ORM, err3.Error()) return } - userIDs := make([]int64, len(*users)) - for i, user := range *users { + userIDs := make([]int64, len(users)) + for i, user := range users { userIDs[i] = user.Id } @@ -102,9 +102,9 @@ func UserManagementGetUserList(c *gin.Context) { return } - userMap := make(map[int64]int, len(*users)) - list := make([]md.UserManagementGetUserListNode, len(*users)) - for i, user := range *users { + userMap := make(map[int64]int, len(users)) + list := make([]md.UserManagementGetUserListNode, len(users)) + for i, user := range users { list[i] = md.UserManagementGetUserListNode{ ID: user.Id, Sex: user.Sex, diff --git a/app/svc/member_center/svc_user_management.go b/app/svc/member_center/svc_user_management.go index e8976f7..b349dd4 100644 --- a/app/svc/member_center/svc_user_management.go +++ b/app/svc/member_center/svc_user_management.go @@ -6,14 +6,31 @@ import ( "applet/app/utils" "code.fnuoos.com/EggPlanet/egg_models.git/src/implement" "code.fnuoos.com/EggPlanet/egg_models.git/src/model" + "fmt" "strings" "time" "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").Distinct("a.id"). +func UserManagementGetUsers(req *md.UserManagementGetUserListReq) ([]*md.UserInfo, int64, error) { + users := make([]*md.UserInfo, 0) + pageSess := userManagementGetUsersBindQuery(db.Db, req) + countSess := userManagementGetUsersBindQuery(db.Db, req) + total, err := countSess.Distinct("a.id").Count(&md.UserInfo{}) + if err != nil { + fmt.Println(err.Error()) + return nil, 0, err + } + + err = pageSess.Distinct("a.*").Limit(req.Limit, (req.Page-1)*req.Limit).Asc("a.id").Find(&users) + if err != nil { + return nil, 0, err + } + return users, total, nil +} + +func userManagementGetUsersBindQuery(engine *xorm.Engine, req *md.UserManagementGetUserListReq) *xorm.Session { + 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 { @@ -67,13 +84,8 @@ func UserManagementGetUsers(engine *xorm.Engine, req *md.UserManagementGetUserLi 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 + return session } - func UserManagementUpdateUserInfo(engine *xorm.Engine, req *md.UserManagementUpdateUserInfoReq) (int64, error) { session := engine.NewSession() defer session.Close()