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.
59 lines
1.3 KiB
59 lines
1.3 KiB
package user
|
|
|
|
import (
|
|
"gorm.io/gorm"
|
|
"live/app/lib/db"
|
|
)
|
|
|
|
type UserTrendData struct {
|
|
db.BaseModel
|
|
Id uint `gorm:"column:id" json:"id"`
|
|
TrendId uint `gorm:"column:trend_id" json:"trendId"`
|
|
Comment uint `gorm:"column:comment" json:"comment"`
|
|
Praise uint `gorm:"praise" json:"praise"`
|
|
}
|
|
|
|
// 插入
|
|
func (u *UserTrendData) Create(userTrendData *UserTrendData) uint {
|
|
u.GetDb().Create(userTrendData)
|
|
if userTrendData.Id > 0 {
|
|
return userTrendData.Id
|
|
}
|
|
return 0
|
|
}
|
|
|
|
// @Title 根据TrendIds批量获取数据
|
|
func (u *UserTrendData) GetListByTrendIds(trendIds []uint) (result []UserTrendData) {
|
|
if len(trendIds) == 0 {
|
|
return
|
|
}
|
|
u.GetDb().Model(u).Find(&result, "trend_id in (?)", trendIds)
|
|
return
|
|
}
|
|
|
|
// @Title 会员新增赞
|
|
func (u *UserTrendData) AddPraise(trendId uint) int64 {
|
|
if trendId <= 0 {
|
|
return 0
|
|
}
|
|
rows := u.GetDb().Model(u).Where(&UserTrendData{TrendId: trendId}).Update("praise", gorm.Expr("praise + ?", 1)).RowsAffected
|
|
if rows == 0 {
|
|
id := u.GetDb().Create(&UserTrendData{
|
|
TrendId: trendId,
|
|
Praise: 1,
|
|
}).RowsAffected
|
|
if id != 0 {
|
|
return 1
|
|
}
|
|
}
|
|
return rows
|
|
}
|
|
|
|
// @Title 会员取消赞
|
|
func (u *UserTrendData) CancelPraise(trendId uint) int64 {
|
|
if trendId == 0 {
|
|
return 0
|
|
}
|
|
return u.GetDb().Model(u).Where(&UserTrendData{TrendId: trendId}).Update("praise", gorm.Expr("praise - ?", 1)).RowsAffected
|
|
}
|