From c1a7417e5fd30cee2abfe2c7ffaca0366b82a4cd Mon Sep 17 00:00:00 2001 From: hujiebin Date: Wed, 14 Jun 2023 15:00:49 +0800 Subject: [PATCH] cpUserAvatar --- cv/cp_cv/cp.go | 7 ++++--- route/user_r/inner.go | 22 ++++++++++++++++------ 2 files changed, 20 insertions(+), 9 deletions(-) diff --git a/cv/cp_cv/cp.go b/cv/cp_cv/cp.go index 4525dd3..0fcb0eb 100644 --- a/cv/cp_cv/cp.go +++ b/cv/cp_cv/cp.go @@ -11,7 +11,8 @@ type CvCp struct { // cp关系 type CvCpRelation struct { - CpId uint64 `json:"cpId"` - UserId uint64 `json:"userId"` - CpUserId uint64 `json:"cpUserId"` + CpId uint64 `json:"cpId"` + UserId uint64 `json:"userId"` + CpUserId uint64 `json:"cpUserId"` + CpUserAvatar string `json:"cpUserAvatar,omitempty"` } diff --git a/route/user_r/inner.go b/route/user_r/inner.go index 7bee448..c379bcc 100644 --- a/route/user_r/inner.go +++ b/route/user_r/inner.go @@ -193,10 +193,12 @@ func GetUserCpRelation(c *gin.Context) (*mycontext.MyContext, error) { if cpUserId == userId { cpUserId = cpRelation.UserId1 } + cpUser, _ := user_m.GetUser(model, cpUserId) response = cp_cv.CvCpRelation{ - CpId: cpRelation.ID, - UserId: userId, - CpUserId: cpUserId, + CpId: cpRelation.ID, + UserId: userId, + CpUserId: cpUserId, + CpUserAvatar: cpUser.Avatar, } resp.ResponseOk(c, response) return myContext, nil @@ -220,9 +222,16 @@ func MGetUserCpRelation(c *gin.Context) (*mycontext.MyContext, error) { } cpRelations := cp_m.MGetCpRelation(model, req.Ids) var m = make(map[uint64]cp_m.CpRelationTmp) + var userIds []uint64 for i, v := range cpRelations { m[v.UserId1] = cpRelations[i] m[v.UserId2] = cpRelations[i] + userIds = append(userIds, v.UserId1) + userIds = append(userIds, v.UserId2) + } + users, err := user_m.GetUserMapByIds(model, userIds) + if err != nil { + return myContext, err } var response = make(map[uint64]cp_cv.CvCpRelation) for _, uid := range req.Ids { @@ -232,9 +241,10 @@ func MGetUserCpRelation(c *gin.Context) (*mycontext.MyContext, error) { cpUserId = cpRelation.UserId1 } response[uid] = cp_cv.CvCpRelation{ - CpId: cpRelation.ID, - UserId: uid, - CpUserId: cpUserId, + CpId: cpRelation.ID, + UserId: uid, + CpUserId: cpUserId, + CpUserAvatar: users[cpUserId].Avatar, } } } -- 2.22.0