Commit e18ca191 by mushishixian

在途库存显示

parent a06f158d
package vars
//商品类型字段
var GoodsLabel = map[int]string{
1: "国内现货",
2: "猎芯期货",
3: "国际现货",
}
//商品标签对应的展示
//1精选,2原厂直供,3认证,4当天发货
var GoodsTags = map[int]string{
1: "精选",
2: "原厂直供",
3: "认证",
4: "当天发货",
}
package vars
//商品类型字段
var GoodsLabel = map[int]string{
1: "国内现货",
2: "猎芯期货",
3: "国际现货",
}
//商品标签对应的展示
//1精选,2原厂直供,3认证,4当天发货
var GoodsTags = map[int]string{
1: "精选",
2: "原厂直供",
3: "认证",
4: "当天发货",
}
var StockInfoSupplierMap = map[int64]string{
6: "element14",
7: "digikey",
14: "mouser",
21: "rs",
1672: "master",
}
package service
import (
"fmt"
"go_sku_server/model"
"go_sku_server/pkg/gredis"
"go_sku_server/service/sorter"
......@@ -37,7 +36,10 @@ func (ls *LyService) LyGoodsDetail(ctx *gin.Context, goodsIds []string, ch chan
redisConn.Close()
}()
fast := ctx.Request.FormValue("power[fast]")
//是否展示属性
showAttr := ctx.Request.FormValue("show_attr")
//是否展示在途库存
showStockInfo := ctx.Request.FormValue("show_stock_info")
//批量获取商品详情
skuArr := gredis.Hmget("default_r", "sku", goodsIds)
//为了性能着想,这边也先去批量获取spu的信息
......@@ -85,7 +87,6 @@ func (ls *LyService) LyGoodsDetail(ctx *gin.Context, goodsIds []string, ch chan
brandId := gjson.Get(spu, "brand_id").Int()
brandName, _ := redis.String(redisConn.Do("HGET", "brand", brandId))
sku.BrandName = brandName
fmt.Println(showAttr)
//获取税务信息
if fast != "1" { //仅提供价格和库存
if sku.GoodsName != "" && brandId != 0 {
......@@ -101,6 +102,16 @@ 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)
}
//格式化为对象返回
if sku.StockInfo == nil {
type StockInfoResult struct {
}
sku.StockInfo = new(StockInfoResult)
}
//获取供应链标准品牌
//什么是供应链的标准品牌 供应链那边报关的时候要求他们的标准品牌,所以要吧自己的品牌映射上去
//继来那边对接的标准品牌(下单的时候)
......
package service
import (
"go_sku_server/model"
"go_sku_server/pkg/logger"
"go_sku_server/pkg/mongo"
"go_sku_server/pkg/vars"
"time"
"gopkg.in/mgo.v2"
"gopkg.in/mgo.v2/bson"
)
//在途库存服务
type StockInfoService struct {
}
func (ss *LyService) getStockInfo(supplierId, oldGoodsId int64) interface{} {
var stockInfo model.StockInfo
//去mongodb获取在途库存信息
mongodb := mongo.Conn("default")
defer func() {
mongodb.Close()
}()
//还要判断去哪个集合取值
collectionName := vars.StockInfoSupplierMap[supplierId]
type Goods struct {
StockInfo model.StockInfo `bson:"stock_info"`
}
var goods Goods
err := mongodb.DB("ichunt").C(collectionName).Find(bson.M{"goods_id": int(oldGoodsId)}).One(&goods)
if err != nil && err != mgo.ErrNotFound {
logger.Select("sku_query").Error(err.Error())
}
stockInfo = goods.StockInfo
if stockInfo.PeriodTime > 0 {
stockInfo.PeriodTimeFormat = time.Unix(int64(stockInfo.PeriodTime), 0).Format("2006-01-02")
}
if stockInfo.Stock != 0 || stockInfo.PeriodTime != 0 {
return stockInfo
}
return nil
}
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