From 24f35a18d5cd5af84111e6f757725e20af1e7624 Mon Sep 17 00:00:00 2001 From: alimy Date: Fri, 6 Feb 2026 11:25:15 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8F=90=E5=8F=96updateCommentThumbsUpCount()?= =?UTF-8?q?=E5=88=B0=E5=8C=85=E5=86=85=E8=BE=85=E7=BB=84=E5=87=BD=E6=95=B0?= =?UTF-8?q?=E4=BB=A5=E8=BF=9B=E8=A1=8C=E4=BA=8B=E5=8A=A1=E6=93=8D=E4=BD=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- internal/dao/jinzhu/comments.go | 17 +---------------- internal/dao/jinzhu/utils.go | 21 +++++++++++++++++++++ 2 files changed, 22 insertions(+), 16 deletions(-) diff --git a/internal/dao/jinzhu/comments.go b/internal/dao/jinzhu/comments.go index c30fda69..262c3007 100644 --- a/internal/dao/jinzhu/comments.go +++ b/internal/dao/jinzhu/comments.go @@ -423,20 +423,5 @@ func (s *commentManageSrv) ThumbsDownReply(userId int64, tweetId, commentId, rep } func (s *commentManageSrv) updateCommentThumbsUpCount(obj any, id int64, thumbsUpCount, thumbsDownCount int32) error { - updateColumns := make(map[string]any, 2) - if thumbsUpCount == 1 { - updateColumns["thumbs_up_count"] = gorm.Expr("thumbs_up_count + 1") - } else if thumbsUpCount == -1 { - updateColumns["thumbs_up_count"] = gorm.Expr("thumbs_up_count - 1") - } - if thumbsDownCount == 1 { - updateColumns["thumbs_down_count"] = gorm.Expr("thumbs_down_count + 1") - } else if thumbsDownCount == -1 { - updateColumns["thumbs_down_count"] = gorm.Expr("thumbs_down_count - 1") - } - if len(updateColumns) > 0 { - updateColumns["modified_on"] = time.Now().Unix() - return s.db.Model(obj).Where("id=?", id).UpdateColumns(updateColumns).Error - } - return nil + return updateCommentThumbsUpCount(s.db, obj, id, thumbsUpCount, thumbsDownCount) } diff --git a/internal/dao/jinzhu/utils.go b/internal/dao/jinzhu/utils.go index 9d97b4b8..6d7ef850 100644 --- a/internal/dao/jinzhu/utils.go +++ b/internal/dao/jinzhu/utils.go @@ -5,6 +5,8 @@ package jinzhu import ( + "time" + "github.com/rocboss/paopao-ce/internal/core/cs" "github.com/rocboss/paopao-ce/internal/dao/jinzhu/dbr" "gorm.io/gorm" @@ -78,3 +80,22 @@ func getUsersByIDs(db *gorm.DB, ids []int64) ([]*dbr.User, error) { "id IN ?": ids, }, 0, 0) } + +func updateCommentThumbsUpCount(db *gorm.DB, obj any, id int64, thumbsUpCount, thumbsDownCount int32) error { + updateColumns := make(map[string]any, 2) + if thumbsUpCount == 1 { + updateColumns["thumbs_up_count"] = gorm.Expr("thumbs_up_count + 1") + } else if thumbsUpCount == -1 { + updateColumns["thumbs_up_count"] = gorm.Expr("thumbs_up_count - 1") + } + if thumbsDownCount == 1 { + updateColumns["thumbs_down_count"] = gorm.Expr("thumbs_down_count + 1") + } else if thumbsDownCount == -1 { + updateColumns["thumbs_down_count"] = gorm.Expr("thumbs_down_count - 1") + } + if len(updateColumns) > 0 { + updateColumns["modified_on"] = time.Now().Unix() + return db.Model(obj).Where("id=?", id).UpdateColumns(updateColumns).Error + } + return nil +}