Commit ced647fb by mushishixian

商品通用函数

parent 55ae9a08
Showing with 201 additions and 38 deletions
package model
type ApiGoods struct {
GoodsId string `json:"goods_id"`
GoodsName string `json:"goods_name"`
GoodsType int64 `json:"goods_type"`
SupplierId int64 `json:"supplier_id"`
Moq int64 `json:"moq"`
Mpq int64 `json:"mpq"`
Stock int64 `json:"stock"`
HkDeliveryTime string `json:"hk_delivery_time"`
CnDeliveryTime string `json:"cn_delivery_time"`
LadderPrice []LadderPrice `json:"ladder_price"`
BrandName string `json:"brand_name"`
SupplierName string `json:"supplier_name"`
BrandId int64 `json:"brand_id"`
IsBuy int64 `json:"is_buy"`
Mpl int64 `json:"mpl"`
Status int64 `json:"status"`
Pdf string `json:"pdf"`
Encap string `json:"encap"`
AcType int64 `json:"ac_type"`
//ErpTax bool `json:"erp_tax"`
PickType int `json:"pick_type"`
BarCode string `json:"bar_code"`
GoodsId string `json:"goods_id"`
GoodsName string `json:"goods_name"`
GoodsType int `json:"goods_type"`
SupplierId int `json:"supplier_id"`
Moq int `json:"moq"`
Mpq int `json:"mpq"`
Stock int `json:"stock"`
HkDeliveryTime string `json:"hk_delivery_time"`
CnDeliveryTime string `json:"cn_delivery_time"`
LadderPrice []LadderPrice `json:"ladder_price"`
BrandName string `json:"brand_name"`
SupplierName string `json:"supplier_name"`
BrandId int `json:"brand_id"`
ClassId1 int `json:"class_id1"`
ClassId2 int `json:"class_id2"`
Encoded string `json:"encoded"`
Packing string `json:"packing"`
GoodsUnit string `json:"goods_unit"`
GoodsImages string `json:"goods_images"`
GoodsBrief string `json:"goods_brief"`
IsBuy int `json:"is_buy"`
Mpl int `json:"mpl"`
Status int `json:"status"`
Pdf string `json:"pdf"`
Encap string `json:"encap"`
AcType int `json:"ac_type"`
OtherAttrs OtherAttrs `json:"other_attrs"`
UpdateTime int `json:"update_time"`
SkuName string `json:"sku_name"`
Attrs Attrs `json:"attrs"`
Cost string `json:"cost"`
NewCost string `json:"new_cost"`
SupplierStock int `json:"supplier_stock"`
SelfSupplierType int `json:"self_supplier_type"`
GoodsUnitName string `json:"goods_unit_name"`
PackingName string `json:"packing_name"`
MpgUnitName string `json:"mpg_unit_name"`
ScmBrandName string `json:"scm_brand_name"`
AllowCoupon int `json:"allow_coupon"`
ClassId1Name string `json:"class_id1_name"`
CLassId2Name string `json:"c_lass_id2_name"`
SpuId string `json:"spu_id,omitempty"`
BatchSn string `json:"batch_sn,omitempty"`
Canal string `json:"canal,omitempty"`
CpTime int `json:"cp_time,omitempty"`
Coefficient Coefficient `json:"coefficient,omitempty"`
OriginalPrice []OriginalPrice `json:"original_price,omitempty"`
SuppExtendFee SuppExtendFee `json:"supp_extend_fee,omitempty"`
ClassId3 int `json:"class_id3,omitempty"`
SpuName string `json:"spu_name,omitempty"`
ImagesL string `json:"images_l,omitempty"`
SpuBrief string `json:"spu_brief,omitempty"`
SpuDetail string `json:"spu_detail,omitempty"`
ClassName3 string `json:"class_name3,omitempty"`
ErpTax bool `json:"erp_tax,omitempty"`
ScmBrand ScmBrand `json:"scm_brand,omitempty"`
}
type Attr struct {
AttrName string
AttrValue string
}
type Attrs map[string]Attr
type OtherAttrs struct {
GrossWeight string `json:"gross_weight"`
}
type LadderPrice struct {
Purchases int64 `json:"purchases"`
Purchases int `json:"purchases"`
PriceUs float64 `json:"price_us"`
PriceCn float64 `json:"price_cn"`
PriceAc float64 `json:"price_ac"`
}
\ No newline at end of file
}
type Coefficient struct {
Cn string `json:"cn"`
Hk string `json:"hk"`
ExtraRatio string `json:"extra_ratio"`
Ratio string `json:"ratio"`
Tax float64 `json:"tax"`
}
type OriginalPrice struct {
Purchases int `json:"purchases"`
PriceCn float64 `json:"price_cn"`
PriceUs float64 `json:"price_us"`
}
type SuppExtendFee struct {
Cn struct {
Max int `json:"max"`
Price float64 `json:"price"`
} `json:"cn,omitempty"`
Hk struct{
Max int `json:"max"`
Price float64 `json:"price"`
} `json:"hk,omitempty"`
}
type ScmBrand struct {
ErpBrandName string `json:"erp_brand_name"`
ErpBrandId string `json:"erp_brand_id"`
ScmBrandId string `json:"scm_brand_id"`
}
......@@ -9,6 +9,7 @@ import (
"gopkg.in/olivere/elastic.v5"
"regexp"
"search_server/model"
"search_server/pkg/common"
"search_server/pkg/config"
"search_server/pkg/es"
"search_server/pkg/gredis"
......@@ -61,28 +62,64 @@ func CurlGoodsInfo(goodsIdsStr string, params req.Param) (goodsList []*model.Api
//还要去判断是否是false,因为商品服务可能返回 "1000":false 这样子的形式
if data.IsObject() {
var goods model.ApiGoods
goods.GoodsName = data.Get("goods_name").String()
goods.PickType = int(data.Get("pick_type").Int())
goods.BarCode = data.Get("bar_code").String()
goods.GoodsId = data.Get("goods_id").String()
goods.BrandId = data.Get("goods_id").Int()
goods.Pdf = data.Get("pdf").String()
goods.Stock = data.Get("stock").Int()
goods.Mpq = data.Get("mpq").Int()
goods.Moq = data.Get("moq").Int()
goods.SupplierName = data.Get("supplier_name").String()
goods.BrandName = data.Get("brand_name").String()
goods.GoodsName = data.Get("goods_name").String()
goods.GoodsType = int(data.Get("goods_type").Int())
goods.SupplierId = int(data.Get("supplier_id").Int())
goods.Mpq = int(data.Get("mpq").Int())
goods.Moq = int(data.Get("moq").Int())
goods.Stock = int(data.Get("stock").Int())
goods.HkDeliveryTime = data.Get("hk_delivery_time").String()
goods.CnDeliveryTime = data.Get("cn_delivery_time").String()
goods.IsBuy = data.Get("is_buy").Int()
goods.Mpl = data.Get("mpl").Int()
goods.BrandName = data.Get("brand_name").String()
goods.SupplierName = data.Get("supplier_name").String()
goods.BrandId = int(data.Get("goods_id").Int())
goods.ClassId1 = int(data.Get("class_id1").Int())
goods.ClassId2 = int(data.Get("class_id2").Int())
goods.Encoded = data.Get("encoded").String()
goods.Packing = data.Get("packing").String()
goods.GoodsUnit = data.Get("goods_unit").String()
goods.GoodsImages = data.Get("goods_images").String()
goods.GoodsBrief = data.Get("goods_brief").String()
goods.Mpl = int(data.Get("mpl").Int())
goods.Status = int(data.Get("status").Int())
goods.IsBuy = int(data.Get("is_buy").Int())
goods.Pdf = data.Get("pdf").String()
goods.Encap = data.Get("encap").String()
goods.SupplierId = data.Get("supplier_id").Int()
goods.Status = data.Get("status").Int()
goods.GoodsType = data.Get("goods_type").Int()
goods.AcType = data.Get("ac_type").Int()
goods.AcType = int(data.Get("ac_type").Int())
goods.SkuName = data.Get("sku_name").String()
goods.Cost = data.Get("const").String()
goods.NewCost = data.Get("new_const").String()
goods.SupplierStock = int(data.Get("supplier_stock").Int())
goods.SelfSupplierType = int(data.Get("self_supplier_type").Int())
goods.GoodsUnitName = data.Get("goods_unit_name").String()
goods.PackingName = data.Get("packing_name").String()
goods.MpgUnitName = data.Get("mpg_unit_name").String()
goods.ScmBrandName = data.Get("scm_brand_name").String()
goods.AllowCoupon = int(data.Get("allow_coupon").Int())
goods.ClassId1Name = data.Get("class_id1_name").String()
goods.CLassId2Name = data.Get("c_lass_id2_name").String()
goods.SpuId = data.Get("spu_id").String()
goods.BatchSn = data.Get("batch_sn").String()
goods.Canal = data.Get("canal").String()
goods.CpTime = int(data.Get("cp_time").Int())
goods.ClassId3 = int(data.Get("class_id3").Int())
goods.SpuName = data.Get("spu_name").String()
goods.ImagesL = data.Get("images_l").String()
goods.SpuBrief = data.Get("spu_brief").String()
goods.SpuDetail = data.Get("spu_detail").String()
goods.ClassName3 = data.Get("class_name3").String()
goods.ErpTax = data.Get("erp_tax").Bool()
goods.SupplierId = int(data.Get("supplier_id").Int())
goods.GoodsType = int(data.Get("goods_type").Int())
//ladder_price
ladderPrice := make([]model.LadderPrice, 0)
for _, price := range data.Get("ladder_price").Array() {
ladder := model.LadderPrice{
Purchases: price.Get("purchases").Int(),
Purchases: int(price.Get("purchases").Int()),
PriceUs: price.Get("price_us").Float(),
PriceCn: price.Get("price_cn").Float(),
PriceAc: price.Get("price_ac").Float(),
......@@ -90,6 +127,52 @@ func CurlGoodsInfo(goodsIdsStr string, params req.Param) (goodsList []*model.Api
ladderPrice = append(ladderPrice, ladder)
}
goods.LadderPrice = ladderPrice
//other_attrs
goods.OtherAttrs.GrossWeight = data.Get("other_attrs.gross_weight").String()
//Attrs
attrMap := make(map[string]model.Attr, 0)
for key, attr := range data.Get("attrs").Array() {
attr := model.Attr{
AttrName: attr.Get("attr_name").String(),
AttrValue: attr.Get("attr_value").String(),
}
attrMap[common.ToString(key)] = attr
}
goods.Attrs = attrMap
//coefficient
goods.Coefficient.Cn = data.Get("coefficient.cn").String()
goods.Coefficient.Hk = data.Get("coefficient.hk").String()
goods.Coefficient.ExtraRatio = data.Get("coefficient.extra_ratio").String()
goods.Coefficient.Ratio = data.Get("coefficient.ratio").String()
goods.Coefficient.Tax = data.Get("coefficient.tax").Float()
//original_price
originalPrice := make([]model.OriginalPrice, 0)
for _, price := range data.Get("ladder_price").Array() {
price := model.OriginalPrice{
Purchases: int(price.Get("purchases").Int()),
PriceUs: price.Get("price_us").Float(),
PriceCn: price.Get("price_cn").Float(),
}
originalPrice = append(originalPrice, price)
}
goods.OriginalPrice = originalPrice
//supp_extend_fee
goods.SuppExtendFee.Cn.Max = int(data.Get("supp_extend_fee.cn.max").Int())
goods.SuppExtendFee.Cn.Price = data.Get("supp_extend_fee.cn.price").Float()
goods.SuppExtendFee.Hk.Max = int(data.Get("supp_extend_fee.cn.max").Int())
goods.SuppExtendFee.Hk.Price = data.Get("supp_extend_fee.cn.price").Float()
//scm_brand
goods.ScmBrand.ErpBrandName = data.Get("scm_brand.erp_brand_name").String()
goods.ScmBrand.ErpBrandId = data.Get("scm_brand.erp_brand_id").String()
goods.ScmBrand.ScmBrandId = data.Get("scm_brand.scm_brand_id").String()
goodsList = append(goodsList, &goods)
goodsListMap[goodsId] = &goods
} else {
......
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