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.

63 lines
1.8 KiB

package goods
import (
"github.com/golangkit/formatime"
"gorm.io/gorm/clause"
"live/app/lib/db"
)
type GoodsWindow 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"`
CreatedAt formatime.Second `gorm:"column:created_at" json:"createdAt"`
UpdatedAt formatime.Second `gorm:"column:updated_at" json:"updatedAt"`
IsDel int `gorm:"column:is_del" json:"isDel"`
}
// 插入
func (g *GoodsWindow) Create(goodsWindow *GoodsWindow) uint {
g.GetDb().Create(goodsWindow)
if goodsWindow.Id > 0 {
return goodsWindow.Id
}
return 0
}
// 批量插入 忽略重复
func (g *GoodsWindow) CreateAll(goodsWindows *[]GoodsWindow) int64 {
if len(*goodsWindows) == 0 {
return 0
}
return g.GetDb().Clauses(clause.OnConflict{DoNothing: true}).Create(goodsWindows).RowsAffected
}
// @Title 通过会员id获取数据
// @Param userId uint true "会员id"
func (g *GoodsWindow) GetListByUserId(userId uint, start, limit int) *[]GoodsWindow {
if userId <= 0 {
return &[]GoodsWindow{}
}
goodsWindows := []GoodsWindow{}
g.GetDb().Model(g).Where("user_id = ?", userId).Where("is_del = ?", 0).Limit(limit).Offset(start).Order("id desc").Find(&goodsWindows)
return &goodsWindows
}
// 获取会员橱柜商品数量
func (g *GoodsWindow) GetCountByUserId(userId uint) (result int64) {
if userId <= 0 {
return
}
g.GetDb().Model(g).Where("user_id = ?", userId).Where("is_del = ?", 0).Count(&result)
return
}
// 会员删除橱柜商品
func (g *GoodsWindow) DelByUserIdAndIds(userId uint, ids []int) int64 {
if userId <= 0 || len(ids) == 0 {
return 0
}
return g.GetDb().Model(g).Where("user_id = ?", userId).Where("goods_id in (?) and is_del = ?", ids, 0).Update("is_del", 1).RowsAffected
}