|
@@ -128,16 +128,102 @@ func Delete(user user.UserInfo, req *reqComment.ReqDel) (err error) {
|
|
|
err = errors.New("不允许删除他人的留言")
|
|
|
return
|
|
|
}
|
|
|
+ if commentInfo.Type != 1 {
|
|
|
+ err = errors.New("不允许删除回复")
|
|
|
+ return
|
|
|
+ }
|
|
|
if commentInfo.Enabled == 0 {
|
|
|
return
|
|
|
}
|
|
|
- commentInfo.Enabled = 0
|
|
|
- commentInfo.ModifyTime = time.Now()
|
|
|
- err = commentInfo.Update([]string{"enabled", "modify_time"})
|
|
|
+ err = yb_comment.Delete(user.UserID, commentInfo.CommentId)
|
|
|
if err != nil {
|
|
|
errMsg = err.Error()
|
|
|
- err = errors.New("更新留言出错")
|
|
|
+ err = errors.New("删除留言出错")
|
|
|
return
|
|
|
}
|
|
|
return
|
|
|
}
|
|
|
+
|
|
|
+// List 查询精选留言列表或我的留言列表
|
|
|
+func List(user user.UserInfo, reportId, reportChapterId int, hotFlag bool, pageIndex, pageSize int) (ret response.RespCommentList, err error) {
|
|
|
+ var errMsg string
|
|
|
+ defer func() {
|
|
|
+ if err != nil {
|
|
|
+ global.LOG.Critical(fmt.Sprintf("GetReportList: userId=%d, err:%s, errMsg:%s", user.UserID, err.Error(), errMsg))
|
|
|
+ }
|
|
|
+ }()
|
|
|
+
|
|
|
+ offset := (pageIndex -1)*pageSize
|
|
|
+ var commentList []*yb_comment.YbComment
|
|
|
+ var total int64
|
|
|
+ //查询精选留言
|
|
|
+ if hotFlag {
|
|
|
+ commentList, err = yb_comment.GetHotListByReportId(reportId, reportChapterId, offset, pageSize)
|
|
|
+ if err != nil {
|
|
|
+ errMsg = err.Error()
|
|
|
+ err = errors.New("查询精选留言列表出错")
|
|
|
+ return
|
|
|
+ }
|
|
|
+ total, err = yb_comment.GetHostListTotalByReportId(reportId, reportChapterId)
|
|
|
+ if err != nil {
|
|
|
+ errMsg = err.Error()
|
|
|
+ err = errors.New("查询精选留言总数出错")
|
|
|
+ return
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ //查询个人留言
|
|
|
+ commentList, err = yb_comment.GetListByUserIdReportId(user.UserID, reportId, reportChapterId)
|
|
|
+ if err != nil {
|
|
|
+ errMsg = err.Error()
|
|
|
+ err = errors.New("查询精选留言列表出错")
|
|
|
+ return
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ var commentIds []uint64
|
|
|
+ for _, v := range commentList {
|
|
|
+ commentIds = append(commentIds, v.CommentId)
|
|
|
+ }
|
|
|
+ // 查询所有的回复列表
|
|
|
+ replyListMap := make(map[uint64][]*response.ReplyItem)
|
|
|
+ if len(commentIds) > 0 {
|
|
|
+ replyList, tErr := yb_comment.GetReplyListByReplyCommentId(reportId, reportChapterId, commentIds)
|
|
|
+ if tErr != nil {
|
|
|
+ errMsg = tErr.Error()
|
|
|
+ err = errors.New("查询回复出错")
|
|
|
+ return
|
|
|
+ }
|
|
|
+ for _, v := range replyList {
|
|
|
+ t := new(response.ReplyItem)
|
|
|
+ t.CommentId = v.CommentId
|
|
|
+ t.Content = v.Content
|
|
|
+ t.AdminId = v.AdminId
|
|
|
+ t.CreateTime = v.CreateTime
|
|
|
+ t.AdminName = ""
|
|
|
+ t.AdminImg = ""
|
|
|
+ replyListMap[v.ReplyCommentId] = append(replyListMap[v.ReplyCommentId], t)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ var list []*response.RespCommentItem
|
|
|
+ for _, v := range commentList {
|
|
|
+ tmp := new(response.RespCommentItem)
|
|
|
+ tmp.CommentId = v.CommentId
|
|
|
+ tmp.UserId = v.UserId
|
|
|
+ tmp.UserName = ""
|
|
|
+ tmp.UserImg = ""
|
|
|
+ tmp.Content = v.Content
|
|
|
+ tmp.IsHot = v.IsHot
|
|
|
+ tmp.IsTop = v.IsTop
|
|
|
+ tmp.HotTopTime = v.HotTopTime
|
|
|
+ tmp.CreateTime = v.CreateTime
|
|
|
+ if existList, ok := replyListMap[v.CommentId]; ok {
|
|
|
+ tmp.ReplyList = existList
|
|
|
+ }
|
|
|
+ list = append(list, tmp)
|
|
|
+ }
|
|
|
+ ret.List = list
|
|
|
+ if hotFlag {
|
|
|
+ ret.Paging = response.GetPaging(pageIndex, pageSize, int(total))
|
|
|
+ }
|
|
|
+ return
|
|
|
+}
|