Commit 60aa49b9 by mushishixian

Merge branch 'ysx-起订量小于50利润取值-20230703' into dev

parents 86923950 1071482a
......@@ -57,7 +57,7 @@ func (ls *LyService) LyGoodsDetail(ctx *gin.Context, goodsIds []string, ch chan
sku.GoodsId = goodsId
spu := spuList[sku.SpuId]
//读取包装字段的缓存
if sku.SupplierId == 7 {
if sku.SupplierId == 7 || sku.SupplierId == 13 {
//sku_raw_map哪里写入(成意写的)
packing, _ := redis.String(redisConn.Do("HGET", "sku_raw_map", goodsId))
sku.Packing = gjson.Get(packing, "pack").String()
......
......@@ -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 {
//拿到系数以后,就要去计算
//拿出里面的所有排序,以人民币系数为准
......
package service
import (
"fmt"
"github.com/gomodule/redigo/redis"
"github.com/tidwall/gjson"
"go_sku_server/model"
......@@ -61,34 +60,70 @@ func (ps *PriceService) GenerateLadderPrice(sku model.LySku) (generatedLadderPri
if isCostPrice {
costPriceCn := sku.LadderPrice[0].PriceCn
costPriceUs := sku.LadderPrice[0].PriceUs
fmt.Println("人民币和美金的成本价分别为 : ", costPriceCn, costPriceUs)
//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
}
//当起订量是小于等于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
})
sku.PriceRatio = showPriceRatio
sort.Slice(generatedLadderPrice, func(i, j int) bool {
......@@ -113,8 +148,8 @@ func (ps *PriceService) GenerateLadderPrice(sku model.LySku) (generatedLadderPri
}
costLadderCount++
}
fmt.Println("阶梯数量为 : ", costLadderCount)
fmt.Println("设置的利润阶梯为 : ", ladderPriceMiniProfitLevel)
//fmt.Println("阶梯数量为 : ", costLadderCount)
//fmt.Println("设置的利润阶梯为 : ", ladderPriceMiniProfitLevel)
if costLadderCount <= ladderPriceMiniProfitLevel {
for i := 1; i <= costLadderCount; i++ {
priceRatioAndPurchases := costLadderPriceRatio[strconv.Itoa(i)]
......@@ -134,7 +169,7 @@ func (ps *PriceService) GenerateLadderPrice(sku model.LySku) (generatedLadderPri
costMapIndex = 1
}
priceRatioAndPurchases = costLadderPriceRatio[strconv.Itoa(costMapIndex)]
fmt.Println("获取到的阶梯系数为 : ", priceRatioAndPurchases)
//fmt.Println("获取到的阶梯系数为 : ", priceRatioAndPurchases)
priceCnRatio := priceRatioAndPurchases.Get("price").Float()
priceUsRatio := priceRatioAndPurchases.Get("price_usd").Float()
// 阶梯价格系数正序取
......@@ -171,7 +206,7 @@ func (ps *PriceService) GenerateLadderPrice(sku model.LySku) (generatedLadderPri
return generatedLadderPrice, showPriceRatio
} else {
ladderPriceRatio := gjson.Get(priceRatio, "ladder_price_egt50_lt200").Map()
fmt.Println(ladderPriceRatio)
//fmt.Println(ladderPriceRatio)
ladderCount := len(sku.LadderPrice)
//走阶梯价
if ladderCount <= ladderPriceMiniProfitLevel {
......@@ -184,9 +219,9 @@ func (ps *PriceService) GenerateLadderPrice(sku model.LySku) (generatedLadderPri
if costMapIndex <= 0 {
costMapIndex = 1
}
fmt.Println(costMapIndex)
//fmt.Println(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})
......
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