Commit bffa45a8 by mushishixian

成本价兼容

parent a03eba7e
......@@ -199,6 +199,7 @@ func (ls *LyService) GetCoefficientAndPrice(sku model.LySku) model.LySku {
if ladderPrice[0].PriceCostUs == 0 && ladderPrice[0].PriceCostCn == 0 {
var priceService PriceService
ladderPrice = priceService.GenerateLadderPrice(sku)
sku.Original = ladderPrice
} else {
fmt.Println("不走成本价生成")
}
......
......@@ -40,50 +40,54 @@ func (ls *LyService) TransformSpecialSupplierPrice(supplierId int64, priceUs flo
//构建专营的阶梯价,现在专营只会存一个简单的成本价,阶梯数量是1,所以我这边要根据专营的阶梯系数去构建具体的阶梯价
func (ps *PriceService) GenerateLadderPrice(sku model.LySku) (generatedLadderPrice []model.LadderPrice) {
//先直接获取成本价原始值,因为能走进来这个方法的,都是只有一个阶梯的成本价的
costPriceCn := sku.LadderPrice[0].PriceCn
costPriceUs := sku.LadderPrice[0].PriceUs
fmt.Println("人民币和美金的成本价分别为 : ", costPriceCn, costPriceUs)
//先去判断起订量,如果起订量小于50,就要走固定配置的阶梯价格系数
if sku.Moq <= 50 {
moq := int(sku.Moq)
//先直接获取成本价原始值,判断第一个阶梯的阶梯数量是否为0,如果是0,那么代表是要走成本价生成,如果不是0,那么就要走阶梯价生成
firstLadderPurchases := sku.LadderPrice[0].Purchases
isCostPrice := bool(firstLadderPurchases == 0)
fixedRatio := make(map[int]float64)
//var fixedRatioSlice map[int]float64
switch {
case sku.Moq < 10:
fixedRatio = map[int]float64{moq: 1.07, 30: 1.08, 100: 1.09, 300: 1.1, 1000: 1.11}
break
case sku.Moq < 30:
fixedRatio = map[int]float64{moq: 1.07, 50: 1.08, 200: 1.09, 500: 1.1, 1000: 1.11}
break
default:
fixedRatio = map[int]float64{moq: 1.07, 200: 1.08, 500: 1.09, 1000: 1.1, 2000: 1.11}
break
}
//然后根据一开始只有一个的阶梯价去生成阶梯价格
for purchases, ratio := range fixedRatio {
generatedLadderPrice = append(generatedLadderPrice, model.LadderPrice{
Purchases: int64(purchases),
PriceCn: c.MulFloat(costPriceCn, ratio),
PriceUs: c.MulFloat(costPriceUs, ratio),
})
}
return generatedLadderPrice
}
isCostPrice := true
//起订量大于50的,就要去读取对应的系数
//先去获取配置的redis
redisCon := gredis.Conn("default_r")
defer redisCon.Close()
priceRatio, _ := redis.String(redisCon.Do("HGET", "magic_cube_price_rule_v2", sku.Canal))
//拿不到就直接返回空价格,防止低价售卖
if priceRatio == "" {
return nil
}
//是否有设置最低利润点阶梯,不足5个阶梯时,最高阶梯对应的最小利润点阶梯
//isSetLowestProfit := gjson.Get(priceRatio, "is_set_lowest_profit").Bool()
ladderPriceMiniProfitLevel := int(gjson.Get(priceRatio, "ladder_price_mini_profit_level").Int())
//判断是否走成本价判断还是走阶梯价判断,因为上传sku的时候,可以设置每个sku的成本价(人民币&&美金),也可以设置每个sku的阶梯价,如果有阶梯价,就要跳过设置的成本价(假设有设置的话)
//判断是否走成本价判断还是走阶梯价判断,因为上传sku的时候,可以设置每个sku的成本价(人民币&&美金),也可以设置每个sku的阶梯价
//如果有阶梯价,就要跳过设置的成本价(假设有设置的话)
if isCostPrice {
costPriceCn := sku.LadderPrice[0].PriceCn
costPriceUs := sku.LadderPrice[0].PriceUs
fmt.Println("人民币和美金的成本价分别为 : ", costPriceCn, costPriceUs)
//先去判断起订量,如果起订量小于50,就要走固定配置的阶梯价格系数
if sku.Moq <= 50 {
moq := int(sku.Moq)
fixedRatio := make(map[int]float64)
//var fixedRatioSlice map[int]float64
switch {
case sku.Moq < 10:
fixedRatio = map[int]float64{moq: 1.07, 30: 1.08, 100: 1.09, 300: 1.1, 1000: 1.11}
break
case sku.Moq < 30:
fixedRatio = map[int]float64{moq: 1.07, 50: 1.08, 200: 1.09, 500: 1.1, 1000: 1.11}
break
default:
fixedRatio = map[int]float64{moq: 1.07, 200: 1.08, 500: 1.09, 1000: 1.1, 2000: 1.11}
break
}
//然后根据一开始只有一个的阶梯价去生成阶梯价格
for purchases, ratio := range fixedRatio {
generatedLadderPrice = append(generatedLadderPrice, model.LadderPrice{
Purchases: int64(purchases),
PriceCn: c.MyRound(c.MulFloat(costPriceCn, ratio), 4),
PriceUs: c.MyRound(c.MulFloat(costPriceUs, ratio), 4),
})
}
return generatedLadderPrice
}
//判断最小起订量是属于哪个范围
ratioKey := ""
if sku.Moq >= 50 && sku.Moq < 200 {
......@@ -92,7 +96,6 @@ func (ps *PriceService) GenerateLadderPrice(sku model.LySku) (generatedLadderPri
ratioKey = "cost_ladder_price_egt200"
}
costLadderPriceRatio := gjson.Get(priceRatio, ratioKey).Map()
// 成本价阶梯数 由最高库存计算得到
costLadderCount := 0
for i := 1; i <= len(costLadderPriceRatio); i++ {
......@@ -115,7 +118,8 @@ func (ps *PriceService) GenerateLadderPrice(sku model.LySku) (generatedLadderPri
break
}
//利润阶梯索引
//计算出库存满足了n个价格阶梯之后 从最小利润点层级反向取n个层级,然后正序计算 如:库存满足1、2、3层阶梯,最小利润点层级是第5个层级,则利润点取3、4、5层级的
//计算出库存满足了n个价格阶梯之后 从最小利润点层级反向取n个层级,然后正序计算
//如:库存满足1、2、3层阶梯,最小利润点层级是第5个层级,则利润点取3、4、5层级的
//最小利润点层级 - 库存满足多少个阶梯 + i
costMapIndex := ladderPriceMiniProfitLevel - costLadderCount + i
if costMapIndex <= 0 {
......@@ -126,8 +130,8 @@ func (ps *PriceService) GenerateLadderPrice(sku model.LySku) (generatedLadderPri
// 阶梯价格系数正序取
generatedLadderPrice = append(generatedLadderPrice, model.LadderPrice{
Purchases: costPurchases,
PriceCn: c.MulFloat(costPriceCn, priceRatioAndPurchases.Get("price").Float()),
PriceUs: c.MulFloat(costPriceUs, priceRatioAndPurchases.Get("price_usd").Float()),
PriceCn: c.MyRound(c.MulFloat(costPriceCn, priceRatioAndPurchases.Get("price").Float()), 4),
PriceUs: c.MyRound(c.MulFloat(costPriceUs, priceRatioAndPurchases.Get("price_usd").Float()), 4),
})
}
} else {
......@@ -144,19 +148,20 @@ func (ps *PriceService) GenerateLadderPrice(sku model.LySku) (generatedLadderPri
// 阶梯价格系数正序取
generatedLadderPrice = append(generatedLadderPrice, model.LadderPrice{
Purchases: sku.Moq * priceRatioAndPurchases.Get("purchases").Int(),
PriceCn: c.MulFloat(costPriceCn, priceRatioAndPurchases.Get("price").Float()),
PriceUs: c.MulFloat(costPriceUs, priceRatioAndPurchases.Get("price_usd").Float()),
PriceCn: c.MyRound(c.MulFloat(costPriceCn, priceRatioAndPurchases.Get("price").Float()), 4),
PriceUs: c.MyRound(c.MulFloat(costPriceUs, priceRatioAndPurchases.Get("price_usd").Float()), 4),
})
}
}
return generatedLadderPrice
} else {
ladderPriceRatio := gjson.Get(priceRatio, "ladder_price_egt50_lt200").Map()
fmt.Println(ladderPriceRatio)
ladderCount := len(sku.LadderPrice)
//走阶梯价
if ladderCount <= ladderPriceMiniProfitLevel {
for i := 1; i <= ladderCount; i++ {
ladder := sku.LadderPrice[i]
ladder := sku.LadderPrice[i-1]
//利润阶梯索引
//计算出库存满足了n个价格阶梯之后 从最小利润点层级反向取n个层级,然后正序计算 如:库存满足1、2、3层阶梯,最小利润点层级是第5个层级,则利润点取3、4、5层级的
//最小利润点层级 - 库存满足多少个阶梯 + i
......@@ -164,30 +169,30 @@ func (ps *PriceService) GenerateLadderPrice(sku model.LySku) (generatedLadderPri
if costMapIndex <= 0 {
costMapIndex = 1
}
fmt.Println(costMapIndex)
priceRatio := ladderPriceRatio[strconv.Itoa(costMapIndex)]
fmt.Println("获取到的阶梯系数为 : ", priceRatio)
// 阶梯价格系数正序取
generatedLadderPrice = append(generatedLadderPrice, model.LadderPrice{
Purchases: ladder.Purchases,
PriceCn: c.MulFloat(ladder.PriceCn, priceRatio.Get("ratio").Float()),
PriceUs: c.MulFloat(ladder.PriceUs, priceRatio.Get("ratio_usd").Float()),
PriceCn: c.MyRound(c.MulFloat(ladder.PriceCn, priceRatio.Get("ratio").Float()), 4),
PriceUs: c.MyRound(c.MulFloat(ladder.PriceUs, priceRatio.Get("ratio_usd").Float()), 4),
})
}
} else {
//价格阶梯数量超过最利润点的层级的情况
for i := 1; i <= 9; i++ {
ladder := sku.LadderPrice[i]
ladder := sku.LadderPrice[i-1]
// 阶梯数量系数正序取
priceRatio := ladderPriceRatio[strconv.Itoa(i)]
// 阶梯价格系数正序取
generatedLadderPrice = append(generatedLadderPrice, model.LadderPrice{
Purchases: int64(ladder.Purchases),
PriceCn: c.MulFloat(ladder.PriceCn, priceRatio.Get("ratio").Float()),
PriceUs: c.MulFloat(ladder.PriceUs, priceRatio.Get("ratio_usd").Float()),
PriceCn: c.MyRound(c.MulFloat(ladder.PriceCn, priceRatio.Get("ratio").Float()), 4),
PriceUs: c.MyRound(c.MulFloat(ladder.PriceUs, priceRatio.Get("ratio_usd").Float()), 4),
})
}
}
return generatedLadderPrice
}
return
}
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