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.5 KiB
63 lines
1.5 KiB
package goods
|
|
|
|
import (
|
|
"live/app/lib"
|
|
"live/app/lib/recook"
|
|
"live/app/model/goods"
|
|
)
|
|
|
|
type Cupboard struct {
|
|
}
|
|
|
|
// @Title 获取会员橱窗列表
|
|
// @Param uid uint true "会员id"
|
|
// @Param listArgs Listargs true "筛选分页参数"
|
|
func (c *Cupboard) GetList(userId uint, page lib.Page) (result *[]recook.GoodsInfo, count int64) {
|
|
goodsWindowModel := &goods.GoodsWindow{}
|
|
result = &[]recook.GoodsInfo{}
|
|
|
|
start := (page.GetPage() - 1) * page.GetLimit()
|
|
count = goodsWindowModel.GetCountByUserId(userId)
|
|
if count <= int64(start) {
|
|
// 没有数据,不需要查库
|
|
return
|
|
}
|
|
goodsWindows := goodsWindowModel.GetListByUserId(userId, start, page.GetLimit())
|
|
if len(*goodsWindows) == 0 {
|
|
// 未查询到数据
|
|
return
|
|
}
|
|
goodsIds := []uint{}
|
|
for _, goodsWindow := range *goodsWindows {
|
|
goodsIds = append(goodsIds, goodsWindow.GoodsId)
|
|
}
|
|
goodsInfo, err := recook.Goods.GetListByIds(goodsIds)
|
|
if err != nil {
|
|
return
|
|
}
|
|
return goodsInfo, count
|
|
}
|
|
|
|
// @Title 根据ids批量删除会员橱窗数据
|
|
func (c *Cupboard) Delete(uid uint, ids []int) (err bool) {
|
|
upRow := (&goods.GoodsWindow{}).DelByUserIdAndIds(uid, ids)
|
|
if upRow > 0 {
|
|
return true
|
|
} else {
|
|
return false
|
|
}
|
|
}
|
|
|
|
// @Title 添加会员橱柜数据
|
|
// @Param uid int true "会员id"
|
|
func (c *Cupboard) Add(userId uint, goodsIds []uint) int64 {
|
|
data := []goods.GoodsWindow{}
|
|
for _, goodsId := range goodsIds {
|
|
data = append(data, goods.GoodsWindow{
|
|
UserId: userId,
|
|
GoodsId: goodsId,
|
|
})
|
|
}
|
|
return (&goods.GoodsWindow{}).CreateAll(&data)
|
|
}
|