Commit 4d95c2a2 by 杨树贤

展示spu详情

parent 9279af23
Showing with 31 additions and 0 deletions
......@@ -77,6 +77,7 @@ type LySku struct {
GoodsTag GoodsTag `json:"goods_tag"`
StockInfo interface{} `json:"stock_info"`
SkuDetail string `json:"sku_detail"`
SpuExtra SpuExtra `json:"spu_extra"`
Eccn string `json:"eccn"`
DiscountRatio DiscountRatio `json:"discount_ratio"`
PriceRatioSort int `json:"price_ratio_sort"`
......@@ -141,6 +142,15 @@ type StockInfo struct {
Stock int `json:"stock" bson:"stock"`
}
type SpuExtra struct {
ImageList []struct {
Name string `bson:"name" json:"name"`
Thumbnail string `bson:"thumbnail" json:"thumbnail"`
} `bson:"image_list" json:"image_list"`
SpuDetail string `bson:"spu_detail" json:"spu_detail"`
SpuId string `bson:"spu_id" json:"spu_id"`
}
// 为什么不直接映射到结构,而要用gjson,因为redis存的数据结构不一定正常,可能类型不一致
func InitSkuData(sku string) (data LySku) {
......
......@@ -48,6 +48,8 @@ func (ls *LyService) LyGoodsDetail(ctx *gin.Context, goodsIds []string, ch chan
showStockInfo := ctx.Request.FormValue("show_stock_info")
//是否展示sku详情
showSkuDetail := ctx.Request.FormValue("show_sku_detail")
//是否展示spu额外信息
showSpuExtra := ctx.Request.FormValue("show_spu_extra")
//批量获取商品详情
skuArr := gredis.Hmget("default_r", "sku", goodsIds)
......@@ -120,6 +122,11 @@ func (ls *LyService) LyGoodsDetail(ctx *gin.Context, goodsIds []string, ch chan
sku.SkuDetail = ls.GetSkuDetail(sku.GoodsId)
}
//是否需要返回spu额外信息
if showSpuExtra == "1" {
sku.SpuExtra = ls.GetSpuExtra(sku.SpuId)
}
//格式化为对象返回
if sku.StockInfo == nil {
type StockInfoResult struct {
......@@ -271,3 +278,17 @@ func (ls *LyService) GetSkuDetail(skuId string) string {
}
return skuDetail.Detail
}
// 获取spu_extra
func (ls *LyService) GetSpuExtra(spuId string) (spuExtra model.SpuExtra) {
mongodb := mongo.Conn("default")
defer func() {
mongodb.Close()
}()
err := mongodb.DB("ichunt").C("spu_extra").Find(bson.M{"spu_id": spuId}).One(&spuExtra)
if err != nil && err != mgo.ErrNotFound {
logger.Select("sku_query").Error(err.Error())
}
return spuExtra
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment