Bläddra i källkod

fix:问答列表页返回最近评论的用户名称

Roc 2 år sedan
förälder
incheckning
4a5d30e720

+ 3 - 4
controller/community/comment.go

@@ -84,15 +84,14 @@ func MyList(c *gin.Context) {
 	page := services.GetCurrPageByClaims(c)
 	pageSize := services.GetPageSizeByClaims(c)
 
-	list, total, isShowName, err, errMsg := yb_community_question.MyList(userinfo.UserID, communityQuestionID, page, pageSize)
+	list, total, err, errMsg := yb_community_question.MyList(userinfo.UserID, communityQuestionID, page, pageSize)
 	if err != nil {
 		response.FailMsg(errMsg, err.Error(), c)
 		return
 	}
 	response.OkData("查询成功", responseModel.RespCommunityQuestionCommentList{
-		List:       list,
-		Paging:     responseModel.GetPaging(page, pageSize, int(total)),
-		IsShowName: isShowName,
+		List:   list,
+		Paging: responseModel.GetPaging(page, pageSize, int(total)),
 	}, c)
 	return
 }

+ 26 - 8
logic/yb_community_question/yb_community_question_comment.go

@@ -6,7 +6,6 @@ import (
 	"hongze/hongze_yb/global"
 	"hongze/hongze_yb/models/response"
 	"hongze/hongze_yb/models/tables/wx_user"
-	"hongze/hongze_yb/models/tables/yb_comment"
 	"hongze/hongze_yb/models/tables/yb_comment_anonymous_user"
 	"hongze/hongze_yb/models/tables/yb_community_question_comment"
 	"hongze/hongze_yb/services/user"
@@ -140,16 +139,11 @@ func Delete(user user.UserInfo, communityQuestionCommentID uint64) (err error, e
 }
 
 // MyList 我的留言列表
-func MyList(userId uint64, communityQuestionID int, page, pageSize int) (list []*response.RespCommunityQuestionCommentItem, total int64, isShowName int8, err error, errMsg string) {
+func MyList(userId uint64, communityQuestionID int, page, pageSize int) (list []*response.RespCommunityQuestionCommentItem, total int64, err error, errMsg string) {
 	list, total, err, errMsg = List(userId, communityQuestionID, false, page, pageSize)
 	if err != nil {
 		return
 	}
-	//查询我的最新一条留言是否勾选匿名的设置
-	lastComment, tErr := yb_comment.GetMyLatestComment(userId)
-	if tErr == nil {
-		isShowName = lastComment.IsShowName
-	}
 	return
 }
 
@@ -304,6 +298,9 @@ func HandleCommentByCommunityQuestionItemList(userId uint64, questionList []*res
 	}
 	idArr := make([]uint32, 0)
 	idMap := make(map[uint32]int)
+
+	userIds := []uint64{userId} //所有的评论人
+
 	for i := 0; i < listLen; i++ {
 		idArr = append(idArr, uint32(questionList[i].CommunityQuestionID))
 		idMap[uint32(questionList[i].CommunityQuestionID)] = 1
@@ -320,6 +317,9 @@ func HandleCommentByCommunityQuestionItemList(userId uint64, questionList []*res
 	for _, v := range hotList {
 		ybCommunityQuestionCommentMap[v.CommunityQuestionID] = v
 		delete(idMap, v.CommunityQuestionID)
+
+		//评论人id
+		userIds = append(userIds, v.UserID)
 	}
 
 	myIdArr := make([]uint32, 0)
@@ -346,15 +346,33 @@ func HandleCommentByCommunityQuestionItemList(userId uint64, questionList []*res
 		numCommentMap[v.CommunityQuestionID] = v.Total
 	}
 
+	var userOthers []*wx_user.WxUser
+	if len(userIds) > 0 {
+		userOthers, err = wx_user.GetByUserIds(userIds)
+		if err != nil {
+			err = errors.New("查询精选留言用户出错")
+			return
+		}
+	}
+	usersMap := make(map[uint64]*wx_user.WxUser)
+	for _, v := range userOthers {
+		usersMap[v.UserID] = v
+	}
+
 	for _, v := range questionList {
 		//评论汇总数
 		if tmpTotal, ok := numCommentMap[uint32(v.CommunityQuestionID)]; ok {
 			v.CommentTotal = tmpTotal
 		}
 
-		//最近一条评论
+		//最近一条 精选/我的 评论
 		if ybCommunityQuestionCommentInfo, ok := ybCommunityQuestionCommentMap[uint32(v.CommunityQuestionID)]; ok {
 			v.Comment = ybCommunityQuestionCommentInfo.Content
+			v.CommentUserName = "匿名用户" + strconv.Itoa(int(3333+ybCommunityQuestionCommentInfo.UserID))
+			if info, ok := usersMap[ybCommunityQuestionCommentInfo.UserID]; ok && ybCommunityQuestionCommentInfo.IsShowName == 1 {
+				v.CommentUserName = info.NickName
+				//v.UserImgUrl = info.Headimgurl
+			}
 		}
 	}
 	return

+ 9 - 9
models/response/community.go

@@ -21,12 +21,13 @@ type CommunityQuestionItem struct {
 	ReplyStatus             int    `json:"reply_status" description:"回复状态 1-待分配 2-待回答 3-已回答"`
 	//AuthOk                  bool                          `json:"auth_ok" description:"是否有权限"`
 	//PermissionInfo          PermissionCheckInfo           `json:"permission_info"`
-	AudioList    []*CommunityQuestionAudioItem `json:"audio_list"`
-	OpType       int8                          `description:"类型. 1-点赞 2-吐槽" json:"op_type"`
-	LikeTotal    int                           `json:"like_total" description:"点赞数"`
-	TeaseTotal   int                           `json:"tease_total" description:"吐槽数"`
-	CommentTotal int                           `json:"comment_total" description:"总共评论数"`
-	Comment      string                        `json:"comment" description:"评论"`
+	AudioList       []*CommunityQuestionAudioItem `json:"audio_list"`
+	OpType          int8                          `description:"类型. 1-点赞 2-吐槽" json:"op_type"`
+	LikeTotal       int                           `json:"like_total" description:"点赞数"`
+	TeaseTotal      int                           `json:"tease_total" description:"吐槽数"`
+	CommentTotal    int                           `json:"comment_total" description:"总共评论数"`
+	Comment         string                        `json:"comment" description:"评论"`
+	CommentUserName string                        `json:"comment_user_name" description:"评论人"`
 }
 
 type CommunityQuestionAudioItem struct {
@@ -112,7 +113,6 @@ type RespCommunityQuestionCommentItem struct {
 
 // RespCommunityQuestionCommentList 问答留言列表接口返回
 type RespCommunityQuestionCommentList struct {
-	List       []*RespCommunityQuestionCommentItem `json:"list"`
-	Paging     *PagingItem                         `json:"paging"`
-	IsShowName int8                                `description:"是否匿名 0-匿名,1-不匿名" json:"is_show_name"`
+	List   []*RespCommunityQuestionCommentItem `json:"list"`
+	Paging *PagingItem                         `json:"paging"`
 }