Commit d1c73493 by mushishixian

匹配专营阶梯

parent 50adaeee
...@@ -198,8 +198,11 @@ func (ls *LyService) GetCoefficientAndPrice(sku model.LySku) model.LySku { ...@@ -198,8 +198,11 @@ func (ls *LyService) GetCoefficientAndPrice(sku model.LySku) model.LySku {
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 {
var priceService PriceService var priceService PriceService
ladderPrice = priceService.GenerateLadderPrice(sku) generatedLadderPrice, priceRatio := priceService.GenerateLadderPrice(sku)
ladderPrice = generatedLadderPrice
//sku.Original = ladderPrice //sku.Original = ladderPrice
sku.PriceRatio = priceRatio
sku.PriceRatioSort = -1
} else { } else {
fmt.Println("不走成本价生成") fmt.Println("不走成本价生成")
} }
......
...@@ -40,7 +40,7 @@ func (ls *LyService) TransformSpecialSupplierPrice(supplierId int64, priceUs flo ...@@ -40,7 +40,7 @@ func (ls *LyService) TransformSpecialSupplierPrice(supplierId int64, priceUs flo
} }
//构建专营的阶梯价,现在专营只会存一个简单的成本价,阶梯数量是1,所以我这边要根据专营的阶梯系数去构建具体的阶梯价 //构建专营的阶梯价,现在专营只会存一个简单的成本价,阶梯数量是1,所以我这边要根据专营的阶梯系数去构建具体的阶梯价
func (ps *PriceService) GenerateLadderPrice(sku model.LySku) (generatedLadderPrice []model.LadderPrice) { func (ps *PriceService) GenerateLadderPrice(sku model.LySku) (generatedLadderPrice []model.LadderPrice, showPriceRatio []model.PriceRatio) {
//先直接获取成本价原始值,判断第一个阶梯的阶梯数量是否为0,如果是0,那么代表是要走成本价生成,如果不是0,那么就要走阶梯价生成 //先直接获取成本价原始值,判断第一个阶梯的阶梯数量是否为0,如果是0,那么代表是要走成本价生成,如果不是0,那么就要走阶梯价生成
firstLadderPurchases := sku.LadderPrice[0].Purchases firstLadderPurchases := sku.LadderPrice[0].Purchases
isCostPrice := bool(firstLadderPurchases == 0) isCostPrice := bool(firstLadderPurchases == 0)
...@@ -51,9 +51,9 @@ func (ps *PriceService) GenerateLadderPrice(sku model.LySku) (generatedLadderPri ...@@ -51,9 +51,9 @@ func (ps *PriceService) GenerateLadderPrice(sku model.LySku) (generatedLadderPri
priceRatio, _ := redis.String(redisCon.Do("HGET", "magic_cube_price_rule_v2", sku.Canal)) priceRatio, _ := redis.String(redisCon.Do("HGET", "magic_cube_price_rule_v2", sku.Canal))
//拿不到就直接返回空价格,防止低价售卖 //拿不到就直接返回空价格,防止低价售卖
if priceRatio == "" { if priceRatio == "" {
return nil return nil, nil
} }
//这是用来展示在商品服务的价格系数,专营的系数和代购的不一样,所以要转换一下展示形式
//是否有设置最低利润点阶梯,不足5个阶梯时,最高阶梯对应的最小利润点阶梯 //是否有设置最低利润点阶梯,不足5个阶梯时,最高阶梯对应的最小利润点阶梯
ladderPriceMiniProfitLevel := int(gjson.Get(priceRatio, "ladder_price_mini_profit_level").Int()) ladderPriceMiniProfitLevel := int(gjson.Get(priceRatio, "ladder_price_mini_profit_level").Int())
//判断是否走成本价判断还是走阶梯价判断,因为上传sku的时候,可以设置每个sku的成本价(人民币&&美金),也可以设置每个sku的阶梯价 //判断是否走成本价判断还是走阶梯价判断,因为上传sku的时候,可以设置每个sku的成本价(人民币&&美金),也可以设置每个sku的阶梯价
...@@ -81,16 +81,20 @@ func (ps *PriceService) GenerateLadderPrice(sku model.LySku) (generatedLadderPri ...@@ -81,16 +81,20 @@ func (ps *PriceService) GenerateLadderPrice(sku model.LySku) (generatedLadderPri
//然后根据一开始只有一个的阶梯价去生成阶梯价格 //然后根据一开始只有一个的阶梯价去生成阶梯价格
for purchases, ratio := range fixedRatio { for purchases, ratio := range fixedRatio {
//同时还要构建价格系数展示在商品服务
showPriceRatio = append(showPriceRatio, model.PriceRatio{Ratio: ratio, RatioUsd: ratio})
generatedLadderPrice = append(generatedLadderPrice, model.LadderPrice{ generatedLadderPrice = append(generatedLadderPrice, model.LadderPrice{
Purchases: int64(purchases), Purchases: int64(purchases),
PriceCn: c.MyRound(c.MulFloat(costPriceCn, ratio), 4), PriceCn: c.MyRound(c.MulFloat(costPriceCn, ratio), 4),
PriceUs: c.MyRound(c.MulFloat(costPriceUs, ratio), 4), PriceUs: c.MyRound(c.MulFloat(costPriceUs, ratio), 4),
}) })
} }
sku.PriceRatio = showPriceRatio
sort.Slice(generatedLadderPrice, func(i, j int) bool { sort.Slice(generatedLadderPrice, func(i, j int) bool {
return generatedLadderPrice[i].Purchases < generatedLadderPrice[j].Purchases return generatedLadderPrice[i].Purchases < generatedLadderPrice[j].Purchases
}) })
return generatedLadderPrice return generatedLadderPrice, showPriceRatio
} }
//判断最小起订量是属于哪个范围 //判断最小起订量是属于哪个范围
ratioKey := "" ratioKey := ""
...@@ -131,12 +135,16 @@ func (ps *PriceService) GenerateLadderPrice(sku model.LySku) (generatedLadderPri ...@@ -131,12 +135,16 @@ func (ps *PriceService) GenerateLadderPrice(sku model.LySku) (generatedLadderPri
} }
priceRatioAndPurchases = costLadderPriceRatio[strconv.Itoa(costMapIndex)] priceRatioAndPurchases = costLadderPriceRatio[strconv.Itoa(costMapIndex)]
fmt.Println("获取到的阶梯系数为 : ", priceRatioAndPurchases) fmt.Println("获取到的阶梯系数为 : ", priceRatioAndPurchases)
priceCnRatio := priceRatioAndPurchases.Get("price").Float()
priceUsRatio := priceRatioAndPurchases.Get("price_usd").Float()
// 阶梯价格系数正序取 // 阶梯价格系数正序取
showPriceRatio = append(showPriceRatio, model.PriceRatio{Ratio: priceCnRatio, RatioUsd: priceUsRatio})
generatedLadderPrice = append(generatedLadderPrice, model.LadderPrice{ generatedLadderPrice = append(generatedLadderPrice, model.LadderPrice{
Purchases: costPurchases, Purchases: costPurchases,
PriceCn: c.MyRound(c.MulFloat(costPriceCn, priceRatioAndPurchases.Get("price").Float()), 4), PriceCn: c.MyRound(c.MulFloat(costPriceCn, priceCnRatio), 4),
PriceUs: c.MyRound(c.MulFloat(costPriceUs, priceRatioAndPurchases.Get("price_usd").Float()), 4), PriceUs: c.MyRound(c.MulFloat(costPriceUs, priceUsRatio), 4),
}) })
sku.PriceRatio = showPriceRatio
} }
} else { } else {
//价格阶梯数量超过最利润点的层级的情况 //价格阶梯数量超过最利润点的层级的情况
...@@ -148,16 +156,19 @@ func (ps *PriceService) GenerateLadderPrice(sku model.LySku) (generatedLadderPri ...@@ -148,16 +156,19 @@ func (ps *PriceService) GenerateLadderPrice(sku model.LySku) (generatedLadderPri
if costPurchases > sku.Stock { if costPurchases > sku.Stock {
break break
} }
fmt.Println(costPriceCn) priceCnRatio := priceRatioAndPurchases.Get("price").Float()
priceUsRatio := priceRatioAndPurchases.Get("price_usd").Float()
showPriceRatio = append(showPriceRatio, model.PriceRatio{Ratio: priceCnRatio, RatioUsd: priceUsRatio})
// 阶梯价格系数正序取 // 阶梯价格系数正序取
generatedLadderPrice = append(generatedLadderPrice, model.LadderPrice{ generatedLadderPrice = append(generatedLadderPrice, model.LadderPrice{
Purchases: sku.Moq * priceRatioAndPurchases.Get("purchases").Int(), Purchases: sku.Moq * priceRatioAndPurchases.Get("purchases").Int(),
PriceCn: c.MyRound(c.MulFloat(costPriceCn, priceRatioAndPurchases.Get("price").Float()), 4), PriceCn: c.MyRound(c.MulFloat(costPriceCn, priceCnRatio), 4),
PriceUs: c.MyRound(c.MulFloat(costPriceUs, priceRatioAndPurchases.Get("price_usd").Float()), 4), PriceUs: c.MyRound(c.MulFloat(costPriceUs, priceUsRatio), 4),
}) })
} }
sku.PriceRatio = showPriceRatio
} }
return generatedLadderPrice return generatedLadderPrice, showPriceRatio
} else { } else {
ladderPriceRatio := gjson.Get(priceRatio, "ladder_price_egt50_lt200").Map() ladderPriceRatio := gjson.Get(priceRatio, "ladder_price_egt50_lt200").Map()
fmt.Println(ladderPriceRatio) fmt.Println(ladderPriceRatio)
...@@ -176,19 +187,27 @@ func (ps *PriceService) GenerateLadderPrice(sku model.LySku) (generatedLadderPri ...@@ -176,19 +187,27 @@ func (ps *PriceService) GenerateLadderPrice(sku model.LySku) (generatedLadderPri
fmt.Println(costMapIndex) fmt.Println(costMapIndex)
priceRatio := ladderPriceRatio[strconv.Itoa(costMapIndex)] priceRatio := ladderPriceRatio[strconv.Itoa(costMapIndex)]
fmt.Println("获取到的阶梯系数为 : ", priceRatio) fmt.Println("获取到的阶梯系数为 : ", priceRatio)
priceCnRatio := priceRatio.Get("ratio").Float()
priceUsRatio := priceRatio.Get("ratio_usd").Float()
showPriceRatio = append(showPriceRatio, model.PriceRatio{Ratio: priceCnRatio, RatioUsd: priceUsRatio})
// 阶梯价格系数正序取 // 阶梯价格系数正序取
generatedLadderPrice = append(generatedLadderPrice, model.LadderPrice{ generatedLadderPrice = append(generatedLadderPrice, model.LadderPrice{
Purchases: ladder.Purchases, Purchases: ladder.Purchases,
PriceCn: c.MyRound(c.MulFloat(ladder.PriceCn, priceRatio.Get("ratio").Float()), 4), PriceCn: c.MyRound(c.MulFloat(ladder.PriceCn, priceCnRatio), 4),
PriceUs: c.MyRound(c.MulFloat(ladder.PriceUs, priceRatio.Get("ratio_usd").Float()), 4), PriceUs: c.MyRound(c.MulFloat(ladder.PriceUs, priceUsRatio), 4),
}) })
} }
sku.PriceRatio = showPriceRatio
} else { } else {
//价格阶梯数量超过最利润点的层级的情况 //价格阶梯数量超过最利润点的层级的情况
for i := 1; i <= 9; i++ { for i := 1; i <= 9; i++ {
ladder := sku.LadderPrice[i-1] ladder := sku.LadderPrice[i-1]
// 阶梯数量系数正序取 // 阶梯数量系数正序取
priceRatio := ladderPriceRatio[strconv.Itoa(i)] priceRatio := ladderPriceRatio[strconv.Itoa(i)]
priceCnRatio := priceRatio.Get("ratio").Float()
priceUsRatio := priceRatio.Get("ratio_usd").Float()
showPriceRatio = append(showPriceRatio, model.PriceRatio{Ratio: priceCnRatio, RatioUsd: priceUsRatio})
// 阶梯价格系数正序取 // 阶梯价格系数正序取
generatedLadderPrice = append(generatedLadderPrice, model.LadderPrice{ generatedLadderPrice = append(generatedLadderPrice, model.LadderPrice{
Purchases: int64(ladder.Purchases), Purchases: int64(ladder.Purchases),
...@@ -196,7 +215,8 @@ func (ps *PriceService) GenerateLadderPrice(sku model.LySku) (generatedLadderPri ...@@ -196,7 +215,8 @@ func (ps *PriceService) GenerateLadderPrice(sku model.LySku) (generatedLadderPri
PriceUs: c.MyRound(c.MulFloat(ladder.PriceUs, priceRatio.Get("ratio_usd").Float()), 4), PriceUs: c.MyRound(c.MulFloat(ladder.PriceUs, priceRatio.Get("ratio_usd").Float()), 4),
}) })
} }
sku.PriceRatio = showPriceRatio
} }
return generatedLadderPrice return generatedLadderPrice, showPriceRatio
} }
} }
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