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.4 KiB
83 lines
2.4 KiB
package user
|
|
|
|
import (
|
|
"github.com/golangkit/formatime"
|
|
"live/app/lib/db"
|
|
)
|
|
|
|
type UserLivePraise struct {
|
|
db.BaseModel
|
|
Id uint `gorm:"column:id" json:"id"`
|
|
UserId uint `gorm:"column:user_id" json:"userId"`
|
|
LiveItemId uint `gorm:"column:live_item_id" json:"LiveItemId"`
|
|
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 *UserLivePraise) Create(userLivePraise *UserLivePraise) uint {
|
|
u.GetDb().Create(userLivePraise)
|
|
if userLivePraise.Id > 0 {
|
|
return userLivePraise.Id
|
|
}
|
|
return 0
|
|
}
|
|
|
|
// @Title 会员新增赞
|
|
func (u *UserLivePraise) AddPraise(userId, liveItemId uint) uint {
|
|
if userId <= 0 || liveItemId <= 0 {
|
|
return 0
|
|
}
|
|
result := &UserLivePraise{
|
|
UserId: userId,
|
|
LiveItemId: liveItemId,
|
|
}
|
|
u.GetDb().Create(result)
|
|
return result.Id
|
|
}
|
|
|
|
// @Title 会员取消赞
|
|
func (u *UserLivePraise) CancelPraise(userId, liveItemId uint) int64 {
|
|
if userId <= 0 || liveItemId <= 0 {
|
|
return 0
|
|
}
|
|
return u.GetDb().Model(u).Where(&UserLivePraise{UserId: userId, LiveItemId: liveItemId}).Update("is_del", 1).RowsAffected
|
|
}
|
|
|
|
// @Title 重新点赞
|
|
func (u *UserLivePraise) RenewPraise(userId, liveItemId uint) int64 {
|
|
if userId <= 0 || liveItemId <= 0 {
|
|
return 0
|
|
}
|
|
return u.GetDb().Model(u).Where(&UserLivePraise{UserId: userId, LiveItemId: liveItemId}).
|
|
Where("is_del = ?", 1).Update("is_Del", 0).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 (?) and is_del = ? ", trendIds, 0)
|
|
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 (?) and is_del = ? ", userId, trendIds, 0)
|
|
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
|
|
}
|