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.
54 lines
1.6 KiB
54 lines
1.6 KiB
5 years ago
|
package goods
|
||
5 years ago
|
|
||
|
import (
|
||
|
"github.com/golangkit/formatime"
|
||
|
"live/app/lib/db"
|
||
|
)
|
||
|
|
||
|
type GoodsWindow struct {
|
||
5 years ago
|
db.BaseModel
|
||
5 years ago
|
Id uint `gorm:"column:id" json:"id"`
|
||
|
UserId uint `gorm:"column:user_id" json:"user_id"`
|
||
|
GoodsId uint `gorm:"column:goods_id" json:"goods_id"`
|
||
|
CreatedAt formatime.Second `gorm:"column:created_at" json:"created_at"`
|
||
|
UpdatedAt formatime.Second `gorm:"column:updated_at" json:"updated_at"`
|
||
|
IsDel int `gorm:"column:is_del" json:"is_del"`
|
||
|
}
|
||
|
|
||
|
// 插入
|
||
|
func (g *GoodsWindow) Create(goodsWindow *GoodsWindow) uint {
|
||
5 years ago
|
g.GetDb().Create(goodsWindow)
|
||
5 years ago
|
if goodsWindow.Id > 0 {
|
||
|
return goodsWindow.Id
|
||
|
}
|
||
|
return 0
|
||
|
}
|
||
|
|
||
|
// @Title 通过会员id获取数据
|
||
|
// @Param userId uint true "会员id"
|
||
|
func (g *GoodsWindow) GetListByUserId(userId uint, start, limit int) *[]GoodsWindow {
|
||
|
if userId <= 0 {
|
||
|
return &[]GoodsWindow{}
|
||
|
}
|
||
|
goodsWindows := []GoodsWindow{}
|
||
5 years ago
|
g.GetDb().Model(g).Where(GoodsWindow{UserId: userId}).Where("is_del = ?", 0).Limit(limit).Offset(start).Order("id desc").Find(&goodsWindows)
|
||
5 years ago
|
return &goodsWindows
|
||
|
}
|
||
|
|
||
|
// 获取会员橱柜商品数量
|
||
|
func (g *GoodsWindow) GetCountByUserId(userId uint) (result int64) {
|
||
|
if userId <= 0 {
|
||
|
return
|
||
|
}
|
||
5 years ago
|
g.GetDb().Model(g).Where(GoodsWindow{UserId: userId}).Where("is_del = ?", 0).Count(&result)
|
||
5 years ago
|
return
|
||
|
}
|
||
|
|
||
|
// 会员删除橱柜商品
|
||
|
func (g *GoodsWindow) DelByUserIdAndIds(userId uint, ids []int) int64 {
|
||
|
if userId <= 0 || len(ids) == 0 {
|
||
|
return 0
|
||
|
}
|
||
5 years ago
|
return g.GetDb().Model(g).Where(GoodsWindow{UserId: userId}).Where("id in (?) and is_del = ?", ids, 0).Update("is_del", 2).RowsAffected
|
||
5 years ago
|
}
|