Commit ef237a7d by 杨树贤

Merge branch 'ysx-价格体系修改-20230815' into dev

parents 1c68ef1c 99d38893
...@@ -2,6 +2,7 @@ package service ...@@ -2,6 +2,7 @@ package service
import ( import (
"encoding/json" "encoding/json"
"fmt"
"github.com/gomodule/redigo/redis" "github.com/gomodule/redigo/redis"
_ "github.com/iancoleman/orderedmap" _ "github.com/iancoleman/orderedmap"
"github.com/syyongx/php2go" "github.com/syyongx/php2go"
...@@ -276,6 +277,7 @@ func (ls *LyService) GetCoefficientAndPrice(sku model.LySku) model.LySku { ...@@ -276,6 +277,7 @@ func (ls *LyService) GetCoefficientAndPrice(sku model.LySku) model.LySku {
if ladderPrice[0].PriceCostUs == 0 && ladderPrice[0].PriceCostCn == 0 { if ladderPrice[0].PriceCostUs == 0 && ladderPrice[0].PriceCostCn == 0 {
sku = priceService.GenerateLadderPrice(sku) sku = priceService.GenerateLadderPrice(sku)
ladderPrice = sku.LadderPrice ladderPrice = sku.LadderPrice
fmt.Println(ladderPrice)
} }
} }
//获取折扣系数 //获取折扣系数
...@@ -283,6 +285,7 @@ func (ls *LyService) GetCoefficientAndPrice(sku model.LySku) model.LySku { ...@@ -283,6 +285,7 @@ func (ls *LyService) GetCoefficientAndPrice(sku model.LySku) model.LySku {
data = make([]model.LadderPrice, len(ladderPrice)) data = make([]model.LadderPrice, len(ladderPrice))
for key, price := range ladderPrice { for key, price := range ladderPrice {
price.PriceUs = priceService.TransformSpecialSupplierPrice(sku, price.PriceUs)
if price.Purchases == 0 { if price.Purchases == 0 {
continue continue
} }
...@@ -385,7 +388,6 @@ func (ls *LyService) GetCoefficientAndPrice(sku model.LySku) model.LySku { ...@@ -385,7 +388,6 @@ func (ls *LyService) GetCoefficientAndPrice(sku model.LySku) model.LySku {
if !hasCoefficient { if !hasCoefficient {
coefficient = defaultCoefficient coefficient = defaultCoefficient
} }
//下面是计算价格 //下面是计算价格
//价格计算文档 https://docs.qq.com/doc/DR3RJcnNPeUNkWHRk //价格计算文档 https://docs.qq.com/doc/DR3RJcnNPeUNkWHRk
// 为何是固定的1.13,关税基本不会变,有变的话跟产品沟通手动修改即可 // 为何是固定的1.13,关税基本不会变,有变的话跟产品沟通手动修改即可
...@@ -393,7 +395,7 @@ func (ls *LyService) GetCoefficientAndPrice(sku model.LySku) model.LySku { ...@@ -393,7 +395,7 @@ func (ls *LyService) GetCoefficientAndPrice(sku model.LySku) model.LySku {
for key, price := range sku.LadderPrice { for key, price := range sku.LadderPrice {
//这里有个前置条件处理美金价,因为element(6)存到美金字段里面的是港币,rs(21)存到美金字段里的是人民币,buerklin(1676)是欧元 //这里有个前置条件处理美金价,因为element(6)存到美金字段里面的是港币,rs(21)存到美金字段里的是人民币,buerklin(1676)是欧元
//所以要全部先转成正确的美金价才能显示,目前先写死汇率,因为目前没有地方能获取实时的各种转美金的汇率 //所以要全部先转成正确的美金价才能显示,目前先写死汇率,因为目前没有地方能获取实时的各种转美金的汇率
price.PriceUs = priceService.TransformSpecialSupplierPrice(sku.SupplierId, price.PriceUs, coefficient.Ratio) price.PriceUs = priceService.TransformSpecialSupplierPrice(sku, price.PriceUs)
originalPrice = append(originalPrice, model.OriginPrice{ originalPrice = append(originalPrice, model.OriginPrice{
PriceUs: price.PriceUs, PriceUs: price.PriceUs,
Purchases: price.Purchases, Purchases: price.Purchases,
......
...@@ -19,6 +19,8 @@ type PriceService struct { ...@@ -19,6 +19,8 @@ type PriceService struct {
// 构建专营的阶梯价,现在专营只会存一个简单的成本价,阶梯数量是1,所以我这边要根据专营的阶梯系数去构建具体的阶梯价 // 构建专营的阶梯价,现在专营只会存一个简单的成本价,阶梯数量是1,所以我这边要根据专营的阶梯系数去构建具体的阶梯价
func (ps *PriceService) GenerateLadderPrice(sku model.LySku) model.LySku { func (ps *PriceService) GenerateLadderPrice(sku model.LySku) model.LySku {
//需要展示的价格系数
var showPriceRatioList []model.PriceRatio
//先去找到对应的价格系数 //先去找到对应的价格系数
var ratioDataKey string var ratioDataKey string
if sku.Moq <= 50 { if sku.Moq <= 50 {
...@@ -167,14 +169,13 @@ func (ps *PriceService) GenerateLadderPrice(sku model.LySku) model.LySku { ...@@ -167,14 +169,13 @@ func (ps *PriceService) GenerateLadderPrice(sku model.LySku) model.LySku {
} }
priceRatioSort = -1 priceRatioSort = -1
} }
sku.PriceRatio = priceRatioList
sku.PriceRatioSort = priceRatioSort sku.PriceRatioSort = priceRatioSort
//这是用来展示在商品服务的价格系数,专营的系数和代购的不一样,所以要转换一下展示形式 //这是用来展示在商品服务的价格系数,专营的系数和代购的不一样,所以要转换一下展示形式
//是否有设置最低利润点阶梯,不足5个阶梯时,最高阶梯对应的最小利润点阶梯 //是否有设置最低利润点阶梯,不足5个阶梯时,最高阶梯对应的最小利润点阶梯
var ladderPriceMiniProfitLevel int var ladderPriceMiniProfitLevel int
fmt.Println("是否找到系数", foundRatio) fmt.Println("是否找到系数", foundRatio)
fmt.Println("系数redis数据为 : ", priceRatioCache) //fmt.Println("系数redis数据为 : ", priceRatioCache)
fmt.Println("具体系数为 : ", priceRatioList) fmt.Println("具体系数为 : ", priceRatioList)
if foundRatio { if foundRatio {
priceRatioSortStr := strconv.Itoa(priceRatioSort) priceRatioSortStr := strconv.Itoa(priceRatioSort)
...@@ -213,16 +214,21 @@ func (ps *PriceService) GenerateLadderPrice(sku model.LySku) model.LySku { ...@@ -213,16 +214,21 @@ func (ps *PriceService) GenerateLadderPrice(sku model.LySku) model.LySku {
fixedPurchases = []int{moq, 200, 500, 1000, 2000} fixedPurchases = []int{moq, 200, 500, 1000, 2000}
break break
} }
for index, purchase := range fixedPurchases { for index, purchases := range fixedPurchases {
//costLadderPriceRatio这个redis是字典,下标从0开始的,所以要从第5个开始取 //costLadderPriceRatio这个redis是字典,下标从0开始的,所以要从第5个开始取
ratio := priceRatioList[4+index].Ratio ratio := priceRatioList[4+index].Ratio
ratioUsd := priceRatioList[4+index].RatioUsd ratioUsd := priceRatioList[4+index].RatioUsd
//同时还要构建价格系数展示在商品服务 //同时还要构建价格系数展示在商品服务
generatedLadderPrice = append(generatedLadderPrice, model.LadderPrice{ generatedLadderPrice = append(generatedLadderPrice, model.LadderPrice{
Purchases: int64(purchase), 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, ratioUsd), 4), PriceUs: c.MyRound(c.MulFloat(costPriceUs, ratioUsd), 4),
}) })
showPriceRatioList = append(showPriceRatioList, model.PriceRatio{
Ratio: ratio,
RatioUsd: ratioUsd,
Purchases: int64(purchases),
})
} }
} else { } else {
...@@ -247,6 +253,11 @@ func (ps *PriceService) GenerateLadderPrice(sku model.LySku) model.LySku { ...@@ -247,6 +253,11 @@ func (ps *PriceService) GenerateLadderPrice(sku model.LySku) model.LySku {
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),
}) })
showPriceRatioList = append(showPriceRatioList, model.PriceRatio{
Ratio: ratio,
RatioUsd: ratio,
Purchases: int64(purchases),
})
} }
} }
...@@ -254,6 +265,8 @@ func (ps *PriceService) GenerateLadderPrice(sku model.LySku) model.LySku { ...@@ -254,6 +265,8 @@ func (ps *PriceService) GenerateLadderPrice(sku model.LySku) model.LySku {
return generatedLadderPrice[i].Purchases < generatedLadderPrice[j].Purchases return generatedLadderPrice[i].Purchases < generatedLadderPrice[j].Purchases
}) })
sku.LadderPrice = generatedLadderPrice sku.LadderPrice = generatedLadderPrice
sku.PriceRatio = showPriceRatioList
return sku return sku
} }
fmt.Println("是成本价") fmt.Println("是成本价")
...@@ -296,6 +309,11 @@ func (ps *PriceService) GenerateLadderPrice(sku model.LySku) model.LySku { ...@@ -296,6 +309,11 @@ func (ps *PriceService) GenerateLadderPrice(sku model.LySku) model.LySku {
PriceCn: c.MyRound(c.MulFloat(costPriceCn, priceCnRatio), 4), PriceCn: c.MyRound(c.MulFloat(costPriceCn, priceCnRatio), 4),
PriceUs: c.MyRound(c.MulFloat(costPriceUs, priceUsRatio), 4), PriceUs: c.MyRound(c.MulFloat(costPriceUs, priceUsRatio), 4),
}) })
showPriceRatioList = append(showPriceRatioList, model.PriceRatio{
Ratio: priceCnRatio,
RatioUsd: priceUsRatio,
Purchases: int64(costPurchases),
})
} }
} else { } else {
//价格阶梯数量超过最利润点的层级的情况 //价格阶梯数量超过最利润点的层级的情况
...@@ -315,9 +333,15 @@ func (ps *PriceService) GenerateLadderPrice(sku model.LySku) model.LySku { ...@@ -315,9 +333,15 @@ func (ps *PriceService) GenerateLadderPrice(sku model.LySku) model.LySku {
PriceCn: c.MyRound(c.MulFloat(costPriceCn, priceCnRatio), 4), PriceCn: c.MyRound(c.MulFloat(costPriceCn, priceCnRatio), 4),
PriceUs: c.MyRound(c.MulFloat(costPriceUs, priceUsRatio), 4), PriceUs: c.MyRound(c.MulFloat(costPriceUs, priceUsRatio), 4),
}) })
showPriceRatioList = append(showPriceRatioList, model.PriceRatio{
Ratio: priceCnRatio,
RatioUsd: priceUsRatio,
Purchases: int64(costPurchases),
})
} }
} }
sku.LadderPrice = generatedLadderPrice sku.LadderPrice = generatedLadderPrice
sku.PriceRatio = showPriceRatioList
return sku return sku
} else { } else {
//fmt.Println(ladderPriceRatio) //fmt.Println(ladderPriceRatio)
...@@ -344,6 +368,11 @@ func (ps *PriceService) GenerateLadderPrice(sku model.LySku) model.LySku { ...@@ -344,6 +368,11 @@ func (ps *PriceService) GenerateLadderPrice(sku model.LySku) model.LySku {
PriceCn: c.MyRound(c.MulFloat(ladder.PriceCn, priceCnRatio), 4), PriceCn: c.MyRound(c.MulFloat(ladder.PriceCn, priceCnRatio), 4),
PriceUs: c.MyRound(c.MulFloat(ladder.PriceUs, priceUsRatio), 4), PriceUs: c.MyRound(c.MulFloat(ladder.PriceUs, priceUsRatio), 4),
}) })
showPriceRatioList = append(showPriceRatioList, model.PriceRatio{
Ratio: priceCnRatio,
RatioUsd: priceUsRatio,
Purchases: int64(ladder.Purchases),
})
} }
} else { } else {
...@@ -360,8 +389,14 @@ func (ps *PriceService) GenerateLadderPrice(sku model.LySku) model.LySku { ...@@ -360,8 +389,14 @@ func (ps *PriceService) GenerateLadderPrice(sku model.LySku) model.LySku {
PriceCn: c.MyRound(c.MulFloat(ladder.PriceCn, priceCnRatio), 4), PriceCn: c.MyRound(c.MulFloat(ladder.PriceCn, priceCnRatio), 4),
PriceUs: c.MyRound(c.MulFloat(ladder.PriceUs, priceUsRatio), 4), PriceUs: c.MyRound(c.MulFloat(ladder.PriceUs, priceUsRatio), 4),
}) })
showPriceRatioList = append(showPriceRatioList, model.PriceRatio{
Ratio: priceCnRatio,
RatioUsd: priceUsRatio,
Purchases: int64(ladder.Purchases),
})
} }
} }
sku.PriceRatio = showPriceRatioList
sku.LadderPrice = generatedLadderPrice sku.LadderPrice = generatedLadderPrice
return sku return sku
} }
...@@ -603,19 +638,31 @@ func (ps PriceService) GetPriceRatio(sku model.LySku) (model.LySku, []model.Pric ...@@ -603,19 +638,31 @@ func (ps PriceService) GetPriceRatio(sku model.LySku) (model.LySku, []model.Pric
return sku, priceRatioList return sku, priceRatioList
} }
// TransformSpecialSupplierPrice 这里有个前置条件处理美金价,因为element(6)存到美金字段里面的是港币,rs(21)存到美金字段里的是人民币,buerklin(1676)是欧元 // 这里有个前置条件处理美金价,因为element(6)存到美金字段里面的是港币,rs(21)存到美金字段里的是人民币,buerklin(1676)是欧元
// 所以要全部先转成正确的美金价才能显示 // 所以要全部先转成正确的美金价才能显示
func (ps *PriceService) TransformSpecialSupplierPrice(supplierId int64, priceUs float64, usRatio float64) float64 { func (ps *PriceService) TransformSpecialSupplierPrice(sku model.LySku, priceUs float64) float64 {
//去redis获取价格 //去redis获取价格
redisCon := gredis.Conn("default_r") redisCon := gredis.Conn("default_r")
defer func() { defer func() {
redisCon.Close() redisCon.Close()
}() }()
currency, _ := redis.Int(redisCon.Do("HGET", "magic_cube_supplier_currency", supplierId)) usRatio, _ := redis.Float64(redisCon.Do("HGET", "erp_rate", 2))
var currency int
//这个供应商把人民币存到美金这个字段了,所以要提前判断和返回
if sku.SupplierId == 6 {
priceUs = c.MyRound(c.DivFloat(priceUs, usRatio), 4)
return priceUs
}
if sku.SupplierId != 17 {
currency, _ = redis.Int(redisCon.Do("HGET", "magic_cube_supplier_currency", sku.SupplierId))
} else {
currency, _ = redis.Int(redisCon.Do("HGET", "magic_cube_supplier_currency", sku.Canal))
}
if currency > 0 { if currency > 0 {
//这里进行转换,因为这里都只能取到对应的币种转人民币的比率,我们没有直接各种币种转美金的数据,所以我这边要 //这里进行转换,因为这里都只能取到对应的币种转人民币的比率,我们没有直接各种币种转美金的数据,所以我这边要
//先根据对应币种转人民币,然后根据人民币转美金,才能得到不同币种对应美金的汇率 //先根据对应币种转人民币,然后根据人民币转美金,才能得到不同币种对应美金的汇率
rmbRatio, _ := redis.Float64(redisCon.Do("HGET", "erp_rate", currency)) rmbRatio, _ := redis.Float64(redisCon.Do("HGET", "erp_rate", currency))
fmt.Println("特殊转换", rmbRatio)
//人民币汇率转美金汇率 //人民币汇率转美金汇率
usRatio = c.MyRound(c.DivFloat(rmbRatio, usRatio), 2) usRatio = c.MyRound(c.DivFloat(rmbRatio, usRatio), 2)
priceUs = c.MyRound(c.DivFloat(priceUs, usRatio), 4) priceUs = c.MyRound(c.DivFloat(priceUs, usRatio), 4)
......
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