This commit is contained in:
sjk
2025-11-28 15:18:10 +08:00
parent ad4a600af9
commit 5683f35942
188 changed files with 53680 additions and 1062 deletions

View File

@@ -202,6 +202,22 @@ func (r *CommentRepository) CreateReply(reply *model.CommentReply) error {
return tx.Commit().Error
}
// GetHighRatingComments 获取高分评论(用于首页展示)
func (r *CommentRepository) GetHighRatingComments(limit int, minRating int) ([]model.Comment, error) {
var comments []model.Comment
// 获取评分>=minRating的评论按评分降序、创建时间降序排列
err := r.db.Model(&model.Comment{}).
Where("status = ? AND rating >= ?", 1, minRating).
Preload("User").
Preload("Product").
Order("rating DESC, created_at DESC").
Limit(limit).
Find(&comments).Error
return comments, err
}
// GetReplies 获取评论回复列表
func (r *CommentRepository) GetReplies(commentID uint) ([]model.CommentReply, error) {
var replies []model.CommentReply