web
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user