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.
83 lines
2.1 KiB
83 lines
2.1 KiB
package goods
|
|
|
|
import (
|
|
"encoding/json"
|
|
"live/app/constant"
|
|
"live/app/lib"
|
|
"live/app/lib/db"
|
|
"live/app/lib/recook"
|
|
"live/app/model/promotion"
|
|
"time"
|
|
)
|
|
|
|
type Goods struct {
|
|
}
|
|
|
|
// @Title 商品列表 关键字jiansuo
|
|
func (g *Goods) GetGoodsList(keyword string, page lib.Page) *recook.GoodsList {
|
|
goodsInfos, err := recook.Goods.GetListByKeyword(keyword, page.GetPage(), page.GetLimit())
|
|
if err != nil {
|
|
return &recook.GoodsList{}
|
|
}
|
|
return goodsInfos
|
|
}
|
|
|
|
// @Title 品牌列表
|
|
func (g *Goods) BrandList(page lib.Page) *recook.BrandList {
|
|
list, _ := recook.Goods.GetBrandList(page.GetPage(), page.GetLimit())
|
|
return list
|
|
}
|
|
|
|
// @Title 指定品牌商品列表
|
|
func (g *Goods) GoodsListByBrandId(brandId uint, page lib.Page) *recook.GoodsList {
|
|
list, _ := recook.Goods.GetListByBrandId(brandId, page.GetPage(), page.GetLimit())
|
|
return list
|
|
}
|
|
|
|
// @Title 指定品牌商品列表
|
|
func (g *Goods) HotGoods(page lib.Page) (result []recook.GoodsInfo, dataLen int) {
|
|
data := db.Redis.Get(constant.RedisKeyPromotionGoodsList).Val()
|
|
promotionGoods := []promotion.PromotionGoods{}
|
|
json.Unmarshal([]byte(data), &promotionGoods)
|
|
day := time.Now().Format("2006-01-02")
|
|
if len(promotionGoods) == 0 || promotionGoods[0].PromotionStartDate.Time.Format("2006-01-02") != day {
|
|
promotionGoodsModel := &promotion.PromotionGoods{}
|
|
lists := promotionGoodsModel.GetDayAll()
|
|
data := []promotion.PromotionGoods{}
|
|
index := 0
|
|
lastId := uint(0)
|
|
for _, list := range lists {
|
|
if lastId != list.PromotionTimeItemId {
|
|
index = 1
|
|
lastId = list.PromotionTimeItemId
|
|
}
|
|
if index > 5 {
|
|
continue
|
|
}
|
|
data = append(data, list)
|
|
index++
|
|
}
|
|
dataStr, _ := json.Marshal(data)
|
|
db.Redis.Set(constant.RedisKeyPromotionGoodsList, string(dataStr), time.Hour*24)
|
|
promotionGoods = data
|
|
}
|
|
dataLen = len(promotionGoods)
|
|
start := page.GetStart()
|
|
if dataLen >= start {
|
|
end := page.GetLimit() + start
|
|
if end > dataLen {
|
|
end = dataLen
|
|
}
|
|
goodsIds := []uint{}
|
|
for _, goods := range promotionGoods[start:end] {
|
|
goodsIds = append(goodsIds, goods.GoodsId)
|
|
}
|
|
ids, err := recook.Goods.GetListByIds(goodsIds)
|
|
if err != nil {
|
|
return
|
|
}
|
|
result = *ids
|
|
}
|
|
return
|
|
}
|