Commit cffaf298 by mushishixian

Merge branch 'ysx-在途库存-20220803' into dev

parents 0e7f9f90 e18ca191
package model package model
import ( import (
"github.com/tidwall/gjson" "github.com/tidwall/gjson"
) )
//联营sku结构体 //联营sku结构体
type LySku struct { type LySku struct {
LadderPrice []LadderPrice `json:"-"` LadderPrice []LadderPrice `json:"-"`
SpuId string `json:"spu_id"` SpuId string `json:"spu_id"`
OldGoodsId int64 `json:"old_goods_id"` OldGoodsId int64 `json:"old_goods_id"`
UpdateTime int64 `json:"update_time"` UpdateTime int64 `json:"update_time"`
CpTime int64 `json:"cp_time"` CpTime int64 `json:"cp_time"`
GoodsStatus int64 `json:"goods_status"` GoodsStatus int64 `json:"goods_status"`
GoodsType int64 `json:"goods_type"` GoodsType int64 `json:"goods_type"`
SupplierId int64 `json:"supplier_id"` SupplierId int64 `json:"supplier_id"`
Encoded string `json:"encoded"` Encoded string `json:"encoded"`
BatchSn string `json:"batch_sn"` BatchSn string `json:"batch_sn"`
Moq int64 `json:"moq"` Moq int64 `json:"moq"`
Mpq int64 `json:"mpq"` Mpq int64 `json:"mpq"`
Stock int64 `json:"stock"` Stock int64 `json:"stock"`
HkDeliveryTime string `json:"hk_delivery_time"` HkDeliveryTime string `json:"hk_delivery_time"`
CnDeliveryTime string `json:"cn_delivery_time"` CnDeliveryTime string `json:"cn_delivery_time"`
LadderPriceResult interface{} `json:"ladder_price"` LadderPriceResult interface{} `json:"ladder_price"`
GoodsImages string `json:"goods_images"` GoodsImages string `json:"goods_images"`
Canal string `json:"canal"` Canal string `json:"canal"`
IsExpire int `json:"is_expire,omitempty"` IsExpire int `json:"is_expire,omitempty"`
Packing string `json:"packing"` Packing string `json:"packing"`
GoodsId string `json:"goods_id"` GoodsId string `json:"goods_id"`
GoodsName string `json:"goods_name"` GoodsName string `json:"goods_name"`
BrandName string `json:"brand_name"` BrandName string `json:"brand_name"`
SupplierName string `json:"supplier_name"` SupplierName string `json:"supplier_name"`
Attrs interface{} `json:"attrs"` Attrs interface{} `json:"attrs"`
ScmBrand interface{} `json:"scm_brand"` ScmBrand interface{} `json:"scm_brand"`
AllowCoupon int `json:"allow_coupon"` AllowCoupon int `json:"allow_coupon"`
BrandId int64 `json:"brand_id"` BrandId int64 `json:"brand_id"`
//系数相关 //系数相关
Coefficient interface{} `json:"coefficient,omitempty"` Coefficient interface{} `json:"coefficient,omitempty"`
Original interface{} `json:"original_price,omitempty"` Original interface{} `json:"original_price,omitempty"`
SuppExtendFee interface{} `json:"supp_extend_fee"` SuppExtendFee interface{} `json:"supp_extend_fee"`
IsBuy int `json:"is_buy"` IsBuy int `json:"is_buy"`
//spu信息 //spu信息
ClassID1 int `json:"class_id1"` ClassID1 int `json:"class_id1"`
ClassID2 int `json:"class_id2"` ClassID2 int `json:"class_id2"`
ClassID3 int `json:"class_id3"` ClassID3 int `json:"class_id3"`
SpuName string `json:"spu_name"` SpuName string `json:"spu_name"`
Status int `json:"status"` Status int `json:"status"`
ImagesL string `json:"images_l"` ImagesL string `json:"images_l"`
Encap string `json:"encap"` Encap string `json:"encap"`
Pdf string `json:"pdf"` Pdf string `json:"pdf"`
SpuBrief string `json:"spu_brief"` SpuBrief string `json:"spu_brief"`
ClassName string `json:"class_name,omitempty"` ClassName string `json:"class_name,omitempty"`
ErpTax interface{} `json:"erp_tax"` ErpTax interface{} `json:"erp_tax"`
GoodsSn string `json:"goods_sn"` GoodsSn string `json:"goods_sn"`
GoodsDetails string `json:"goods_details"` GoodsDetails string `json:"goods_details"`
ClassName1 string `json:"class_name1,omitempty"` ClassName1 string `json:"class_name1,omitempty"`
ClassName2 string `json:"class_name2,omitempty"` ClassName2 string `json:"class_name2,omitempty"`
ClassName3 string `json:"class_name3,omitempty"` ClassName3 string `json:"class_name3,omitempty"`
Ratio float64 `json:"ratio,omitempty"` Ratio float64 `json:"ratio,omitempty"`
SpuDetail string `json:"spu_detail,omitempty"` SpuDetail string `json:"spu_detail,omitempty"`
AcType int `json:"ac_type"` AcType int `json:"ac_type"`
//活动信息 //活动信息
HasGiftActivity int `json:"has_gift_activity"` HasGiftActivity int `json:"has_gift_activity"`
GiftActivity GiftActivity `json:"gift_activity"` GiftActivity GiftActivity `json:"gift_activity"`
ActivityInfo PriceActivity `json:"activity_info"` ActivityInfo PriceActivity `json:"activity_info"`
StandardBrand StandardBrand `json:"standard_brand"` StandardBrand StandardBrand `json:"standard_brand"`
GoodsTag GoodsTag `json:"goods_tag"` GoodsTag GoodsTag `json:"goods_tag"`
} StockInfo interface{} `json:"stock_info"`
}
type PriceActivity struct {
ActivityCommon type PriceActivity struct {
Ratio float64 `json:"ratio,omitempty"` ActivityCommon
SignText string `json:"sign_text,omitempty"` Ratio float64 `json:"ratio,omitempty"`
Sign string `json:"sign,omitempty"` SignText string `json:"sign_text,omitempty"`
ShowName string `json:"show_name,omitempty"` Sign string `json:"sign,omitempty"`
} ShowName string `json:"show_name,omitempty"`
}
type GiftActivity struct {
ActivityCommon type GiftActivity struct {
CanAdminOrder interface{} `json:"can_admin_order"` ActivityCommon
ItemList []ActivityItem `json:"items,omitempty"` CanAdminOrder interface{} `json:"can_admin_order"`
} ItemList []ActivityItem `json:"items,omitempty"`
}
type ActivityCommon struct {
HasActivity bool `json:"-"` type ActivityCommon struct {
ActivityId int `json:"activity_id,omitempty"` HasActivity bool `json:"-"`
ActivityName string `json:"activity_name,omitempty"` ActivityId int `json:"activity_id,omitempty"`
AllowCoupon int `json:"-"` ActivityName string `json:"activity_name,omitempty"`
UserScope int `json:"user_scope,omitempty"` AllowCoupon int `json:"-"`
} UserScope int `json:"user_scope,omitempty"`
}
type StandardBrand struct {
StandardBrandId int `json:"standard_brand_id,omitempty"` type StandardBrand struct {
BrandName string `json:"brand_name,omitempty"` StandardBrandId int `json:"standard_brand_id,omitempty"`
BrandLogo string `json:"brand_logo,omitempty"` BrandName string `json:"brand_name,omitempty"`
} BrandLogo string `json:"brand_logo,omitempty"`
}
type GoodsTag struct {
GoodsLabel int `json:"goods_label,omitempty"` type GoodsTag struct {
GoodsLabelName string `json:"goods_label_name,omitempty"` GoodsLabel int `json:"goods_label,omitempty"`
GoodsTag []int `json:"goods_tag,omitempty"` GoodsLabelName string `json:"goods_label_name,omitempty"`
GoodsTagNames []string `json:"goods_tag_names,omitempty"` GoodsTag []int `json:"goods_tag,omitempty"`
} GoodsTagNames []string `json:"goods_tag_names,omitempty"`
}
//为什么不直接映射到结构,而要用gjson,因为redis存的数据结构不一定正常,可能类型不一致
func InitSkuData(sku string) (data LySku) { type StockInfo struct {
goodsSn := gjson.Get(sku, "goods_sn").String() Period string `json:"period" bson:"period"`
data.GoodsSn = goodsSn PeriodTime int `json:"-" bson:"period_time"`
PeriodTimeFormat string `json:"period_time"`
spuId := gjson.Get(sku, "spu_id").String() Stock int `json:"stock" bson:"stock"`
data.SpuId = spuId }
oldGoodsId := gjson.Get(sku, "old_goods_id").Int() //为什么不直接映射到结构,而要用gjson,因为redis存的数据结构不一定正常,可能类型不一致
data.OldGoodsId = oldGoodsId func InitSkuData(sku string) (data LySku) {
goodsSn := gjson.Get(sku, "goods_sn").String()
updateTime := gjson.Get(sku, "update_time").Int() data.GoodsSn = goodsSn
data.UpdateTime = updateTime
spuId := gjson.Get(sku, "spu_id").String()
goodsStatus := gjson.Get(sku, "goods_status").Int() data.SpuId = spuId
data.GoodsStatus = goodsStatus
oldGoodsId := gjson.Get(sku, "old_goods_id").Int()
goodsName := gjson.Get(sku, "goods_name").String() data.OldGoodsId = oldGoodsId
data.GoodsName = goodsName
updateTime := gjson.Get(sku, "update_time").Int()
goodsType := gjson.Get(sku, "goods_type").Int() data.UpdateTime = updateTime
data.GoodsType = goodsType
goodsStatus := gjson.Get(sku, "goods_status").Int()
supplierId := gjson.Get(sku, "supplier_id").Int() data.GoodsStatus = goodsStatus
data.SupplierId = supplierId
goodsName := gjson.Get(sku, "goods_name").String()
encoded := gjson.Get(sku, "encoded").String() data.GoodsName = goodsName
data.Encoded = encoded
goodsType := gjson.Get(sku, "goods_type").Int()
batchSn := gjson.Get(sku, "batch_sn").String() data.GoodsType = goodsType
data.BatchSn = batchSn
supplierId := gjson.Get(sku, "supplier_id").Int()
moq := gjson.Get(sku, "moq").Int() data.SupplierId = supplierId
data.Moq = moq
encoded := gjson.Get(sku, "encoded").String()
mpq := gjson.Get(sku, "mpq").Int() data.Encoded = encoded
data.Mpq = mpq
batchSn := gjson.Get(sku, "batch_sn").String()
stock := gjson.Get(sku, "stock").Int() data.BatchSn = batchSn
data.Stock = stock
moq := gjson.Get(sku, "moq").Int()
isExpire := gjson.Get(sku, "is_expire").Int() data.Moq = moq
data.IsExpire = int(isExpire)
mpq := gjson.Get(sku, "mpq").Int()
hkDeliveryTime := gjson.Get(sku, "hk_delivery_time").String() data.Mpq = mpq
data.HkDeliveryTime = hkDeliveryTime
stock := gjson.Get(sku, "stock").Int()
cnDeliveryTime := gjson.Get(sku, "cn_delivery_time").String() data.Stock = stock
data.CnDeliveryTime = cnDeliveryTime
isExpire := gjson.Get(sku, "is_expire").Int()
goodsDetail := gjson.Get(sku, "goods_details").String() data.IsExpire = int(isExpire)
data.GoodsDetails = goodsDetail
hkDeliveryTime := gjson.Get(sku, "hk_delivery_time").String()
goodsImages := gjson.Get(sku, "goods_images").String() data.HkDeliveryTime = hkDeliveryTime
data.GoodsImages = goodsImages
cnDeliveryTime := gjson.Get(sku, "cn_delivery_time").String()
canal := gjson.Get(sku, "canal").String() data.CnDeliveryTime = cnDeliveryTime
data.Canal = canal
goodsDetail := gjson.Get(sku, "goods_details").String()
//加上紧急判断,如果是立创(L0001175)的商品,就修改内部编码 data.GoodsDetails = goodsDetail
if data.Canal == "L0001175" {
data.Encoded = "10142-L" goodsImages := gjson.Get(sku, "goods_images").String()
} data.GoodsImages = goodsImages
cpTime := gjson.Get(sku, "cp_time").Int() canal := gjson.Get(sku, "canal").String()
data.CpTime = cpTime data.Canal = canal
LadderPriceStr := gjson.Get(sku, "ladder_price").String() //加上紧急判断,如果是立创(L0001175)的商品,就修改内部编码
data.LadderPrice = getLadderPrice(LadderPriceStr) if data.Canal == "L0001175" {
data.Original = getOriginPrice(LadderPriceStr) data.Encoded = "10142-L"
}
return
} cpTime := gjson.Get(sku, "cp_time").Int()
data.CpTime = cpTime
//获取联营商品的阶梯价
func getLadderPrice(ladderPriceStr string) (ladderPrice []LadderPrice) { LadderPriceStr := gjson.Get(sku, "ladder_price").String()
ladderPriceArr := gjson.Parse(ladderPriceStr).Array() data.LadderPrice = getLadderPrice(LadderPriceStr)
for _, price := range ladderPriceArr { data.Original = getOriginPrice(LadderPriceStr)
ladderPrice = append(ladderPrice, LadderPrice{
Purchases: price.Get("purchases").Int(), return
PriceUs: price.Get("price_us").Float(), }
PriceCn: price.Get("price_cn").Float(),
PriceAc: price.Get("price_ac").Float(), //获取联营商品的阶梯价
CostPrice: price.Get("cost_price").Float(), func getLadderPrice(ladderPriceStr string) (ladderPrice []LadderPrice) {
}) ladderPriceArr := gjson.Parse(ladderPriceStr).Array()
} for _, price := range ladderPriceArr {
if len(ladderPrice) == 0 { ladderPrice = append(ladderPrice, LadderPrice{
ladderPrice = []LadderPrice{} Purchases: price.Get("purchases").Int(),
return PriceUs: price.Get("price_us").Float(),
} PriceCn: price.Get("price_cn").Float(),
return PriceAc: price.Get("price_ac").Float(),
} CostPrice: price.Get("cost_price").Float(),
})
//获取原始价格 }
func getOriginPrice(ladderPriceStr string) (ladderPrice []OriginPrice) { if len(ladderPrice) == 0 {
ladderPriceArr := gjson.Parse(ladderPriceStr).Array() ladderPrice = []LadderPrice{}
for _, price := range ladderPriceArr { return
ladderPrice = append(ladderPrice, OriginPrice{ }
Purchases: price.Get("purchases").Int(), return
PriceUs: price.Get("price_us").Float(), }
PriceCn: price.Get("price_cn").Float(),
PriceAc: price.Get("price_ac").Float(), //获取原始价格
CostPrice: price.Get("cost_price").Float(), func getOriginPrice(ladderPriceStr string) (ladderPrice []OriginPrice) {
}) ladderPriceArr := gjson.Parse(ladderPriceStr).Array()
} for _, price := range ladderPriceArr {
if len(ladderPrice) == 0 { ladderPrice = append(ladderPrice, OriginPrice{
ladderPrice = []OriginPrice{} Purchases: price.Get("purchases").Int(),
return PriceUs: price.Get("price_us").Float(),
} PriceCn: price.Get("price_cn").Float(),
return PriceAc: price.Get("price_ac").Float(),
} CostPrice: price.Get("cost_price").Float(),
})
}
if len(ladderPrice) == 0 {
ladderPrice = []OriginPrice{}
return
}
return
}
package vars package vars
//商品类型字段 //商品类型字段
var GoodsLabel = map[int]string{ var GoodsLabel = map[int]string{
1: "国内现货", 1: "国内现货",
2: "猎芯期货", 2: "猎芯期货",
3: "国际现货", 3: "国际现货",
} }
//商品标签对应的展示 //商品标签对应的展示
//1精选,2原厂直供,3认证,4当天发货 //1精选,2原厂直供,3认证,4当天发货
var GoodsTags = map[int]string{ var GoodsTags = map[int]string{
1: "精选", 1: "精选",
2: "原厂直供", 2: "原厂直供",
3: "认证", 3: "认证",
4: "当天发货", 4: "当天发货",
} }
var StockInfoSupplierMap = map[int64]string{
6: "element14",
7: "digikey",
14: "mouser",
21: "rs",
1672: "master",
}
package service package service
import ( import (
"fmt"
"go_sku_server/model" "go_sku_server/model"
"go_sku_server/pkg/gredis" "go_sku_server/pkg/gredis"
"go_sku_server/service/sorter" "go_sku_server/service/sorter"
...@@ -37,7 +36,10 @@ func (ls *LyService) LyGoodsDetail(ctx *gin.Context, goodsIds []string, ch chan ...@@ -37,7 +36,10 @@ func (ls *LyService) LyGoodsDetail(ctx *gin.Context, goodsIds []string, ch chan
redisConn.Close() redisConn.Close()
}() }()
fast := ctx.Request.FormValue("power[fast]") fast := ctx.Request.FormValue("power[fast]")
//是否展示属性
showAttr := ctx.Request.FormValue("show_attr") showAttr := ctx.Request.FormValue("show_attr")
//是否展示在途库存
showStockInfo := ctx.Request.FormValue("show_stock_info")
//批量获取商品详情 //批量获取商品详情
skuArr := gredis.Hmget("default_r", "sku", goodsIds) skuArr := gredis.Hmget("default_r", "sku", goodsIds)
//为了性能着想,这边也先去批量获取spu的信息 //为了性能着想,这边也先去批量获取spu的信息
...@@ -85,7 +87,6 @@ func (ls *LyService) LyGoodsDetail(ctx *gin.Context, goodsIds []string, ch chan ...@@ -85,7 +87,6 @@ func (ls *LyService) LyGoodsDetail(ctx *gin.Context, goodsIds []string, ch chan
brandId := gjson.Get(spu, "brand_id").Int() brandId := gjson.Get(spu, "brand_id").Int()
brandName, _ := redis.String(redisConn.Do("HGET", "brand", brandId)) brandName, _ := redis.String(redisConn.Do("HGET", "brand", brandId))
sku.BrandName = brandName sku.BrandName = brandName
fmt.Println(showAttr)
//获取税务信息 //获取税务信息
if fast != "1" { //仅提供价格和库存 if fast != "1" { //仅提供价格和库存
if sku.GoodsName != "" && brandId != 0 { if sku.GoodsName != "" && brandId != 0 {
...@@ -101,6 +102,16 @@ func (ls *LyService) LyGoodsDetail(ctx *gin.Context, goodsIds []string, ch chan ...@@ -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