Commit 1071482a by mushishixian

起订量小于50取利润系数问题

parent a3041195
......@@ -251,12 +251,12 @@ func (ls *LyService) GetCoefficientAndPrice(sku model.LySku) model.LySku {
//先去读取成本折扣系数
//找一个标志位,因为默认的全局折扣系数的数据格式和非全局的是不一样的
isDefaultDiscoutRatio := false
isDefaultDiscountRatio := false
discountRatio, _ := redis.String(redisCon.Do("HGET", "magic_cube_channel_discount_daigou", sku.SupplierId))
checkNullRation := gjson.Get(discountRatio, "ration").String()
//如果这个渠道没有对应的折扣系数,那么就去读取全局的
if discountRatio == "" || checkNullRation == "{}" {
isDefaultDiscoutRatio = true
isDefaultDiscountRatio = true
discountRatio, _ = redis.String(redisCon.Do("GET", "magic_cube_channel_discount_default_daigou"))
}
var cnDiscountRatio float64
......@@ -264,7 +264,7 @@ func (ls *LyService) GetCoefficientAndPrice(sku model.LySku) model.LySku {
//是否找到对应的折扣系数,找不到就去找默认
findedDiscountRatio := false
//如果有默认系数,那么就去找默认系数
if isDefaultDiscoutRatio {
if isDefaultDiscountRatio {
} else {
//拿到系数以后,就要去计算
//拿出里面的所有排序,以人民币系数为准
......
......@@ -65,32 +65,62 @@ func (ps *PriceService) GenerateLadderPrice(sku model.LySku) (generatedLadderPri
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}
fixedRatio = map[int]float64{moq: 1.11, 30: 1.1, 100: 1.09, 300: 1.08, 1000: 1.07}
break
case sku.Moq < 30:
//fixedRatio = map[int]float64{moq: 1.07, 50: 1.08, 200: 1.09, 500: 1.1, 1000: 1.11}
fixedRatio = map[int]float64{moq: 1.11, 50: 1.1, 200: 1.09, 500: 1.08, 1000: 1.07}
break
default:
//fixedRatio = map[int]float64{moq: 1.07, 200: 1.08, 500: 1.09, 1000: 1.1, 2000: 1.11}
fixedRatio = map[int]float64{moq: 1.11, 200: 1.1, 500: 1.09, 1000: 1.08, 2000: 1.07}
break
}
//当起订量是小于等于50的时候,阶梯数量和阶梯数是固定的,但是具体的利润还是要去取配置的值,因为固定死的阶梯数量是5,所以这边要直接取魔方配置9个的后5个
costLadderPriceRatio := gjson.Get(priceRatio, "cost_ladder_price_egt50_lt200").Map()
if len(costLadderPriceRatio) == 9 {
//priceRatioAndPurchases := costLadderPriceRatio[strconv.Itoa(i)]
//priceCnRatio := priceRatioAndPurchases.Get("price").Float()
var fixedPurchases []int
switch {
case sku.Moq < 10:
fixedPurchases = []int{moq, 30, 100, 300, 1000}
break
case sku.Moq < 30:
fixedPurchases = []int{moq, 50, 200, 500, 1000}
break
default:
fixedPurchases = []int{moq, 200, 500, 1000, 2000}
break
}
for index, purchase := range fixedPurchases {
//costLadderPriceRatio这个redis是字典,下标从1开始的,所以要从第5个开始取
ratio := costLadderPriceRatio[strconv.Itoa(5+index)].Get("price").Float()
ratioUsd := costLadderPriceRatio[strconv.Itoa(5+index)].Get("price_us").Float()
//同时还要构建价格系数展示在商品服务
showPriceRatio = append(showPriceRatio, model.PriceRatio{Ratio: ratio, RatioUsd: ratioUsd})
generatedLadderPrice = append(generatedLadderPrice, model.LadderPrice{
Purchases: int64(purchase),
PriceCn: c.MyRound(c.MulFloat(costPriceCn, ratio), 4),
PriceUs: c.MyRound(c.MulFloat(costPriceUs, ratioUsd), 4),
})
}
//然后根据一开始只有一个的阶梯价去生成阶梯价格
for purchases, ratio := range fixedRatio {
//同时还要构建价格系数展示在商品服务
showPriceRatio = append(showPriceRatio, model.PriceRatio{Ratio: ratio, RatioUsd: ratio})
generatedLadderPrice = append(generatedLadderPrice, model.LadderPrice{
Purchases: int64(purchases),
PriceCn: c.MyRound(c.MulFloat(costPriceCn, ratio), 4),
PriceUs: c.MyRound(c.MulFloat(costPriceUs, ratio), 4),
})
} else {
//如果魔方不是9个阶梯,那么就是魔方配置出问题了,还是要走固定的配置(主要是为了防止卖亏)
//var fixedRatioSlice map[int]float64
switch {
case sku.Moq < 10:
fixedRatio = map[int]float64{moq: 1.11, 30: 1.1, 100: 1.09, 300: 1.08, 1000: 1.07}
break
case sku.Moq < 30:
fixedRatio = map[int]float64{moq: 1.11, 50: 1.1, 200: 1.09, 500: 1.08, 1000: 1.07}
break
default:
fixedRatio = map[int]float64{moq: 1.11, 200: 1.1, 500: 1.09, 1000: 1.08, 2000: 1.07}
break
}
//然后根据一开始只有一个的阶梯价去生成阶梯价格
for purchases, ratio := range fixedRatio {
//同时还要构建价格系数展示在商品服务
showPriceRatio = append(showPriceRatio, model.PriceRatio{Ratio: ratio, RatioUsd: ratio})
generatedLadderPrice = append(generatedLadderPrice, model.LadderPrice{
Purchases: int64(purchases),
PriceCn: c.MyRound(c.MulFloat(costPriceCn, ratio), 4),
PriceUs: c.MyRound(c.MulFloat(costPriceUs, ratio), 4),
})
}
}
sort.Slice(showPriceRatio, func(i, j int) bool {
return showPriceRatio[i].Ratio > showPriceRatio[j].Ratio
})
......
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