Commit cffaf298 by mushishixian

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

parents 0e7f9f90 e18ca191
package model
import (
"github.com/tidwall/gjson"
)
//联营sku结构体
type LySku struct {
LadderPrice []LadderPrice `json:"-"`
SpuId string `json:"spu_id"`
OldGoodsId int64 `json:"old_goods_id"`
UpdateTime int64 `json:"update_time"`
CpTime int64 `json:"cp_time"`
GoodsStatus int64 `json:"goods_status"`
GoodsType int64 `json:"goods_type"`
SupplierId int64 `json:"supplier_id"`
Encoded string `json:"encoded"`
BatchSn string `json:"batch_sn"`
Moq int64 `json:"moq"`
Mpq int64 `json:"mpq"`
Stock int64 `json:"stock"`
HkDeliveryTime string `json:"hk_delivery_time"`
CnDeliveryTime string `json:"cn_delivery_time"`
LadderPriceResult interface{} `json:"ladder_price"`
GoodsImages string `json:"goods_images"`
Canal string `json:"canal"`
IsExpire int `json:"is_expire,omitempty"`
Packing string `json:"packing"`
GoodsId string `json:"goods_id"`
GoodsName string `json:"goods_name"`
BrandName string `json:"brand_name"`
SupplierName string `json:"supplier_name"`
Attrs interface{} `json:"attrs"`
ScmBrand interface{} `json:"scm_brand"`
AllowCoupon int `json:"allow_coupon"`
BrandId int64 `json:"brand_id"`
//系数相关
Coefficient interface{} `json:"coefficient,omitempty"`
Original interface{} `json:"original_price,omitempty"`
SuppExtendFee interface{} `json:"supp_extend_fee"`
IsBuy int `json:"is_buy"`
//spu信息
ClassID1 int `json:"class_id1"`
ClassID2 int `json:"class_id2"`
ClassID3 int `json:"class_id3"`
SpuName string `json:"spu_name"`
Status int `json:"status"`
ImagesL string `json:"images_l"`
Encap string `json:"encap"`
Pdf string `json:"pdf"`
SpuBrief string `json:"spu_brief"`
ClassName string `json:"class_name,omitempty"`
ErpTax interface{} `json:"erp_tax"`
GoodsSn string `json:"goods_sn"`
GoodsDetails string `json:"goods_details"`
ClassName1 string `json:"class_name1,omitempty"`
ClassName2 string `json:"class_name2,omitempty"`
ClassName3 string `json:"class_name3,omitempty"`
Ratio float64 `json:"ratio,omitempty"`
SpuDetail string `json:"spu_detail,omitempty"`
AcType int `json:"ac_type"`
//活动信息
HasGiftActivity int `json:"has_gift_activity"`
GiftActivity GiftActivity `json:"gift_activity"`
ActivityInfo PriceActivity `json:"activity_info"`
StandardBrand StandardBrand `json:"standard_brand"`
GoodsTag GoodsTag `json:"goods_tag"`
}
type PriceActivity struct {
ActivityCommon
Ratio float64 `json:"ratio,omitempty"`
SignText string `json:"sign_text,omitempty"`
Sign string `json:"sign,omitempty"`
ShowName string `json:"show_name,omitempty"`
}
type GiftActivity struct {
ActivityCommon
CanAdminOrder interface{} `json:"can_admin_order"`
ItemList []ActivityItem `json:"items,omitempty"`
}
type ActivityCommon struct {
HasActivity bool `json:"-"`
ActivityId int `json:"activity_id,omitempty"`
ActivityName string `json:"activity_name,omitempty"`
AllowCoupon int `json:"-"`
UserScope int `json:"user_scope,omitempty"`
}
type StandardBrand struct {
StandardBrandId int `json:"standard_brand_id,omitempty"`
BrandName string `json:"brand_name,omitempty"`
BrandLogo string `json:"brand_logo,omitempty"`
}
type GoodsTag struct {
GoodsLabel int `json:"goods_label,omitempty"`
GoodsLabelName string `json:"goods_label_name,omitempty"`
GoodsTag []int `json:"goods_tag,omitempty"`
GoodsTagNames []string `json:"goods_tag_names,omitempty"`
}
//为什么不直接映射到结构,而要用gjson,因为redis存的数据结构不一定正常,可能类型不一致
func InitSkuData(sku string) (data LySku) {
goodsSn := gjson.Get(sku, "goods_sn").String()
data.GoodsSn = goodsSn
spuId := gjson.Get(sku, "spu_id").String()
data.SpuId = spuId
oldGoodsId := gjson.Get(sku, "old_goods_id").Int()
data.OldGoodsId = oldGoodsId
updateTime := gjson.Get(sku, "update_time").Int()
data.UpdateTime = updateTime
goodsStatus := gjson.Get(sku, "goods_status").Int()
data.GoodsStatus = goodsStatus
goodsName := gjson.Get(sku, "goods_name").String()
data.GoodsName = goodsName
goodsType := gjson.Get(sku, "goods_type").Int()
data.GoodsType = goodsType
supplierId := gjson.Get(sku, "supplier_id").Int()
data.SupplierId = supplierId
encoded := gjson.Get(sku, "encoded").String()
data.Encoded = encoded
batchSn := gjson.Get(sku, "batch_sn").String()
data.BatchSn = batchSn
moq := gjson.Get(sku, "moq").Int()
data.Moq = moq
mpq := gjson.Get(sku, "mpq").Int()
data.Mpq = mpq
stock := gjson.Get(sku, "stock").Int()
data.Stock = stock
isExpire := gjson.Get(sku, "is_expire").Int()
data.IsExpire = int(isExpire)
hkDeliveryTime := gjson.Get(sku, "hk_delivery_time").String()
data.HkDeliveryTime = hkDeliveryTime
cnDeliveryTime := gjson.Get(sku, "cn_delivery_time").String()
data.CnDeliveryTime = cnDeliveryTime
goodsDetail := gjson.Get(sku, "goods_details").String()
data.GoodsDetails = goodsDetail
goodsImages := gjson.Get(sku, "goods_images").String()
data.GoodsImages = goodsImages
canal := gjson.Get(sku, "canal").String()
data.Canal = canal
//加上紧急判断,如果是立创(L0001175)的商品,就修改内部编码
if data.Canal == "L0001175" {
data.Encoded = "10142-L"
}
cpTime := gjson.Get(sku, "cp_time").Int()
data.CpTime = cpTime
LadderPriceStr := gjson.Get(sku, "ladder_price").String()
data.LadderPrice = getLadderPrice(LadderPriceStr)
data.Original = getOriginPrice(LadderPriceStr)
return
}
//获取联营商品的阶梯价
func getLadderPrice(ladderPriceStr string) (ladderPrice []LadderPrice) {
ladderPriceArr := gjson.Parse(ladderPriceStr).Array()
for _, price := range ladderPriceArr {
ladderPrice = append(ladderPrice, LadderPrice{
Purchases: price.Get("purchases").Int(),
PriceUs: price.Get("price_us").Float(),
PriceCn: price.Get("price_cn").Float(),
PriceAc: price.Get("price_ac").Float(),
CostPrice: price.Get("cost_price").Float(),
})
}
if len(ladderPrice) == 0 {
ladderPrice = []LadderPrice{}
return
}
return
}
//获取原始价格
func getOriginPrice(ladderPriceStr string) (ladderPrice []OriginPrice) {
ladderPriceArr := gjson.Parse(ladderPriceStr).Array()
for _, price := range ladderPriceArr {
ladderPrice = append(ladderPrice, OriginPrice{
Purchases: price.Get("purchases").Int(),
PriceUs: price.Get("price_us").Float(),
PriceCn: price.Get("price_cn").Float(),
PriceAc: price.Get("price_ac").Float(),
CostPrice: price.Get("cost_price").Float(),
})
}
if len(ladderPrice) == 0 {
ladderPrice = []OriginPrice{}
return
}
return
}
package model
import (
"github.com/tidwall/gjson"
)
//联营sku结构体
type LySku struct {
LadderPrice []LadderPrice `json:"-"`
SpuId string `json:"spu_id"`
OldGoodsId int64 `json:"old_goods_id"`
UpdateTime int64 `json:"update_time"`
CpTime int64 `json:"cp_time"`
GoodsStatus int64 `json:"goods_status"`
GoodsType int64 `json:"goods_type"`
SupplierId int64 `json:"supplier_id"`
Encoded string `json:"encoded"`
BatchSn string `json:"batch_sn"`
Moq int64 `json:"moq"`
Mpq int64 `json:"mpq"`
Stock int64 `json:"stock"`
HkDeliveryTime string `json:"hk_delivery_time"`
CnDeliveryTime string `json:"cn_delivery_time"`
LadderPriceResult interface{} `json:"ladder_price"`
GoodsImages string `json:"goods_images"`
Canal string `json:"canal"`
IsExpire int `json:"is_expire,omitempty"`
Packing string `json:"packing"`
GoodsId string `json:"goods_id"`
GoodsName string `json:"goods_name"`
BrandName string `json:"brand_name"`
SupplierName string `json:"supplier_name"`
Attrs interface{} `json:"attrs"`
ScmBrand interface{} `json:"scm_brand"`
AllowCoupon int `json:"allow_coupon"`
BrandId int64 `json:"brand_id"`
//系数相关
Coefficient interface{} `json:"coefficient,omitempty"`
Original interface{} `json:"original_price,omitempty"`
SuppExtendFee interface{} `json:"supp_extend_fee"`
IsBuy int `json:"is_buy"`
//spu信息
ClassID1 int `json:"class_id1"`
ClassID2 int `json:"class_id2"`
ClassID3 int `json:"class_id3"`
SpuName string `json:"spu_name"`
Status int `json:"status"`
ImagesL string `json:"images_l"`
Encap string `json:"encap"`
Pdf string `json:"pdf"`
SpuBrief string `json:"spu_brief"`
ClassName string `json:"class_name,omitempty"`
ErpTax interface{} `json:"erp_tax"`
GoodsSn string `json:"goods_sn"`
GoodsDetails string `json:"goods_details"`
ClassName1 string `json:"class_name1,omitempty"`
ClassName2 string `json:"class_name2,omitempty"`
ClassName3 string `json:"class_name3,omitempty"`
Ratio float64 `json:"ratio,omitempty"`
SpuDetail string `json:"spu_detail,omitempty"`
AcType int `json:"ac_type"`
//活动信息
HasGiftActivity int `json:"has_gift_activity"`
GiftActivity GiftActivity `json:"gift_activity"`
ActivityInfo PriceActivity `json:"activity_info"`
StandardBrand StandardBrand `json:"standard_brand"`
GoodsTag GoodsTag `json:"goods_tag"`
StockInfo interface{} `json:"stock_info"`
}
type PriceActivity struct {
ActivityCommon
Ratio float64 `json:"ratio,omitempty"`
SignText string `json:"sign_text,omitempty"`
Sign string `json:"sign,omitempty"`
ShowName string `json:"show_name,omitempty"`
}
type GiftActivity struct {
ActivityCommon
CanAdminOrder interface{} `json:"can_admin_order"`
ItemList []ActivityItem `json:"items,omitempty"`
}
type ActivityCommon struct {
HasActivity bool `json:"-"`
ActivityId int `json:"activity_id,omitempty"`
ActivityName string `json:"activity_name,omitempty"`
AllowCoupon int `json:"-"`
UserScope int `json:"user_scope,omitempty"`
}
type StandardBrand struct {
StandardBrandId int `json:"standard_brand_id,omitempty"`
BrandName string `json:"brand_name,omitempty"`
BrandLogo string `json:"brand_logo,omitempty"`
}
type GoodsTag struct {
GoodsLabel int `json:"goods_label,omitempty"`
GoodsLabelName string `json:"goods_label_name,omitempty"`
GoodsTag []int `json:"goods_tag,omitempty"`
GoodsTagNames []string `json:"goods_tag_names,omitempty"`
}
type StockInfo struct {
Period string `json:"period" bson:"period"`
PeriodTime int `json:"-" bson:"period_time"`
PeriodTimeFormat string `json:"period_time"`
Stock int `json:"stock" bson:"stock"`
}
//为什么不直接映射到结构,而要用gjson,因为redis存的数据结构不一定正常,可能类型不一致
func InitSkuData(sku string) (data LySku) {
goodsSn := gjson.Get(sku, "goods_sn").String()
data.GoodsSn = goodsSn
spuId := gjson.Get(sku, "spu_id").String()
data.SpuId = spuId
oldGoodsId := gjson.Get(sku, "old_goods_id").Int()
data.OldGoodsId = oldGoodsId
updateTime := gjson.Get(sku, "update_time").Int()
data.UpdateTime = updateTime
goodsStatus := gjson.Get(sku, "goods_status").Int()
data.GoodsStatus = goodsStatus
goodsName := gjson.Get(sku, "goods_name").String()
data.GoodsName = goodsName
goodsType := gjson.Get(sku, "goods_type").Int()
data.GoodsType = goodsType
supplierId := gjson.Get(sku, "supplier_id").Int()
data.SupplierId = supplierId
encoded := gjson.Get(sku, "encoded").String()
data.Encoded = encoded
batchSn := gjson.Get(sku, "batch_sn").String()
data.BatchSn = batchSn
moq := gjson.Get(sku, "moq").Int()
data.Moq = moq
mpq := gjson.Get(sku, "mpq").Int()
data.Mpq = mpq
stock := gjson.Get(sku, "stock").Int()
data.Stock = stock
isExpire := gjson.Get(sku, "is_expire").Int()
data.IsExpire = int(isExpire)
hkDeliveryTime := gjson.Get(sku, "hk_delivery_time").String()
data.HkDeliveryTime = hkDeliveryTime
cnDeliveryTime := gjson.Get(sku, "cn_delivery_time").String()
data.CnDeliveryTime = cnDeliveryTime
goodsDetail := gjson.Get(sku, "goods_details").String()
data.GoodsDetails = goodsDetail
goodsImages := gjson.Get(sku, "goods_images").String()
data.GoodsImages = goodsImages
canal := gjson.Get(sku, "canal").String()
data.Canal = canal
//加上紧急判断,如果是立创(L0001175)的商品,就修改内部编码
if data.Canal == "L0001175" {
data.Encoded = "10142-L"
}
cpTime := gjson.Get(sku, "cp_time").Int()
data.CpTime = cpTime
LadderPriceStr := gjson.Get(sku, "ladder_price").String()
data.LadderPrice = getLadderPrice(LadderPriceStr)
data.Original = getOriginPrice(LadderPriceStr)
return
}
//获取联营商品的阶梯价
func getLadderPrice(ladderPriceStr string) (ladderPrice []LadderPrice) {
ladderPriceArr := gjson.Parse(ladderPriceStr).Array()
for _, price := range ladderPriceArr {
ladderPrice = append(ladderPrice, LadderPrice{
Purchases: price.Get("purchases").Int(),
PriceUs: price.Get("price_us").Float(),
PriceCn: price.Get("price_cn").Float(),
PriceAc: price.Get("price_ac").Float(),
CostPrice: price.Get("cost_price").Float(),
})
}
if len(ladderPrice) == 0 {
ladderPrice = []LadderPrice{}
return
}
return
}
//获取原始价格
func getOriginPrice(ladderPriceStr string) (ladderPrice []OriginPrice) {
ladderPriceArr := gjson.Parse(ladderPriceStr).Array()
for _, price := range ladderPriceArr {
ladderPrice = append(ladderPrice, OriginPrice{
Purchases: price.Get("purchases").Int(),
PriceUs: price.Get("price_us").Float(),
PriceCn: price.Get("price_cn").Float(),
PriceAc: price.Get("price_ac").Float(),
CostPrice: price.Get("cost_price").Float(),
})
}
if len(ladderPrice) == 0 {
ladderPrice = []OriginPrice{}
return
}
return
}
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