Commit eeaa4575 by 杨树贤

Merge branch 'ysx-特殊币种人民币是否含税-20230828'

parents 59aa7627 2769553c
package model
//联营统一返回格式
// 联营统一返回格式
type LyResponse struct {
ErrorCode int `json:"error_code"`
ErrorMsg string `json:"error_msg"`
Data interface{} `json:"data"`
}
//原始sku梯度
// 原始sku梯度
type LadderPrice struct {
Purchases int64 `json:"purchases"` //购买数量
PriceUs float64 `json:"price_us,omitempty"` //数量对应的英文价格
......@@ -27,13 +27,21 @@ type OriginPrice struct {
CostPrice float64 `json:"cost_price"`
}
//立创价格梯度
type DatabasePrice struct {
Purchases int64 `json:"purchases"` //购买数量
PriceUs float64 `json:"price_us"` //数量对应的英文价格
PriceCn float64 `json:"price_cn"` //数量对应的中文价格
PriceAc float64 `json:"price_ac,omitempty"`
CostPrice float64 `json:"cost_price"`
}
// 立创价格梯度
type LadderPriceLc struct {
Purchases int64 `json:"purchases"` //购买数量
Price float64 `json:"price"` //立创价格,人民币
}
//自营属性列表
// 自营属性列表
type Attrs struct {
AttrName string `json:"attr_name"` //属性名称
AttrValue string `json:"attr_value"` //属性值
......
......@@ -39,8 +39,10 @@ type LySku struct {
AllowCoupon int `json:"allow_coupon"`
BrandId int64 `json:"brand_id"`
//系数相关
Coefficient interface{} `json:"coefficient,omitempty"`
Original interface{} `json:"original_price,omitempty"`
Coefficient interface{} `json:"coefficient,omitempty"`
OriginalPrice []OriginPrice `json:"original_price,omitempty"`
//数据库存的价格,因为数据库存的是什么币种都有可能,但是也要展示数据库存的,所以要有这个字段
DatabasePrice interface{} `json:"database_price,omitempty"`
SuppExtendFee interface{} `json:"supp_extend_fee"`
IsBuy int `json:"is_buy"`
//spu信息
......@@ -67,17 +69,18 @@ type LySku struct {
AcType int `json:"ac_type"`
//活动信息
HasGiftActivity int `json:"has_gift_activity"`
GiftActivity GiftActivity `json:"gift_activity"`
ActivityInfo PriceActivity `json:"activity_info"`
StandardBrand StandardBrand `json:"standard_brand"`
GoodsTag GoodsTag `json:"goods_tag"`
StockInfo interface{} `json:"stock_info"`
Eccn string `json:"eccn"`
DiscountRatio DiscountRatio `json:"discount_ratio"`
PriceRatioSort int `json:"price_ratio_sort"`
PriceRatio []PriceRatio `json:"price_ratio"`
Source int `json:"source"`
HasGiftActivity int `json:"has_gift_activity"`
GiftActivity GiftActivity `json:"gift_activity"`
ActivityInfo PriceActivity `json:"activity_info"`
StandardBrand StandardBrand `json:"standard_brand"`
GoodsTag GoodsTag `json:"goods_tag"`
StockInfo interface{} `json:"stock_info"`
Eccn string `json:"eccn"`
DiscountRatio DiscountRatio `json:"discount_ratio"`
PriceRatioSort int `json:"price_ratio_sort"`
PriceRatio []PriceRatio `json:"price_ratio"`
Source int `json:"source"`
OriginCurrencySymbol string `json:"origin_currency_symbol,omitempty"`
}
type DiscountRatio struct {
......@@ -179,6 +182,8 @@ func InitSkuData(sku string) (data LySku) {
mpq := gjson.Get(sku, "mpq").Int()
data.Mpq = mpq
data.OriginCurrencySymbol = "$"
//递增量
Multiple := gjson.Get(sku, "multiple").Int()
if Multiple > 0 {
......@@ -230,7 +235,8 @@ func InitSkuData(sku string) (data LySku) {
LadderPriceStr := gjson.Get(sku, "ladder_price").String()
data.LadderPrice = getLadderPrice(LadderPriceStr)
data.Original = getOriginPrice(LadderPriceStr)
data.OriginalPrice = getOriginPrice(LadderPriceStr)
data.DatabasePrice = getDatabasePrice(LadderPriceStr)
return
}
......@@ -272,5 +278,26 @@ func getOriginPrice(ladderPriceStr string) (ladderPrice []OriginPrice) {
ladderPrice = []OriginPrice{}
return
}
return
}
// 获取原始价格
func getDatabasePrice(ladderPriceStr string) (ladderPrice []DatabasePrice) {
ladderPriceArr := gjson.Parse(ladderPriceStr).Array()
for _, price := range ladderPriceArr {
ladderPrice = append(ladderPrice, DatabasePrice{
Purchases: price.Get("purchases").Int(),
PriceUs: price.Get("price_us").Float(),
PriceCn: price.Get("price_cn").Float(),
PriceAc: price.Get("price_ac").Float(),
CostPrice: price.Get("cost_price").Float(),
})
}
if len(ladderPrice) == 0 {
ladderPrice = []DatabasePrice{}
return
}
return
}
......@@ -172,21 +172,11 @@ func (ls *LyService) LyGoodsDetail(ctx *gin.Context, goodsIds []string, ch chan
//判断是否可以购买
sku.IsBuy = ls.GetIsBuy(sku)
//过期修改库存为0
if sku.IsExpire == 1 && sku.SupplierId != 17 {
sku.Stock = 0
}
//特殊判断,如果是罗侧斯特的ADI的商品,价格为0,库存为0
if sku.StandardBrand.StandardBrandId == 8 && sku.SupplierId == 3 {
sku.Stock = 0
sku.LadderPriceResult = []int{}
sku.IsBuy = 0
sku.BatchSn = ""
sku.Attrs = []int{}
}
//获取标签信息
var TagService TagsService
sku.GoodsTag = TagService.GetTags(sku.GoodsId, 0)
......
......@@ -11,7 +11,9 @@ import (
"go_sku_server/pkg/gredis"
"go_sku_server/pkg/logger"
_ "go_sku_server/pkg/mongo"
"go_sku_server/service/sorter"
_ "gopkg.in/mgo.v2/bson"
"sort"
"strings"
)
......@@ -267,9 +269,12 @@ func (ls *LyService) GetCoefficientAndPrice(sku model.LySku) model.LySku {
flag := 0
var data []model.LadderPrice
var originalPrice []model.OriginPrice
sort.Sort(sorter.OriginPriceSorter(sku.OriginalPrice))
//专卖价格获取
if sku.SupplierId == 17 {
ladderPrice := sku.LadderPrice
sku = priceService.TransformSpecialSupplierPrice(sku)
//判断redis里面是否有成本价,有的话,那就直接去取价格,不需要生成阶梯价
//如果没有成本价字段,就要去生成阶梯价格
if len(ladderPrice) > 0 {
......@@ -281,10 +286,9 @@ func (ls *LyService) GetCoefficientAndPrice(sku model.LySku) model.LySku {
}
//获取折扣系数
sku = priceService.GetDiscountRatio(sku)
data = make([]model.LadderPrice, len(ladderPrice))
for key, price := range ladderPrice {
price.PriceUs = priceService.TransformSpecialSupplierPrice(sku, price.PriceUs)
if price.Purchases == 0 {
continue
}
......@@ -395,11 +399,9 @@ func (ls *LyService) GetCoefficientAndPrice(sku model.LySku) model.LySku {
//价格计算文档 https://docs.qq.com/doc/DR3RJcnNPeUNkWHRk
// 为何是固定的1.13,关税基本不会变,有变的话跟产品沟通手动修改即可
tax := 1.13
sku = priceService.TransformSpecialSupplierPrice(sku)
var showPriceRatioList []model.PriceRatio
for key, price := range sku.LadderPrice {
//这里有个前置条件处理美金价,因为element(6)存到美金字段里面的是港币,rs(21)存到美金字段里的是人民币,buerklin(1676)是欧元
//所以要全部先转成正确的美金价才能显示,目前先写死汇率,因为目前没有地方能获取实时的各种转美金的汇率
price.PriceUs = priceService.TransformSpecialSupplierPrice(sku, price.PriceUs)
originalPrice = append(originalPrice, model.OriginPrice{
PriceUs: price.PriceUs,
Purchases: price.Purchases,
......@@ -494,7 +496,7 @@ func (ls *LyService) GetCoefficientAndPrice(sku model.LySku) model.LySku {
}
//判断原始价格有变化,那就要覆盖
if len(originalPrice) > 0 {
sku.Original = originalPrice
sku.OriginalPrice = originalPrice
}
//输出税费到前端
......
......@@ -640,7 +640,7 @@ func (ps PriceService) GetPriceRatio(sku model.LySku) (model.LySku, []model.Pric
// 这里有个前置条件处理美金价,因为element(6)存到美金字段里面的是港币,rs(21)存到美金字段里的是人民币,buerklin(1676)是欧元
// 所以要全部先转成正确的美金价才能显示
func (ps *PriceService) TransformSpecialSupplierPrice(sku model.LySku, priceUs float64) float64 {
func (ps *PriceService) TransformSpecialSupplierPrice(sku model.LySku) model.LySku {
//去redis获取价格
redisCon := gredis.Conn("default_r")
defer func() {
......@@ -648,22 +648,38 @@ func (ps *PriceService) TransformSpecialSupplierPrice(sku model.LySku, priceUs f
}()
usRatio, _ := redis.Float64(redisCon.Do("HGET", "erp_rate", 2))
var currency int
var currencyConfig string
if sku.SupplierId != 17 {
currency, _ = redis.Int(redisCon.Do("HGET", "magic_cube_supplier_currency", sku.SupplierId))
currencyConfig, _ = redis.String(redisCon.Do("HGET", "magic_cube_supplier_currency", sku.SupplierId))
} else {
currency, _ = redis.Int(redisCon.Do("HGET", "magic_cube_supplier_currency", sku.Canal))
currencyConfig, _ = redis.String(redisCon.Do("HGET", "magic_cube_supplier_currency", sku.Canal))
}
//fmt.Println("进来的美金价格:", priceUs)
if currency > 0 {
hasTax := false
symbol := "$"
if currencyConfig != "" {
currency = int(gjson.Get(currencyConfig, "currency").Int())
if currency == 0 {
return sku
}
hasTax = gjson.Get(currencyConfig, "has_tax").Bool()
symbol = gjson.Get(currencyConfig, "symbol").String()
//这里进行转换,因为这里都只能取到对应的币种转人民币的比率,我们没有直接各种币种转美金的数据,所以我这边要
//先根据对应币种转人民币,然后根据人民币转美金,才能得到不同币种对应美金的汇率
rmbRatio, _ := redis.Float64(redisCon.Do("HGET", "erp_rate", currency))
//fmt.Println("特殊转换", rmbRatio)
//fmt.Println(rmbRatio, usRatio)
//人民币汇率转美金汇率
usRatio = c.MyRound(c.DivFloat(rmbRatio, usRatio), 10)
priceUs = c.MyRound(c.MulFloat(priceUs, usRatio), 4)
for index, price := range sku.LadderPrice {
priceUs := price.PriceUs
priceUs = c.MyRound(c.MulFloat(priceUs, usRatio), 4)
if hasTax {
priceUs = c.MyRound(c.DivFloat(priceUs, 1.13), 4)
}
sku.LadderPrice[index].PriceUs = priceUs
sku.OriginalPrice[index].PriceUs = priceUs
}
}
return priceUs
sku.OriginCurrencySymbol = symbol
return sku
}
package sorter
import "go_sku_server/model"
// 阶梯价格排序算法
type OriginPriceSorter []model.OriginPrice
func (a OriginPriceSorter) Len() int {
return len(a)
}
func (a OriginPriceSorter) Swap(i, j int) {
a[i], a[j] = a[j], a[i]
}
func (a OriginPriceSorter) Less(i, j int) bool {
return a[j].Purchases > a[i].Purchases
}
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