You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
83 lines
2.5 KiB
83 lines
2.5 KiB
package user
|
|
|
|
import (
|
|
"github.com/golangkit/formatime"
|
|
"live/app/lib/db"
|
|
)
|
|
|
|
type UserTrendCommentPraise struct {
|
|
db.BaseModel
|
|
Id uint `gorm:"column:id" json:"id"`
|
|
UserId uint `gorm:"column:user_id" json:"userId"`
|
|
CommentId uint `gorm:"column:comment_id" json:"commentId"`
|
|
IsDel int `gorm:"column:is_del" json:"isDel"`
|
|
CreatedAt formatime.Second `gorm:"column:created_at" json:"createdAt"`
|
|
UpdatedAt formatime.Second `gorm:"column:updated_at" json:"updatedAt"`
|
|
}
|
|
|
|
// 插入
|
|
func (u *UserTrendCommentPraise) Create(userTrendCommentPraise *UserTrendCommentPraise) uint {
|
|
u.GetDb().Create(userTrendCommentPraise)
|
|
if userTrendCommentPraise.Id > 0 {
|
|
return userTrendCommentPraise.Id
|
|
}
|
|
return 0
|
|
}
|
|
|
|
// @Title 会员新增赞
|
|
func (u *UserTrendCommentPraise) AddPraise(userId, commentId uint) uint {
|
|
if userId <= 0 || commentId <= 0 {
|
|
return 0
|
|
}
|
|
result := &UserTrendCommentPraise{
|
|
UserId: userId,
|
|
CommentId: commentId,
|
|
}
|
|
u.GetDb().Create(result)
|
|
return result.Id
|
|
}
|
|
|
|
// @Title 会员取消赞
|
|
func (u *UserTrendCommentPraise) CancelPraise(userId, commentId uint) int64 {
|
|
if userId <= 0 || commentId <= 0 {
|
|
return 0
|
|
}
|
|
return u.GetDb().Model(u).Where(&UserTrendCommentPraise{UserId: userId, CommentId: commentId}).Update("is_del", 1).RowsAffected
|
|
}
|
|
|
|
// @Title 重新点赞
|
|
func (u *UserTrendCommentPraise) RenewPraise(userId, commentId uint) int64 {
|
|
if userId <= 0 || commentId <= 0 {
|
|
return 0
|
|
}
|
|
return u.GetDb().Model(u).Where(&UserTrendCommentPraise{UserId: userId, CommentId: commentId}).
|
|
Where("is_del = ?", 1).Update("is_Del", 0).RowsAffected
|
|
}
|
|
|
|
// @Title 根据TrendIds批量获取数据
|
|
func (u *UserTrendCommentPraise) GetPraiseByCommentIds(commentIds []uint) (result []UserTrendCommentPraise) {
|
|
if len(commentIds) == 0 {
|
|
return
|
|
}
|
|
u.GetDb().Model(u).Find(&result, "comment_id in (?) and is_del = ? ", commentIds, 0)
|
|
return
|
|
}
|
|
|
|
// @Title 根据trendIds批量获取会员数据
|
|
func (u *UserTrendCommentPraise) GetPraiseByUserIdAndCommentIds(userId uint, commentIds []uint) (result []UserTrendCommentPraise) {
|
|
if userId <= 0 || len(commentIds) == 0 {
|
|
return
|
|
}
|
|
u.GetDb().Model(u).Find(&result, "user_id = ? and comment_id in (?) and is_del = ? ", userId, commentIds, 0)
|
|
return
|
|
}
|
|
|
|
// @Title 根据trendId获取会员数据
|
|
func (u *UserTrendCommentPraise) GetPraiseByUserIdAndCommentId(userId uint, commentId uint) (result UserTrendCommentPraise) {
|
|
if userId <= 0 || commentId <= 0 {
|
|
return
|
|
}
|
|
u.GetDb().Model(u).Find(&result, "user_id = ? and comment_id = ?", userId, commentId, 0)
|
|
return
|
|
}
|