Commit 9279af23 by 杨树贤

添加sku_detail返回

parent 4853474c
Showing with 32 additions and 0 deletions
......@@ -76,6 +76,7 @@ type LySku struct {
StandardBrand StandardBrand `json:"standard_brand"`
GoodsTag GoodsTag `json:"goods_tag"`
StockInfo interface{} `json:"stock_info"`
SkuDetail string `json:"sku_detail"`
Eccn string `json:"eccn"`
DiscountRatio DiscountRatio `json:"discount_ratio"`
PriceRatioSort int `json:"price_ratio_sort"`
......
......@@ -3,7 +3,11 @@ package service
import (
"go_sku_server/model"
"go_sku_server/pkg/gredis"
"go_sku_server/pkg/logger"
"go_sku_server/pkg/mongo"
"go_sku_server/service/sorter"
"gopkg.in/mgo.v2"
"gopkg.in/mgo.v2/bson"
"sort"
"sync"
......@@ -42,6 +46,8 @@ func (ls *LyService) LyGoodsDetail(ctx *gin.Context, goodsIds []string, ch chan
showAttr := ctx.Request.FormValue("show_attr")
//是否展示在途库存
showStockInfo := ctx.Request.FormValue("show_stock_info")
//是否展示sku详情
showSkuDetail := ctx.Request.FormValue("show_sku_detail")
//批量获取商品详情
skuArr := gredis.Hmget("default_r", "sku", goodsIds)
......@@ -108,6 +114,12 @@ func (ls *LyService) LyGoodsDetail(ctx *gin.Context, goodsIds []string, ch chan
if showStockInfo == "1" && sku.OldGoodsId != 0 {
sku.StockInfo = ls.getStockInfo(sku.SupplierId, sku.OldGoodsId)
}
//判断是否需要返回sku详情
if showSkuDetail == "1" {
sku.SkuDetail = ls.GetSkuDetail(sku.GoodsId)
}
//格式化为对象返回
if sku.StockInfo == nil {
type StockInfoResult struct {
......@@ -240,3 +252,22 @@ func (ls *LyService) GetActivity(sku model.LySku) model.LySku {
}
return sku
}
// 获取sku_detail
func (ls *LyService) GetSkuDetail(skuId string) string {
mongodb := mongo.Conn("default")
defer func() {
mongodb.Close()
}()
var skuDetail struct {
SkuId string `bson:"sku_id"`
Detail string `bson:"detail"`
}
err := mongodb.DB("ichunt").C("sku_detail").Find(bson.M{"sku_id": skuId}).One(&skuDetail)
if err != nil && err != mgo.ErrNotFound {
logger.Select("sku_query").Error(err.Error())
}
return skuDetail.Detail
}
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