Commit ce80840a by 杨树贤

兼容人民币转换

parent 86ea8bda
...@@ -2,7 +2,6 @@ package service ...@@ -2,7 +2,6 @@ package service
import ( import (
"encoding/json" "encoding/json"
"fmt"
"go_sku_server/model" "go_sku_server/model"
c "go_sku_server/pkg/common" c "go_sku_server/pkg/common"
"go_sku_server/pkg/gredis" "go_sku_server/pkg/gredis"
...@@ -348,7 +347,6 @@ func (ls *LyService) GetCoefficientAndPrice(sku model.LySku) model.LySku { ...@@ -348,7 +347,6 @@ func (ls *LyService) GetCoefficientAndPrice(sku model.LySku) model.LySku {
ladderPrice = sku.LadderPrice ladderPrice = sku.LadderPrice
} }
} }
fmt.Println("原始价格", sku.OriginalPrice)
//获取折扣系数 //获取折扣系数
sku = priceService.GetDiscountRatio(sku) sku = priceService.GetDiscountRatio(sku)
data = make([]model.LadderPrice, len(ladderPrice)) data = make([]model.LadderPrice, len(ladderPrice))
......
package service package service
import ( import (
"fmt"
"go_sku_server/model" "go_sku_server/model"
c "go_sku_server/pkg/common" c "go_sku_server/pkg/common"
"go_sku_server/pkg/gredis" "go_sku_server/pkg/gredis"
...@@ -20,6 +21,7 @@ type PriceService struct { ...@@ -20,6 +21,7 @@ type PriceService struct {
// 构建专营的阶梯价,现在专营只会存一个简单的成本价,阶梯数量是1,所以我这边要根据专营的阶梯系数去构建具体的阶梯价 // 构建专营的阶梯价,现在专营只会存一个简单的成本价,阶梯数量是1,所以我这边要根据专营的阶梯系数去构建具体的阶梯价
// 还要需要注意的一点是,价格体系改版后华云的sku,也会进入这个判断,毕竟华云的sku也是属于专营的 // 还要需要注意的一点是,价格体系改版后华云的sku,也会进入这个判断,毕竟华云的sku也是属于专营的
// 现在还有新的逻辑,就是判断售价组如果设置为type=2的时候,要根据规则生成阶梯和价格(阶梯是固定的)
func (ps *PriceService) GenerateLadderPrice(sku model.LySku) model.LySku { func (ps *PriceService) GenerateLadderPrice(sku model.LySku) model.LySku {
//需要展示的价格系数 //需要展示的价格系数
var showPriceRatioList []model.PriceRatio var showPriceRatioList []model.PriceRatio
...@@ -81,7 +83,7 @@ func (ps *PriceService) GenerateLadderPrice(sku model.LySku) model.LySku { ...@@ -81,7 +83,7 @@ func (ps *PriceService) GenerateLadderPrice(sku model.LySku) model.LySku {
priceRatio.Purchases = gjson.Get(value.String(), "purchases").Int() priceRatio.Purchases = gjson.Get(value.String(), "purchases").Int()
priceRatioList = append(priceRatioList, priceRatio) priceRatioList = append(priceRatioList, priceRatio)
} }
//是否满足特定条件的判断 //是否满足特定条件的判断
var hasSpecialCheck = false var hasSpecialCheck = false
conditionsMet := true conditionsMet := true
...@@ -194,15 +196,20 @@ func (ps *PriceService) GenerateLadderPrice(sku model.LySku) model.LySku { ...@@ -194,15 +196,20 @@ func (ps *PriceService) GenerateLadderPrice(sku model.LySku) model.LySku {
//这是用来展示在商品服务的价格系数,专营的系数和代购的不一样,所以要转换一下展示形式 //这是用来展示在商品服务的价格系数,专营的系数和代购的不一样,所以要转换一下展示形式
//是否有设置最低利润点阶梯,不足5个阶梯时,最高阶梯对应的最小利润点阶梯 //是否有设置最低利润点阶梯,不足5个阶梯时,最高阶梯对应的最小利润点阶梯
//这里还要去获取type字段,因为这个是判断阶梯价类型的设置,如果是1的话,还是走以前的逻辑
//type=2的话,就要去找人工固定阶梯的逻辑
var ladderPriceMiniProfitLevel int var ladderPriceMiniProfitLevel int
//fmt.Println("是否找到系数", foundRatio) var ladderType int
//fmt.Println("系数redis数据为 : ", priceRatioCache) // fmt.Println("是否找到系数", foundRatio)
//fmt.Println("具体系数为 : ", priceRatioList) // fmt.Println("具体系数为 : ", priceRatioList)
if foundRatio { if foundRatio {
priceRatioSortStr := strconv.Itoa(priceRatioSort) priceRatioSortStr := strconv.Itoa(priceRatioSort)
ladderPriceMiniProfitLevel = int(gjson.Get(priceRatioCache, "ladder_price_mini_profit_level."+priceRatioSortStr).Int()) ladderPriceMiniProfitLevel = int(gjson.Get(priceRatioCache, "ladder_price_mini_profit_level."+priceRatioSortStr).Int())
ladderType = int(gjson.Get(priceRatioCache, "type."+priceRatioSortStr).Int())
fmt.Println(priceRatioSortStr)
} else { } else {
ladderPriceMiniProfitLevel = int(gjson.Get(priceRatioCache, "ladder_price_mini_profit_level").Int()) ladderPriceMiniProfitLevel = int(gjson.Get(priceRatioCache, "ladder_price_mini_profit_level").Int())
ladderType = 1
} }
//fmt.Println("最低利润点阶梯数 : ", ladderPriceMiniProfitLevel) //fmt.Println("最低利润点阶梯数 : ", ladderPriceMiniProfitLevel)
var generatedLadderPrice []model.LadderPrice var generatedLadderPrice []model.LadderPrice
...@@ -210,7 +217,6 @@ func (ps *PriceService) GenerateLadderPrice(sku model.LySku) model.LySku { ...@@ -210,7 +217,6 @@ func (ps *PriceService) GenerateLadderPrice(sku model.LySku) model.LySku {
//先直接获取成本价原始值,判断第一个阶梯的阶梯数量是否为0,如果是0,那么代表是要走成本价生成,如果不是0,那么就要走阶梯价生成 //先直接获取成本价原始值,判断第一个阶梯的阶梯数量是否为0,如果是0,那么代表是要走成本价生成,如果不是0,那么就要走阶梯价生成
firstLadderPurchases := sku.LadderPrice[0].Purchases firstLadderPurchases := sku.LadderPrice[0].Purchases
isCostPrice := bool(firstLadderPurchases == 0) isCostPrice := bool(firstLadderPurchases == 0)
//判断是否走成本价判断还是走阶梯价判断,因为上传sku的时候,可以设置每个sku的成本价(人民币&&美金),也可以设置每个sku的阶梯价 //判断是否走成本价判断还是走阶梯价判断,因为上传sku的时候,可以设置每个sku的成本价(人民币&&美金),也可以设置每个sku的阶梯价
//如果有阶梯价,就要跳过设置的成本价(假设有设置的话) //如果有阶梯价,就要跳过设置的成本价(假设有设置的话)
if isCostPrice { if isCostPrice {
...@@ -365,38 +371,64 @@ func (ps *PriceService) GenerateLadderPrice(sku model.LySku) model.LySku { ...@@ -365,38 +371,64 @@ func (ps *PriceService) GenerateLadderPrice(sku model.LySku) model.LySku {
sku.PriceRatio = showPriceRatioList sku.PriceRatio = showPriceRatioList
return sku return sku
} else { } else {
//fmt.Println(ladderPriceRatio)
ladderCount := len(sku.LadderPrice) ladderCount := len(sku.LadderPrice)
if len(priceRatioList) == 0 { if len(priceRatioList) == 0 {
return sku return sku
} }
fmt.Println(ladderType)
//走阶梯价 //走阶梯价
//type = 2 的时候,阶梯都是少于等于ladderPriceMiniProfitLevel的
fmt.Println(ladderPriceMiniProfitLevel)
if ladderCount <= ladderPriceMiniProfitLevel { if ladderCount <= ladderPriceMiniProfitLevel {
for i := 0; i < ladderCount; i++ { //这里有新的逻辑,判断售价组系数的类型,如果为1,那么就是走下面的老逻辑,否则就要走固定阶梯逻辑
ladder := sku.LadderPrice[i] if ladderType == 1 {
//利润阶梯索引 for i := 0; i < ladderCount; i++ {
//计算出库存满足了n个价格阶梯之后 从最小利润点层级反向取n个层级,然后正序计算 如:库存满足1、2、3层阶梯,最小利润点层级是第5个层级,则利润点取3、4、5层级的
//最小利润点层级 - 库存满足多少个阶梯 + i ladder := sku.LadderPrice[i]
costMapIndex := ladderPriceMiniProfitLevel - ladderCount + i //利润阶梯索引
if costMapIndex <= 0 { //计算出库存满足了n个价格阶梯之后 从最小利润点层级反向取n个层级,然后正序计算 如:库存满足1、2、3层阶梯,最小利润点层级是第5个层级,则利润点取3、4、5层级的
costMapIndex = 0 //最小利润点层级 - 库存满足多少个阶梯 + i
costMapIndex := ladderPriceMiniProfitLevel - ladderCount + i
if costMapIndex <= 0 {
costMapIndex = 0
}
priceRatio := priceRatioList[costMapIndex]
priceCnRatio := priceRatio.Ratio
priceUsRatio := priceRatio.RatioUsd
// 阶梯价格系数正序取
generatedLadderPrice = append(generatedLadderPrice, model.LadderPrice{
Purchases: ladder.Purchases,
PriceCn: c.MyRound(c.MulFloat(ladder.PriceCn, priceCnRatio), 5),
PriceUs: c.MyRound(c.MulFloat(ladder.PriceUs, priceUsRatio), 5),
})
showPriceRatioList = append(showPriceRatioList, model.PriceRatio{
Ratio: priceCnRatio,
RatioUsd: priceUsRatio,
Purchases: int64(ladder.Purchases),
})
}
} else {
ladder := sku.LadderPrice[0]
//因为走的是固定阶梯数量,所以要以售价组为准
for _, priceRatio := range priceRatioList {
priceCnRatio := priceRatio.Ratio
priceUsRatio := priceRatio.RatioUsd
purchases := priceRatio.Purchases
if purchases == 0 {
continue
}
generatedLadderPrice = append(generatedLadderPrice, model.LadderPrice{
Purchases: purchases,
PriceCn: c.MyRound(c.MulFloat(ladder.PriceCn, priceCnRatio), 5),
PriceUs: c.MyRound(c.MulFloat(ladder.PriceUs, priceUsRatio), 5),
})
showPriceRatioList = append(showPriceRatioList, model.PriceRatio{
Ratio: priceCnRatio,
RatioUsd: priceUsRatio,
Purchases: int64(purchases),
})
} }
//fmt.Println(costMapIndex)
priceRatio := priceRatioList[costMapIndex]
priceCnRatio := priceRatio.Ratio
priceUsRatio := priceRatio.RatioUsd
// 阶梯价格系数正序取
//fmt.Println("价格:",c.MulFloat(ladder.PriceCn, priceCnRatio))
generatedLadderPrice = append(generatedLadderPrice, model.LadderPrice{
Purchases: ladder.Purchases,
PriceCn: c.MyRound(c.MulFloat(ladder.PriceCn, priceCnRatio), 5),
PriceUs: c.MyRound(c.MulFloat(ladder.PriceUs, priceUsRatio), 5),
})
showPriceRatioList = append(showPriceRatioList, model.PriceRatio{
Ratio: priceCnRatio,
RatioUsd: priceUsRatio,
Purchases: int64(ladder.Purchases),
})
} }
} else { } else {
//价格阶梯数量超过最利润点的层级的情况 //价格阶梯数量超过最利润点的层级的情况
......
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