Commit 54266907 by 杨树贤

优化

parent f1d51788
...@@ -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,
......
...@@ -174,7 +174,7 @@ func (ps *PriceService) GenerateLadderPrice(sku model.LySku) model.LySku { ...@@ -174,7 +174,7 @@ func (ps *PriceService) GenerateLadderPrice(sku model.LySku) model.LySku {
//是否有设置最低利润点阶梯,不足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)
...@@ -603,19 +603,31 @@ func (ps PriceService) GetPriceRatio(sku model.LySku) (model.LySku, []model.Pric ...@@ -603,19 +603,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