Bladeren bron

fix:报告和章节的留言点赞分开返回

Roc 5 maanden geleden
bovenliggende
commit
ed0120dbd5
2 gewijzigde bestanden met toevoegingen van 44 en 19 verwijderingen
  1. 40 15
      models/tables/yb_comment/query.go
  2. 4 4
      services/yb_common.go

+ 40 - 15
models/tables/yb_comment/query.go

@@ -5,12 +5,18 @@ import (
 	"hongze/hongze_yb/utils"
 )
 
-
 // GetListByUserIdReportId 获取用户的留言列表
 func GetListByUserIdReportId(userId uint64, reportId, reportChapterId int) (list []*YbComment, err error) {
-	err = global.DEFAULT_MYSQL.Model(YbComment{}).
-		Where("user_id = ? and report_id = ? and report_chapter_id = ? and enabled = 1 ", userId, reportId, reportChapterId).
-		Order("create_time desc, comment_id desc").
+	//err = global.DEFAULT_MYSQL.Model(YbComment{}).
+	//	Where("user_id = ? and report_id = ? and report_chapter_id = ? and enabled = 1 ", userId, reportId, reportChapterId).
+	//	Order("create_time desc, comment_id desc").
+	//	Scan(&list).Error
+	tmp := global.DEFAULT_MYSQL.Model(YbComment{}).
+		Where("user_id = ? and report_id = ? and enabled = 1 ", userId, reportId)
+	if reportChapterId > 0 {
+		tmp = tmp.Where("report_chapter_id = ?", reportChapterId)
+	}
+	err = tmp.Order("create_time desc, comment_id desc").
 		Scan(&list).Error
 	if err == utils.ErrNoRow {
 		err = nil
@@ -32,20 +38,39 @@ func GetListByUserIdOldReportId(userId uint64, oldReportId, oldReportChapterId i
 
 // GetHotListByReportId 获取报告的精选留言列表
 func GetHotListByReportId(reportId, reportChapterId int, offset, limit int) (list []*YbComment, err error) {
-	err = global.DEFAULT_MYSQL.Model(YbComment{}).
-		Where("report_id = ? and report_chapter_id = ? and enabled = 1 and is_hot = 1 and type = 1", reportId, reportChapterId).
-		Order("is_top desc, hot_top_time desc, comment_id desc").
+	//err = global.DEFAULT_MYSQL.Model(YbComment{}).
+	//	Where("report_id = ? and report_chapter_id = ? and enabled = 1 and is_hot = 1 and type = 1", reportId, reportChapterId).
+	//	Order("is_top desc, hot_top_time desc, comment_id desc").
+	//	Offset(offset).
+	//	Limit(limit).
+	//	Scan(&list).Error
+
+	tmp := global.DEFAULT_MYSQL.Model(YbComment{}).
+		Where("report_id = ? and enabled = 1 and is_hot = 1 and type = 1", reportId)
+
+	// 如果有填写章节id,那么就查询章节id
+	if reportChapterId > 0 {
+		tmp = tmp.Where("report_chapter_id = ? ", reportChapterId)
+	}
+
+	err = tmp.Order("is_top desc, hot_top_time desc, comment_id desc").
 		Offset(offset).
 		Limit(limit).
 		Scan(&list).Error
+
 	return
 }
 
 // GetHotListTotalByReportId 获取精选留言总条数
-func GetHotListTotalByReportId(reportId, reportChapterId int)(total int64, err error)  {
-	err = global.DEFAULT_MYSQL.Model(YbComment{}).
-		Where("report_id = ? and report_chapter_id = ? and enabled = 1 and is_hot = 1 and type = 1", reportId, reportChapterId).
-		Count(&total).Error
+func GetHotListTotalByReportId(reportId, reportChapterId int) (total int64, err error) {
+	tmp := global.DEFAULT_MYSQL.Model(YbComment{}).
+		Where("report_id = ? and enabled = 1 and is_hot = 1 and type = 1", reportId)
+	// 如果有填写章节id,那么就查询章节id
+	if reportChapterId > 0 {
+		tmp = tmp.Where(" report_chapter_id = ? ", reportChapterId)
+	}
+	err = tmp.Count(&total).Error
+
 	return
 }
 
@@ -61,7 +86,7 @@ func GetHotListByOldReportId(oldReportId, oldReportChapterId int, offset, limit
 }
 
 // GetHotListTotalByOldReportId 获取老报告的精选留言总条数
-func GetHotListTotalByOldReportId(oldReportId, oldReportChapterId int)(total int64, err error)  {
+func GetHotListTotalByOldReportId(oldReportId, oldReportChapterId int) (total int64, err error) {
 	err = global.DEFAULT_MYSQL.Model(YbComment{}).
 		Where("old_report_id = ? and old_report_chapter_id = ? and enabled = 1 and is_hot = 1 and type = 1", oldReportId, oldReportChapterId).
 		Count(&total).Error
@@ -78,7 +103,7 @@ func GetReplyListByReplyCommentId(replyCommentIds []uint64) (list []*YbComment,
 }
 
 // GetSimpleByCommentId 根据留言ID,查询留言
-func GetSimpleByCommentId(commentId uint64)(item *YbComment, err error)  {
+func GetSimpleByCommentId(commentId uint64) (item *YbComment, err error) {
 	err = global.DEFAULT_MYSQL.Model(YbComment{}).
 		Select("comment_id, user_id, type, enabled").
 		Where("comment_id = ?", commentId).First(&item).Error
@@ -89,9 +114,9 @@ func GetSimpleByCommentId(commentId uint64)(item *YbComment, err error)  {
 }
 
 // GetMyLatestComment 获取用户最新的留言
-func GetMyLatestComment(userId uint64) (item *YbComment, err error){
+func GetMyLatestComment(userId uint64) (item *YbComment, err error) {
 	err = global.DEFAULT_MYSQL.Model(YbComment{}).
 		Select("comment_id, user_id, type, enabled, is_show_name").
 		Where("user_id = ? and type=1", userId).Order("comment_id desc").First(&item).Error
 	return
-}
+}

+ 4 - 4
services/yb_common.go

@@ -99,10 +99,10 @@ func CheckReportExistByReportIdReportChapterId(reportId, reportChapterId int) (e
 		return
 	}
 
-	if reportInfo.HasChapter == 1 && reportChapterId <= 0 {
-		err = errors.New("请输入报告章节ID")
-		return
-	}
+	//if reportInfo.HasChapter == 1 && reportChapterId <= 0 {
+	//	err = errors.New("请输入报告章节ID")
+	//	return
+	//}
 
 	if reportChapterId > 0 {
 		reportChapterInfo, tErr := report_chapter.GetTypeIdById(reportChapterId)