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.
76 lines
2.2 KiB
76 lines
2.2 KiB
package user
|
|
|
|
import (
|
|
"github.com/golangkit/formatime"
|
|
"gorm.io/gorm"
|
|
"live/app/lib/db"
|
|
)
|
|
|
|
type UserLivePraise struct {
|
|
db.BaseModel
|
|
Id uint `gorm:"column:id" json:"id"`
|
|
UserId uint `gorm:"column:user_id" json:"userId"`
|
|
Praise uint `gorm:"column:praise" json:"praise"`
|
|
LiveItemId uint `gorm:"column:live_item_id" json:"LiveItemId"`
|
|
CreatedAt formatime.Second `gorm:"column:created_at" json:"createdAt"`
|
|
UpdatedAt formatime.Second `gorm:"column:updated_at" json:"updatedAt"`
|
|
}
|
|
|
|
// 插入
|
|
func (u *UserLivePraise) Create(userLivePraise *UserLivePraise) uint {
|
|
u.GetDb().Create(userLivePraise)
|
|
if userLivePraise.Id > 0 {
|
|
return userLivePraise.Id
|
|
}
|
|
return 0
|
|
}
|
|
|
|
// @Title 会员新增赞
|
|
func (u *UserLivePraise) CreatePraise(userId, liveItemId, praise uint) uint {
|
|
if userId <= 0 || liveItemId <= 0 || praise <= 0 {
|
|
return 0
|
|
}
|
|
result := &UserLivePraise{
|
|
UserId: userId,
|
|
LiveItemId: liveItemId,
|
|
Praise: praise,
|
|
}
|
|
u.GetDb().Create(result)
|
|
return result.Id
|
|
}
|
|
|
|
// @Title 会员新增赞
|
|
func (u *UserLivePraise) AddPraise(userId, liveItemId, praise, maxPraise uint) int64 {
|
|
if userId <= 0 || liveItemId <= 0 || praise <= 0 {
|
|
return 0
|
|
}
|
|
return u.GetDb().Model(&u).Where("user_id = ? and live_item_id = ? and praise <= ?", userId, liveItemId, maxPraise-praise).Update("praise", gorm.Expr("praise + ?", praise)).RowsAffected
|
|
}
|
|
|
|
// @Title 根据TrendIds批量获取数据
|
|
func (u *UserLivePraise) GetPraiseByLiveItemIds(trendIds []uint) (result []UserLivePraise) {
|
|
if len(trendIds) == 0 {
|
|
return
|
|
}
|
|
u.GetDb().Model(u).Find(&result, "live_item_id in (?)", trendIds)
|
|
return
|
|
}
|
|
|
|
// @Title 根据trendIds批量获取会员数据
|
|
func (u *UserLivePraise) GetPraiseByUserIdAndLiveItemIds(userId uint, trendIds []uint) (result []UserLivePraise) {
|
|
if userId <= 0 || len(trendIds) == 0 {
|
|
return
|
|
}
|
|
u.GetDb().Model(u).Find(&result, "user_id = ? and live_item_id in (?)", userId, trendIds)
|
|
return
|
|
}
|
|
|
|
// @Title 根据trendId获取会员数据
|
|
func (u *UserLivePraise) GetPraiseByUserIdAndLiveItemId(userId uint, trendId uint) (result UserLivePraise) {
|
|
if userId <= 0 || trendId <= 0 {
|
|
return
|
|
}
|
|
u.GetDb().Model(u).Find(&result, "user_id = ? and live_item_id = ?", userId, trendId, 0)
|
|
return
|
|
}
|