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

package goods
import (
"live/app/lib"
"live/app/lib/recook"
"live/app/model/goods"
)
type Car struct {
}
// @Title 获取会员直播车列表
// @Param uid uint true "会员id"
// @Param listArgs Listargs true "筛选分页参数"
func (c *Car) GetList(userId uint, page lib.Page) (result *[]recook.GoodsInfo, count int64) {
goodsCarModel := &goods.GoodsCar{}
result = &[]recook.GoodsInfo{}
start := (page.GetPage() - 1) * page.GetLimit()
count = goodsCarModel.GetCountByUserId(userId)
if count <= int64(start) {
// 没有数据,不需要查库
return
}
goodsWindows := goodsCarModel.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 *Car) Delete(uid uint, ids []int) (err bool) {
upRow := (&goods.GoodsCar{}).DelByUserIdAndIds(uid, ids)
if upRow > 0 {
return true
} else {
return false
}
}
// @Title 添加会员直播车数据
// @Param uid int true "会员id"
func (c *Car) Add(userId uint, goodsIds []uint) int64 {
data := []goods.GoodsCar{}
for _, goodsId := range goodsIds {
data = append(data, goods.GoodsCar{
UserId: userId,
GoodsId: goodsId,
})
}
return (&goods.GoodsCar{}).CreateAll(&data)
}