Commit f24c6b26 by 杨树贤

Merge branch 'ysx-自营库存特殊价格处理-20250903' into dev

parents 79ca797a d908ce29
...@@ -7,4 +7,5 @@ type PrevSku struct { ...@@ -7,4 +7,5 @@ type PrevSku struct {
ID bson.ObjectId `bson:"_id"` ID bson.ObjectId `bson:"_id"`
SkuId int64 `bson:"sku_id"` SkuId int64 `bson:"sku_id"`
SpuId int64 `bson:"spu_id"` SpuId int64 `bson:"spu_id"`
SupplierId int64 `bson:"supplier_id"`
} }
...@@ -2,15 +2,17 @@ package service ...@@ -2,15 +2,17 @@ package service
import ( import (
"encoding/json" "encoding/json"
"github.com/iancoleman/orderedmap"
"go_sku_server/pkg/logger" "go_sku_server/pkg/logger"
"go_sku_server/pkg/mongo" "go_sku_server/pkg/mongo"
"strconv"
"strings"
"github.com/iancoleman/orderedmap"
"gopkg.in/mgo.v2" "gopkg.in/mgo.v2"
"gopkg.in/mgo.v2/bson" "gopkg.in/mgo.v2/bson"
"strconv"
) )
//获取Spu的属性 // 获取Spu的属性
func (ls *LyService) GetSpuAttr(spuId string) (attrsResult interface{}) { func (ls *LyService) GetSpuAttr(spuId string) (attrsResult interface{}) {
var spuAttr SpuAttr var spuAttr SpuAttr
var attrsList []interface{} var attrsList []interface{}
...@@ -26,7 +28,17 @@ func (ls *LyService) GetSpuAttr(spuId string) (attrsResult interface{}) { ...@@ -26,7 +28,17 @@ func (ls *LyService) GetSpuAttr(spuId string) (attrsResult interface{}) {
//fmt.Println(spuAttr.AttrsExtend) //fmt.Println(spuAttr.AttrsExtend)
//如果有attrs_extend,就去取attrs_extend //如果有attrs_extend,就去取attrs_extend
if len(spuAttr.AttrsExtend) != 0 { if len(spuAttr.AttrsExtend) != 0 {
return spuAttr.AttrsExtend //便利AttrsExtend的值
for _, value := range spuAttr.AttrsExtend {
data := make(map[string]interface{})
data["attr_name"] = value.AttrName
//€符号全部替换为逗号
data["attr_value"] = strings.ReplaceAll(value.AttrValue, "€", ",")
data["attr_unit"] = value.AttrUnit
attrsList = append(attrsList, data)
attrsResult = attrsList
}
return attrsResult
} else if spuAttr.Attrs != "" { } else if spuAttr.Attrs != "" {
o := orderedmap.New() o := orderedmap.New()
err := json.Unmarshal([]byte(spuAttr.Attrs), &o) err := json.Unmarshal([]byte(spuAttr.Attrs), &o)
......
...@@ -93,6 +93,7 @@ func (ls *LyService) LyGoodsDetail(ctx *gin.Context, goodsIds []string, ch chan ...@@ -93,6 +93,7 @@ func (ls *LyService) LyGoodsDetail(ctx *gin.Context, goodsIds []string, ch chan
GoodsRes.Store(goodsId, false) GoodsRes.Store(goodsId, false)
continue continue
} }
sku.SupplierId = prevSku.SupplierId
sku.SpuId = spuIdStr sku.SpuId = spuIdStr
spu = spuStr spu = spuStr
} else { } else {
......
...@@ -289,6 +289,8 @@ func (ls *LyService) CombineSup(sku model.LySku, spuStr string) model.LySku { ...@@ -289,6 +289,8 @@ func (ls *LyService) CombineSup(sku model.LySku, spuStr string) model.LySku {
// 获取系数和总体价格,生成和处理价格的方法,很重要 // 获取系数和总体价格,生成和处理价格的方法,很重要
func (ls *LyService) GetCoefficientAndPrice(sku model.LySku) model.LySku { func (ls *LyService) GetCoefficientAndPrice(sku model.LySku) model.LySku {
// 为何是固定的1.13,关税基本不会变,有变的话跟产品沟通手动修改即可
tax := 1.13
//没有阶梯价格,直接跳过 //没有阶梯价格,直接跳过
if len(sku.LadderPrice) == 0 { if len(sku.LadderPrice) == 0 {
return sku return sku
...@@ -302,14 +304,49 @@ func (ls *LyService) GetCoefficientAndPrice(sku model.LySku) model.LySku { ...@@ -302,14 +304,49 @@ func (ls *LyService) GetCoefficientAndPrice(sku model.LySku) model.LySku {
ladderPrice := sku.LadderPrice ladderPrice := sku.LadderPrice
//这里是存了一些特殊供应商价格的判断,数据库里不是所有供应商都是存的人民币/美金 //这里是存了一些特殊供应商价格的判断,数据库里不是所有供应商都是存的人民币/美金
sku = priceService.TransformSpecialSupplierPrice(sku) sku = priceService.TransformSpecialSupplierPrice(sku)
//这里还有一个特殊判断
//猎芯自营 L0018319 WMS同步过来的未税成本单价(人民币),需乘以关税,再填入到基石该SKU的 成本价——国内含税(¥)
// 香港自营(L0018562)WMS同步过来的未税成本单价(美金)
//需更新到 基石该SKU的 成本价——香港交货($)且也需乘美金转人民币汇率, 再乘以关税,填入到基石该SKU的 成本价——国内含税(¥)价
if sku.Canal == "L0018319" {
for _, price := range sku.OriginalPrice {
originalPrice = append(originalPrice, model.OriginPrice{
Purchases: price.Purchases,
PriceCn: c.MyRound(c.MulFloat(price.PriceCn, tax), 4),
})
}
for index, price := range sku.LadderPrice {
ladderPrice[index].PriceCn = c.MyRound(c.MulFloat(price.PriceCn, tax), 4)
}
}
if sku.Canal == "L0018562" {
redisCon := gredis.Conn("default_r")
usdRatio, _ := redis.Float64(redisCon.Do("HGET", "erp_rate", 2))
for _, price := range sku.OriginalPrice {
originalPrice = append(originalPrice, model.OriginPrice{
Purchases: price.Purchases,
PriceCn: c.MyRound(c.MulFloat(price.PriceUs, usdRatio*tax), 4),
PriceUs: price.PriceUs,
})
}
for index, price := range sku.LadderPrice {
ladderPrice[index].PriceCn = c.MyRound(c.MulFloat(price.PriceUs, usdRatio*tax), 4)
}
}
//判断redis里面是否有成本价,有的话,那就直接去取价格,不需要生成阶梯价 //判断redis里面是否有成本价,有的话,那就直接去取价格,不需要生成阶梯价
//如果没有成本价字段,就要去生成阶梯价格 //如果没有成本价字段,就要去生成阶梯价格
if len(ladderPrice) > 0 { if len(ladderPrice) > 0 {
if ladderPrice[0].PriceCostUs == 0 && ladderPrice[0].PriceCostCn == 0 { if ladderPrice[0].PriceCostUs == 0 && ladderPrice[0].PriceCostCn == 0 {
//售价组也在这里计算了
sku = priceService.GenerateLadderPrice(sku) sku = priceService.GenerateLadderPrice(sku)
ladderPrice = sku.LadderPrice ladderPrice = sku.LadderPrice
} }
} }
//获取折扣系数 //获取折扣系数
sku = priceService.GetDiscountRatio(sku) sku = priceService.GetDiscountRatio(sku)
data = make([]model.LadderPrice, len(ladderPrice)) data = make([]model.LadderPrice, len(ladderPrice))
...@@ -335,6 +372,11 @@ func (ls *LyService) GetCoefficientAndPrice(sku model.LySku) model.LySku { ...@@ -335,6 +372,11 @@ func (ls *LyService) GetCoefficientAndPrice(sku model.LySku) model.LySku {
//专卖成本价 //专卖成本价
data[key].PriceCostUs = price.PriceCostUs data[key].PriceCostUs = price.PriceCostUs
data[key].PriceCostCn = price.PriceCostCn data[key].PriceCostCn = price.PriceCostCn
//判断原始价格有变化,那就要覆盖
if len(originalPrice) > 0 {
sku.OriginalPrice = originalPrice
}
} }
} else { } else {
data = make([]model.LadderPrice, len(sku.LadderPrice)) data = make([]model.LadderPrice, len(sku.LadderPrice))
...@@ -403,8 +445,7 @@ func (ls *LyService) GetCoefficientAndPrice(sku model.LySku) model.LySku { ...@@ -403,8 +445,7 @@ func (ls *LyService) GetCoefficientAndPrice(sku model.LySku) model.LySku {
} }
//下面是计算价格 //下面是计算价格
//价格计算文档 https://docs.qq.com/doc/DR3RJcnNPeUNkWHRk //价格计算文档 https://docs.qq.com/doc/DR3RJcnNPeUNkWHRk
// 为何是固定的1.13,关税基本不会变,有变的话跟产品沟通手动修改即可
tax := 1.13
sku = priceService.TransformSpecialSupplierPrice(sku) sku = priceService.TransformSpecialSupplierPrice(sku)
var showPriceRatioList []model.PriceRatio var showPriceRatioList []model.PriceRatio
for key, price := range sku.LadderPrice { for key, price := range sku.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