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.
57 lines
1.3 KiB
57 lines
1.3 KiB
package live
|
|
|
|
import (
|
|
"live/app/lib/db"
|
|
)
|
|
|
|
type LiveGoods struct {
|
|
db.BaseModel
|
|
Id uint `gorm:"column:id" json:"id"`
|
|
UserId uint `gorm:"column:user_id" json:"userId"`
|
|
GoodsId uint `gorm:"column:goods_id" json:"goodsId"`
|
|
LiveItemId uint `gorm:"column:live_item_id" json:"liveItemId"`
|
|
IsExplain uint `gorm:"column:is_explain" json:"isExplain"`
|
|
}
|
|
|
|
// 插入
|
|
func (l *LiveGoods) Create(liveGoods *LiveGoods) uint {
|
|
l.GetDb().Create(liveGoods)
|
|
if liveGoods.Id > 0 {
|
|
return liveGoods.Id
|
|
}
|
|
return 0
|
|
}
|
|
|
|
// 批量插入
|
|
func (l *LiveGoods) CreateAll(liveGoods *[]LiveGoods) int64 {
|
|
if len(*liveGoods) == 0 {
|
|
return 0
|
|
}
|
|
return l.GetDb().Create(liveGoods).RowsAffected
|
|
}
|
|
|
|
// 获取直播推荐商品
|
|
func (l *LiveGoods) GetGoodsByLiveItemId(liveItemId uint) (result []LiveGoods) {
|
|
if liveItemId == 0 {
|
|
return
|
|
}
|
|
l.GetDb().Find(&result, "live_item_id = ?", liveItemId)
|
|
return
|
|
}
|
|
|
|
// 取消讲解
|
|
func (l *LiveGoods) UnExplain(liveItemId uint) int64 {
|
|
if liveItemId == 0 {
|
|
return 0
|
|
}
|
|
return l.GetDb().Model(&LiveGoods{}).Where("live_item_id = ?", liveItemId).Update("is_explain", 0).RowsAffected
|
|
}
|
|
|
|
// 讲解
|
|
func (l *LiveGoods) Explain(liveItemId, goodsId uint) int64 {
|
|
if liveItemId == 0 {
|
|
return 0
|
|
}
|
|
return l.GetDb().Model(&LiveGoods{}).Where("live_item_id = ? and goods_id = ?", liveItemId, goodsId).Update("is_explain", 1).RowsAffected
|
|
}
|