Commit 2fa5c932 by 杨树贤

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

parents 30ae5c57 a23205fa
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,13 @@ type OriginPrice struct {
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"` //属性值
......
......@@ -40,7 +40,9 @@ type LySku struct {
BrandId int64 `json:"brand_id"`
//系数相关
Coefficient interface{} `json:"coefficient,omitempty"`
Original interface{} `json:"original_price,omitempty"`
OriginalPrice interface{} `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 {
......@@ -231,7 +234,7 @@ 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)
return
}
......
......@@ -57,14 +57,16 @@ func Sha1(query string, pri_key string) string {
return query
}
/**
@author wangsong
获取请求过来的参数,并转为字符串,作用:为了有时候需要记录请求参数,压入日志
注意:
1.如果请求的是json,接收是需要读取body,而gin大部分函数只能读取一次body,读第二次会读不到
而此函数需要频繁调用,所以需要在调用此函数之前,使用过ShouldBindBodyWith 方法,不然会读取不到。
具体需了解 ShouldBindBodyWith 源码 和 多次使用shouldbindjsond 的问题
2.表单提交不需要读body,则正常使用
/*
*
@author wangsong
获取请求过来的参数,并转为字符串,作用:为了有时候需要记录请求参数,压入日志
注意:
1.如果请求的是json,接收是需要读取body,而gin大部分函数只能读取一次body,读第二次会读不到
而此函数需要频繁调用,所以需要在调用此函数之前,使用过ShouldBindBodyWith 方法,不然会读取不到。
具体需了解 ShouldBindBodyWith 源码 和 多次使用shouldbindjsond 的问题
2.表单提交不需要读body,则正常使用
*/
func GetRequestParam(ctx *gin.Context) string {
ct := ctx.Request.Header.Get("Content-Type")
......@@ -141,7 +143,8 @@ func CopyStruct(struct1 interface{}, struct2 interface{}, Status ...int) {
}
}
/**
/*
*
@author wangsong
合并map,都有值以map1为主,字段类型以map1为主
*/
......@@ -227,7 +230,7 @@ func Md5(str string) string {
return hex.EncodeToString(hash.Sum(nil))
}
//非精确匹配,字符串截取向下80%,5个字符以下不截,5-10个截一个,10-20个向下取80%,20个以上向下取70%
// 非精确匹配,字符串截取向下80%,5个字符以下不截,5-10个截一个,10-20个向下取80%,20个以上向下取70%
func SubKeyWordStr(str string) string {
strLen := len(str)
strLenFloat := float64(strLen)
......@@ -248,7 +251,7 @@ func SubKeyWordStr(str string) string {
return str
}
//转成字符串的方法
// 转成字符串的方法
func ToString(a interface{}) string {
if v, p := a.(int); p {
return strconv.Itoa(v)
......@@ -271,14 +274,14 @@ func ToString(a interface{}) string {
return "change to String error"
}
//替换字符串,不区分大小写
// 替换字符串,不区分大小写
func CaseInsensitiveReplace(subject string, search string, replace string) string {
searchRegex := regexp.MustCompile("(?i)" + search)
return searchRegex.ReplaceAllString(subject, replace)
}
/*
md5字符串
md5字符串
*/
func GetKey(s string) string {
return php2go.Md5(strings.ToLower(s))
......@@ -349,7 +352,7 @@ func StrRandom(lenNum int) string {
return result
}
//生成范围区间内的随机数
// 生成范围区间内的随机数
func Rand(min, max int) int {
n, _ := crand.Int(crand.Reader, big.NewInt(int64(max+1)))
return int(n.Int64()) + min
......@@ -363,7 +366,7 @@ func CopyMapString(distmap map[string]string) map[string]string {
return tmpmap
}
//反爬虫加密验证
// 反爬虫加密验证
func CheckSignApi(ctx *gin.Context) (resNo int) {
params := make(map[string]string)
if ctx == nil {
......@@ -442,7 +445,7 @@ func CheckSignApi(ctx *gin.Context) (resNo int) {
return 3
}
//内部免验证通过
// 内部免验证通过
func auth(ctx *gin.Context) bool {
if ctx == nil {
return false
......@@ -498,7 +501,7 @@ func isSlice(arg interface{}) (val reflect.Value, ok bool) {
return
}
//向左补充字符串
// 向左补充字符串
func StrPadLeft(input string, padLength int, padString string) string {
output := padString
......@@ -513,7 +516,7 @@ func StrPadLeft(input string, padLength int, padString string) string {
return output[:padLength-len(input)] + input
}
//移除字符串切片中某個元素
// 移除字符串切片中某個元素
func RemoveSliceString(s []string, i string) []string {
b := make([]string, 0)
for _, v := range s {
......@@ -525,7 +528,7 @@ func RemoveSliceString(s []string, i string) []string {
return b
}
//map排序
// map排序
func MapSort(mapList map[int]int) []int {
var (
keys []int
......@@ -544,7 +547,7 @@ func MapSort(mapList map[int]int) []int {
return newList
}
////////////类型转换/////////////////////
// //////////类型转换/////////////////////
func MyInt(str string) int {
res, _ := strconv.ParseInt(str, 10, 64)
return int(res)
......@@ -580,7 +583,8 @@ func MyIntToStr(i int) string {
}
/*
四舍五入取多少位
四舍五入取多少位
@param float64 x 目标分析字符串
@param int wei 取小数多少位
*/
......@@ -589,12 +593,16 @@ func MyRound(x float64, wei int) float64 {
return math.Floor(x + 0.5)
}
weis := map[int]float64{
1: 10,
2: 100,
3: 1000,
4: 10000,
5: 100000,
6: 1000000,
1: 10,
2: 100,
3: 1000,
4: 10000,
5: 100000,
6: 1000000,
7: 10000000,
8: 100000000,
9: 1000000000,
10: 1000000000,
}
weishu := weis[wei]
a := math.Floor(x*weishu+0.5) / weishu
......@@ -603,7 +611,7 @@ func MyRound(x float64, wei int) float64 {
////////////类型转换/////////////////////
//浮点数乘法
// 浮点数乘法
func MulFloat(first float64, args ...float64) float64 {
var result float64
result = first
......@@ -613,7 +621,7 @@ func MulFloat(first float64, args ...float64) float64 {
return result
}
//浮点除法
// 浮点除法
func DivFloat(first float64, second float64) float64 {
return ((first * 1000000000) / (second * 1000000000))
}
......@@ -283,8 +283,8 @@ func (ls *LyService) GetCoefficientAndPrice(sku model.LySku) model.LySku {
sku = priceService.GetDiscountRatio(sku)
data = make([]model.LadderPrice, len(ladderPrice))
sku = priceService.TransformSpecialSupplierPrice(sku)
for key, price := range ladderPrice {
price.PriceUs = priceService.TransformSpecialSupplierPrice(sku, price.PriceUs)
if price.Purchases == 0 {
continue
}
......@@ -395,11 +395,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 +492,7 @@ func (ls *LyService) GetCoefficientAndPrice(sku model.LySku) model.LySku {
}
//判断原始价格有变化,那就要覆盖
if len(originalPrice) > 0 {
sku.Original = originalPrice
sku.OriginalPrice = originalPrice
}
//输出税费到前端
......
......@@ -641,7 +641,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() {
......@@ -649,22 +649,39 @@ 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 {
sku.DatabasePrice = sku.OriginalPrice
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), 6)
usRatio = c.MyRound(c.DivFloat(rmbRatio, usRatio), 10)
}
sku.OriginCurrencySymbol = symbol
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
}
return priceUs
return sku
}
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