Commit 296b85cc by 杨树贤

Merge branch 'ysx-华云改造-20240306'

parents 8641a0d9 e3c0ca23
...@@ -9,14 +9,15 @@ type LyResponse struct { ...@@ -9,14 +9,15 @@ type LyResponse struct {
// 原始sku梯度 // 原始sku梯度
type LadderPrice struct { type LadderPrice struct {
Purchases int64 `json:"purchases"` //购买数量 Purchases int64 `json:"purchases"` //购买数量
PriceUs float64 `json:"price_us,omitempty"` //数量对应的英文价格 PriceUs float64 `json:"price_us,omitempty"` //数量对应的英文价格
PriceCn float64 `json:"price_cn"` //数量对应的中文价格 PriceCn float64 `json:"price_cn"` //数量对应的中文价格
PriceCostUs float64 `json:"price_cost_us"` //成本价美金 PriceCostUs float64 `json:"price_cost_us,omitempty"` //成本价美金
PriceCostCn float64 `json:"price_cost_cn"` //成本价人民币 PriceCostCn float64 `json:"price_cost_cn,omitempty"` //成本价人民币
PriceAc float64 `json:"price_ac,omitempty"` //活动价人民币 PriceAc float64 `json:"price_ac,omitempty"` //活动价人民币
PriceAcUs float64 `json:"price_ac_us,omitempty"` //活动价美金 PriceAcUs float64 `json:"price_ac_us,omitempty"` //活动价美金
CostPrice float64 `json:"-"` CostPrice float64 `json:"-"`
PriceName string `json:"price_name,omitempty"`
} }
type OriginPrice struct { type OriginPrice struct {
......
...@@ -45,6 +45,7 @@ type LySku struct { ...@@ -45,6 +45,7 @@ type LySku struct {
DatabasePrice interface{} `json:"database_price,omitempty"` DatabasePrice interface{} `json:"database_price,omitempty"`
SuppExtendFee interface{} `json:"supp_extend_fee"` SuppExtendFee interface{} `json:"supp_extend_fee"`
IsBuy int `json:"is_buy"` IsBuy int `json:"is_buy"`
OrgId int `json:"org_id"`
//spu信息 //spu信息
ClassID1 int `json:"class_id1"` ClassID1 int `json:"class_id1"`
ClassID2 int `json:"class_id2"` ClassID2 int `json:"class_id2"`
...@@ -75,6 +76,8 @@ type LySku struct { ...@@ -75,6 +76,8 @@ type LySku struct {
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"` StockInfo interface{} `json:"stock_info"`
SkuDetail string `json:"sku_detail"`
SpuExtra SpuExtra `json:"spu_extra"`
Eccn string `json:"eccn"` Eccn string `json:"eccn"`
DiscountRatio DiscountRatio `json:"discount_ratio"` DiscountRatio DiscountRatio `json:"discount_ratio"`
PriceRatioSort int `json:"price_ratio_sort"` PriceRatioSort int `json:"price_ratio_sort"`
...@@ -139,6 +142,15 @@ type StockInfo struct { ...@@ -139,6 +142,15 @@ type StockInfo struct {
Stock int `json:"stock" bson:"stock"` Stock int `json:"stock" bson:"stock"`
} }
type SpuExtra struct {
ImageList []struct {
Name string `bson:"name" json:"name"`
Thumbnail string `bson:"thumbnail" json:"thumbnail"`
} `bson:"image_list" json:"image_list"`
SpuDetail string `bson:"spu_detail" json:"spu_detail"`
SpuId string `bson:"spu_id" json:"spu_id"`
}
// 为什么不直接映射到结构,而要用gjson,因为redis存的数据结构不一定正常,可能类型不一致 // 为什么不直接映射到结构,而要用gjson,因为redis存的数据结构不一定正常,可能类型不一致
func InitSkuData(sku string) (data LySku) { func InitSkuData(sku string) (data LySku) {
...@@ -197,7 +209,8 @@ func InitSkuData(sku string) (data LySku) { ...@@ -197,7 +209,8 @@ func InitSkuData(sku string) (data LySku) {
data.Multiple = mpq data.Multiple = mpq
} }
} }
//todo 2023.5.6 如果是rochester ,递增量为1
//2023.5.6 如果是rochester ,递增量为1
if supplierId == 3 { if supplierId == 3 {
data.Multiple = 1 data.Multiple = 1
} }
...@@ -230,6 +243,14 @@ func InitSkuData(sku string) (data LySku) { ...@@ -230,6 +243,14 @@ func InitSkuData(sku string) (data LySku) {
canal := gjson.Get(sku, "canal").String() canal := gjson.Get(sku, "canal").String()
data.Canal = canal data.Canal = canal
//组织id,默认都是猎芯,因为没有默认存到redis,所以默认是1
orgId := gjson.Get(sku, "org_id").Int()
if orgId != 0 {
data.OrgId = int(orgId)
} else {
data.OrgId = 1
}
//加上紧急判断,如果是立创(L0001175)的商品,就修改内部编码 //加上紧急判断,如果是立创(L0001175)的商品,就修改内部编码
if data.Canal == "L0001175" { if data.Canal == "L0001175" {
data.Encoded = "10142-L" data.Encoded = "10142-L"
......
...@@ -3,7 +3,11 @@ package service ...@@ -3,7 +3,11 @@ package service
import ( import (
"go_sku_server/model" "go_sku_server/model"
"go_sku_server/pkg/gredis" "go_sku_server/pkg/gredis"
"go_sku_server/pkg/logger"
"go_sku_server/pkg/mongo"
"go_sku_server/service/sorter" "go_sku_server/service/sorter"
"gopkg.in/mgo.v2"
"gopkg.in/mgo.v2/bson"
"sort" "sort"
"sync" "sync"
...@@ -36,11 +40,17 @@ func (ls *LyService) LyGoodsDetail(ctx *gin.Context, goodsIds []string, ch chan ...@@ -36,11 +40,17 @@ func (ls *LyService) LyGoodsDetail(ctx *gin.Context, goodsIds []string, ch chan
redisConn.Close() redisConn.Close()
redisConnSpu.Close() redisConnSpu.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") showStockInfo := ctx.Request.FormValue("show_stock_info")
//是否展示sku详情
showSkuDetail := ctx.Request.FormValue("show_sku_detail")
//是否展示spu额外信息
showSpuExtra := ctx.Request.FormValue("show_spu_extra")
//批量获取商品详情 //批量获取商品详情
skuArr := gredis.Hmget("default_r", "sku", goodsIds) skuArr := gredis.Hmget("default_r", "sku", goodsIds)
//为了性能着想,这边也先去批量获取spu的信息 //为了性能着想,这边也先去批量获取spu的信息
...@@ -66,14 +76,14 @@ func (ls *LyService) LyGoodsDetail(ctx *gin.Context, goodsIds []string, ch chan ...@@ -66,14 +76,14 @@ func (ls *LyService) LyGoodsDetail(ctx *gin.Context, goodsIds []string, ch chan
sku = ls.GetGoodsImages(sku, spu) sku = ls.GetGoodsImages(sku, spu)
sku = ls.GetPdf(sku, spu) sku = ls.GetPdf(sku, spu)
//todo 2023.11.20 DGK商品的包装若为“Tape & Reel (TR)”,则递增量=起订量 // 2023.11.20 DGK商品的包装若为“Tape & Reel (TR)”,则递增量=起订量
if sku.SupplierId == 7 && sku.Packing == "Tape & Reel (TR)"{ if sku.SupplierId == 7 && sku.Packing == "Tape & Reel (TR)" {
sku.Multiple = sku.Moq sku.Multiple = sku.Moq
} }
//获取商品名称 //获取商品名称
//1688就是mro的sku spuName和GoodsName不是一个东西,不能公用 //1688就是mro的sku spuName和GoodsName不是一个东西,不能公用
if sku.GoodsName != "" && sku.SupplierId == 1688 { if sku.GoodsName != "" && (sku.SupplierId == 1688 || sku.Canal == "L0015730") {
sku.GoodsName = gjson.Get(spu, "spu_name").String() sku.GoodsName = gjson.Get(spu, "spu_name").String()
} }
if sku.GoodsName == "" { if sku.GoodsName == "" {
...@@ -106,6 +116,17 @@ func (ls *LyService) LyGoodsDetail(ctx *gin.Context, goodsIds []string, ch chan ...@@ -106,6 +116,17 @@ func (ls *LyService) LyGoodsDetail(ctx *gin.Context, goodsIds []string, ch chan
if showStockInfo == "1" && sku.OldGoodsId != 0 { if showStockInfo == "1" && sku.OldGoodsId != 0 {
sku.StockInfo = ls.getStockInfo(sku.SupplierId, sku.OldGoodsId) sku.StockInfo = ls.getStockInfo(sku.SupplierId, sku.OldGoodsId)
} }
//判断是否需要返回sku详情
if showSkuDetail == "1" {
sku.SkuDetail = ls.GetSkuDetail(sku.GoodsId)
}
//是否需要返回spu额外信息
if showSpuExtra == "1" {
sku.SpuExtra = ls.GetSpuExtra(sku.SpuId)
}
//格式化为对象返回 //格式化为对象返回
if sku.StockInfo == nil { if sku.StockInfo == nil {
type StockInfoResult struct { type StockInfoResult struct {
...@@ -121,7 +142,7 @@ func (ls *LyService) LyGoodsDetail(ctx *gin.Context, goodsIds []string, ch chan ...@@ -121,7 +142,7 @@ func (ls *LyService) LyGoodsDetail(ctx *gin.Context, goodsIds []string, ch chan
//获取新版的标准品牌 //获取新版的标准品牌
sku.StandardBrand = ls.GetStandardBrand(brandId) sku.StandardBrand = ls.GetStandardBrand(brandId)
//处理过期,todo 2022.7.13 专卖没有过期 //处理过期, 2022.7.13 专卖没有过期
if sku.SupplierId != 17 && gjson.Get(skuStr, "is_expire").Int() != 0 { if sku.SupplierId != 17 && gjson.Get(skuStr, "is_expire").Int() != 0 {
sku.LadderPrice = nil sku.LadderPrice = nil
} }
...@@ -145,8 +166,18 @@ func (ls *LyService) LyGoodsDetail(ctx *gin.Context, goodsIds []string, ch chan ...@@ -145,8 +166,18 @@ func (ls *LyService) LyGoodsDetail(ctx *gin.Context, goodsIds []string, ch chan
} }
} }
//获取系数 //这里又有一个判断,如果是非猎芯的,目前只有爱智,通过org_id来判断,如果是爱智,不需要走价格体系
sku = ls.GetCoefficientAndPrice(sku) //1是猎芯,3是爱智
switch sku.OrgId {
case 1:
//获取系数和价格
sku = ls.GetCoefficientAndPrice(sku)
break
case 3:
priceService := PriceService{}
sku.LadderPrice = priceService.GetIEdgePrice(sku.LadderPrice)
break
}
//仅提供价格和库存 //仅提供价格和库存
if fast != "1" { if fast != "1" {
...@@ -228,3 +259,36 @@ func (ls *LyService) GetActivity(sku model.LySku) model.LySku { ...@@ -228,3 +259,36 @@ func (ls *LyService) GetActivity(sku model.LySku) model.LySku {
} }
return sku 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
}
// 获取spu_extra
func (ls *LyService) GetSpuExtra(spuId string) (spuExtra model.SpuExtra) {
mongodb := mongo.Conn("default")
defer func() {
mongodb.Close()
}()
err := mongodb.DB("ichunt").C("spu_extra").Find(bson.M{"spu_id": spuId}).One(&spuExtra)
if err != nil && err != mgo.ErrNotFound {
logger.Select("sku_query").Error(err.Error())
}
return spuExtra
}
...@@ -503,16 +503,6 @@ func (ls *LyService) GetCoefficientAndPrice(sku model.LySku) model.LySku { ...@@ -503,16 +503,6 @@ func (ls *LyService) GetCoefficientAndPrice(sku model.LySku) model.LySku {
//活动价都是有样式的和平时不一样,如果价格一样,但是样子是活动价,客户会迷惑,所以不输出即可,保持原来的样式 //活动价都是有样式的和平时不一样,如果价格一样,但是样子是活动价,客户会迷惑,所以不输出即可,保持原来的样式
if data[key].PriceCn == priceAc && key < 2 { if data[key].PriceCn == priceAc && key < 2 {
flag++ flag++
//if flag >= 2 {
// sku.AcType = 0
// continue
//}
//if len(data) > 1 {
// if data[1].PriceCn == 0 {
// sku.AcType = 0
// continue
// }
//}
} }
data[key].PriceAc = priceAc data[key].PriceAc = priceAc
...@@ -547,7 +537,5 @@ func (ls *LyService) GetCoefficientAndPrice(sku model.LySku) model.LySku { ...@@ -547,7 +537,5 @@ func (ls *LyService) GetCoefficientAndPrice(sku model.LySku) model.LySku {
sku.LadderPrice = data sku.LadderPrice = data
} }
//fmt.Println(sku.PriceRatio, sku.PriceRatioSort)
return sku return sku
} }
...@@ -347,6 +347,9 @@ func (ps *PriceService) GenerateLadderPrice(sku model.LySku) model.LySku { ...@@ -347,6 +347,9 @@ func (ps *PriceService) GenerateLadderPrice(sku model.LySku) model.LySku {
} else { } else {
//fmt.Println(ladderPriceRatio) //fmt.Println(ladderPriceRatio)
ladderCount := len(sku.LadderPrice) ladderCount := len(sku.LadderPrice)
if len(priceRatioList) == 0 {
return sku
}
//走阶梯价 //走阶梯价
if ladderCount <= ladderPriceMiniProfitLevel { if ladderCount <= ladderPriceMiniProfitLevel {
for i := 0; i < ladderCount; i++ { for i := 0; i < ladderCount; i++ {
...@@ -716,3 +719,16 @@ func (ps *PriceService) TransformSpecialSupplierPrice(sku model.LySku) model.LyS ...@@ -716,3 +719,16 @@ func (ps *PriceService) TransformSpecialSupplierPrice(sku model.LySku) model.LyS
sku.OriginCurrencySymbol = symbol sku.OriginCurrencySymbol = symbol
return sku return sku
} }
// 处理爱智的价格,目前爱智是有个价格名称的东西
func (ps *PriceService) GetIEdgePrice(ladderPrice []model.LadderPrice) []model.LadderPrice {
//目前的价格名称是硬编码到代码里面
priceNameMap := map[int64]string{
1: "标准价",
2: "企业价",
}
for index, price := range ladderPrice {
ladderPrice[index].PriceName = priceNameMap[price.Purchases]
}
return ladderPrice
}
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