Commit 2fa5c932 by 杨树贤

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

parents 30ae5c57 a23205fa
package model package model
//联营统一返回格式 // 联营统一返回格式
type LyResponse struct { type LyResponse struct {
ErrorCode int `json:"error_code"` ErrorCode int `json:"error_code"`
ErrorMsg string `json:"error_msg"` ErrorMsg string `json:"error_msg"`
Data interface{} `json:"data"` Data interface{} `json:"data"`
} }
//原始sku梯度 // 原始sku梯度
type LadderPrice struct { type LadderPrice struct {
Purchases int64 `json:"purchases"` //购买数量 Purchases int64 `json:"purchases"` //购买数量
PriceUs float64 `json:"price_us,omitempty"` //数量对应的英文价格 PriceUs float64 `json:"price_us,omitempty"` //数量对应的英文价格
...@@ -27,13 +27,13 @@ type OriginPrice struct { ...@@ -27,13 +27,13 @@ type OriginPrice struct {
CostPrice float64 `json:"cost_price"` CostPrice float64 `json:"cost_price"`
} }
//立创价格梯度 // 立创价格梯度
type LadderPriceLc struct { type LadderPriceLc struct {
Purchases int64 `json:"purchases"` //购买数量 Purchases int64 `json:"purchases"` //购买数量
Price float64 `json:"price"` //立创价格,人民币 Price float64 `json:"price"` //立创价格,人民币
} }
//自营属性列表 // 自营属性列表
type Attrs struct { type Attrs struct {
AttrName string `json:"attr_name"` //属性名称 AttrName string `json:"attr_name"` //属性名称
AttrValue string `json:"attr_value"` //属性值 AttrValue string `json:"attr_value"` //属性值
......
...@@ -40,7 +40,9 @@ type LySku struct { ...@@ -40,7 +40,9 @@ type LySku struct {
BrandId int64 `json:"brand_id"` BrandId int64 `json:"brand_id"`
//系数相关 //系数相关
Coefficient interface{} `json:"coefficient,omitempty"` 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"` SuppExtendFee interface{} `json:"supp_extend_fee"`
IsBuy int `json:"is_buy"` IsBuy int `json:"is_buy"`
//spu信息 //spu信息
...@@ -78,6 +80,7 @@ type LySku struct { ...@@ -78,6 +80,7 @@ type LySku struct {
PriceRatioSort int `json:"price_ratio_sort"` PriceRatioSort int `json:"price_ratio_sort"`
PriceRatio []PriceRatio `json:"price_ratio"` PriceRatio []PriceRatio `json:"price_ratio"`
Source int `json:"source"` Source int `json:"source"`
OriginCurrencySymbol string `json:"origin_currency_symbol,omitempty"`
} }
type DiscountRatio struct { type DiscountRatio struct {
...@@ -231,7 +234,7 @@ func InitSkuData(sku string) (data LySku) { ...@@ -231,7 +234,7 @@ func InitSkuData(sku string) (data LySku) {
LadderPriceStr := gjson.Get(sku, "ladder_price").String() LadderPriceStr := gjson.Get(sku, "ladder_price").String()
data.LadderPrice = getLadderPrice(LadderPriceStr) data.LadderPrice = getLadderPrice(LadderPriceStr)
data.Original = getOriginPrice(LadderPriceStr) data.OriginalPrice = getOriginPrice(LadderPriceStr)
return return
} }
......
...@@ -57,7 +57,9 @@ func Sha1(query string, pri_key string) string { ...@@ -57,7 +57,9 @@ func Sha1(query string, pri_key string) string {
return query return query
} }
/** /*
*
@author wangsong @author wangsong
获取请求过来的参数,并转为字符串,作用:为了有时候需要记录请求参数,压入日志 获取请求过来的参数,并转为字符串,作用:为了有时候需要记录请求参数,压入日志
注意: 注意:
...@@ -141,7 +143,8 @@ func CopyStruct(struct1 interface{}, struct2 interface{}, Status ...int) { ...@@ -141,7 +143,8 @@ func CopyStruct(struct1 interface{}, struct2 interface{}, Status ...int) {
} }
} }
/** /*
*
@author wangsong @author wangsong
合并map,都有值以map1为主,字段类型以map1为主 合并map,都有值以map1为主,字段类型以map1为主
*/ */
...@@ -227,7 +230,7 @@ func Md5(str string) string { ...@@ -227,7 +230,7 @@ func Md5(str string) string {
return hex.EncodeToString(hash.Sum(nil)) 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 { func SubKeyWordStr(str string) string {
strLen := len(str) strLen := len(str)
strLenFloat := float64(strLen) strLenFloat := float64(strLen)
...@@ -248,7 +251,7 @@ func SubKeyWordStr(str string) string { ...@@ -248,7 +251,7 @@ func SubKeyWordStr(str string) string {
return str return str
} }
//转成字符串的方法 // 转成字符串的方法
func ToString(a interface{}) string { func ToString(a interface{}) string {
if v, p := a.(int); p { if v, p := a.(int); p {
return strconv.Itoa(v) return strconv.Itoa(v)
...@@ -271,14 +274,14 @@ func ToString(a interface{}) string { ...@@ -271,14 +274,14 @@ func ToString(a interface{}) string {
return "change to String error" return "change to String error"
} }
//替换字符串,不区分大小写 // 替换字符串,不区分大小写
func CaseInsensitiveReplace(subject string, search string, replace string) string { func CaseInsensitiveReplace(subject string, search string, replace string) string {
searchRegex := regexp.MustCompile("(?i)" + search) searchRegex := regexp.MustCompile("(?i)" + search)
return searchRegex.ReplaceAllString(subject, replace) return searchRegex.ReplaceAllString(subject, replace)
} }
/* /*
md5字符串 md5字符串
*/ */
func GetKey(s string) string { func GetKey(s string) string {
return php2go.Md5(strings.ToLower(s)) return php2go.Md5(strings.ToLower(s))
...@@ -349,7 +352,7 @@ func StrRandom(lenNum int) string { ...@@ -349,7 +352,7 @@ func StrRandom(lenNum int) string {
return result return result
} }
//生成范围区间内的随机数 // 生成范围区间内的随机数
func Rand(min, max int) int { func Rand(min, max int) int {
n, _ := crand.Int(crand.Reader, big.NewInt(int64(max+1))) n, _ := crand.Int(crand.Reader, big.NewInt(int64(max+1)))
return int(n.Int64()) + min return int(n.Int64()) + min
...@@ -363,7 +366,7 @@ func CopyMapString(distmap map[string]string) map[string]string { ...@@ -363,7 +366,7 @@ func CopyMapString(distmap map[string]string) map[string]string {
return tmpmap return tmpmap
} }
//反爬虫加密验证 // 反爬虫加密验证
func CheckSignApi(ctx *gin.Context) (resNo int) { func CheckSignApi(ctx *gin.Context) (resNo int) {
params := make(map[string]string) params := make(map[string]string)
if ctx == nil { if ctx == nil {
...@@ -442,7 +445,7 @@ func CheckSignApi(ctx *gin.Context) (resNo int) { ...@@ -442,7 +445,7 @@ func CheckSignApi(ctx *gin.Context) (resNo int) {
return 3 return 3
} }
//内部免验证通过 // 内部免验证通过
func auth(ctx *gin.Context) bool { func auth(ctx *gin.Context) bool {
if ctx == nil { if ctx == nil {
return false return false
...@@ -498,7 +501,7 @@ func isSlice(arg interface{}) (val reflect.Value, ok bool) { ...@@ -498,7 +501,7 @@ func isSlice(arg interface{}) (val reflect.Value, ok bool) {
return return
} }
//向左补充字符串 // 向左补充字符串
func StrPadLeft(input string, padLength int, padString string) string { func StrPadLeft(input string, padLength int, padString string) string {
output := padString output := padString
...@@ -513,7 +516,7 @@ func StrPadLeft(input string, padLength int, padString string) string { ...@@ -513,7 +516,7 @@ func StrPadLeft(input string, padLength int, padString string) string {
return output[:padLength-len(input)] + input return output[:padLength-len(input)] + input
} }
//移除字符串切片中某個元素 // 移除字符串切片中某個元素
func RemoveSliceString(s []string, i string) []string { func RemoveSliceString(s []string, i string) []string {
b := make([]string, 0) b := make([]string, 0)
for _, v := range s { for _, v := range s {
...@@ -525,7 +528,7 @@ func RemoveSliceString(s []string, i string) []string { ...@@ -525,7 +528,7 @@ func RemoveSliceString(s []string, i string) []string {
return b return b
} }
//map排序 // map排序
func MapSort(mapList map[int]int) []int { func MapSort(mapList map[int]int) []int {
var ( var (
keys []int keys []int
...@@ -544,7 +547,7 @@ func MapSort(mapList map[int]int) []int { ...@@ -544,7 +547,7 @@ func MapSort(mapList map[int]int) []int {
return newList return newList
} }
////////////类型转换///////////////////// // //////////类型转换/////////////////////
func MyInt(str string) int { func MyInt(str string) int {
res, _ := strconv.ParseInt(str, 10, 64) res, _ := strconv.ParseInt(str, 10, 64)
return int(res) return int(res)
...@@ -581,6 +584,7 @@ func MyIntToStr(i int) string { ...@@ -581,6 +584,7 @@ func MyIntToStr(i int) string {
/* /*
四舍五入取多少位 四舍五入取多少位
@param float64 x 目标分析字符串 @param float64 x 目标分析字符串
@param int wei 取小数多少位 @param int wei 取小数多少位
*/ */
...@@ -595,6 +599,10 @@ func MyRound(x float64, wei int) float64 { ...@@ -595,6 +599,10 @@ func MyRound(x float64, wei int) float64 {
4: 10000, 4: 10000,
5: 100000, 5: 100000,
6: 1000000, 6: 1000000,
7: 10000000,
8: 100000000,
9: 1000000000,
10: 1000000000,
} }
weishu := weis[wei] weishu := weis[wei]
a := math.Floor(x*weishu+0.5) / weishu a := math.Floor(x*weishu+0.5) / weishu
...@@ -603,7 +611,7 @@ func MyRound(x float64, wei int) float64 { ...@@ -603,7 +611,7 @@ func MyRound(x float64, wei int) float64 {
////////////类型转换///////////////////// ////////////类型转换/////////////////////
//浮点数乘法 // 浮点数乘法
func MulFloat(first float64, args ...float64) float64 { func MulFloat(first float64, args ...float64) float64 {
var result float64 var result float64
result = first result = first
...@@ -613,7 +621,7 @@ func MulFloat(first float64, args ...float64) float64 { ...@@ -613,7 +621,7 @@ func MulFloat(first float64, args ...float64) float64 {
return result return result
} }
//浮点除法 // 浮点除法
func DivFloat(first float64, second float64) float64 { func DivFloat(first float64, second float64) float64 {
return ((first * 1000000000) / (second * 1000000000)) return ((first * 1000000000) / (second * 1000000000))
} }
...@@ -283,8 +283,8 @@ func (ls *LyService) GetCoefficientAndPrice(sku model.LySku) model.LySku { ...@@ -283,8 +283,8 @@ func (ls *LyService) GetCoefficientAndPrice(sku model.LySku) model.LySku {
sku = priceService.GetDiscountRatio(sku) sku = priceService.GetDiscountRatio(sku)
data = make([]model.LadderPrice, len(ladderPrice)) data = make([]model.LadderPrice, len(ladderPrice))
sku = priceService.TransformSpecialSupplierPrice(sku)
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
} }
...@@ -395,11 +395,9 @@ func (ls *LyService) GetCoefficientAndPrice(sku model.LySku) model.LySku { ...@@ -395,11 +395,9 @@ func (ls *LyService) GetCoefficientAndPrice(sku model.LySku) model.LySku {
//价格计算文档 https://docs.qq.com/doc/DR3RJcnNPeUNkWHRk //价格计算文档 https://docs.qq.com/doc/DR3RJcnNPeUNkWHRk
// 为何是固定的1.13,关税基本不会变,有变的话跟产品沟通手动修改即可 // 为何是固定的1.13,关税基本不会变,有变的话跟产品沟通手动修改即可
tax := 1.13 tax := 1.13
sku = priceService.TransformSpecialSupplierPrice(sku)
var showPriceRatioList []model.PriceRatio var showPriceRatioList []model.PriceRatio
for key, price := range sku.LadderPrice { for key, price := range sku.LadderPrice {
//这里有个前置条件处理美金价,因为element(6)存到美金字段里面的是港币,rs(21)存到美金字段里的是人民币,buerklin(1676)是欧元
//所以要全部先转成正确的美金价才能显示,目前先写死汇率,因为目前没有地方能获取实时的各种转美金的汇率
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,
...@@ -494,7 +492,7 @@ func (ls *LyService) GetCoefficientAndPrice(sku model.LySku) model.LySku { ...@@ -494,7 +492,7 @@ func (ls *LyService) GetCoefficientAndPrice(sku model.LySku) model.LySku {
} }
//判断原始价格有变化,那就要覆盖 //判断原始价格有变化,那就要覆盖
if len(originalPrice) > 0 { 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 ...@@ -641,7 +641,7 @@ func (ps PriceService) GetPriceRatio(sku model.LySku) (model.LySku, []model.Pric
// 这里有个前置条件处理美金价,因为element(6)存到美金字段里面的是港币,rs(21)存到美金字段里的是人民币,buerklin(1676)是欧元 // 这里有个前置条件处理美金价,因为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获取价格 //去redis获取价格
redisCon := gredis.Conn("default_r") redisCon := gredis.Conn("default_r")
defer func() { defer func() {
...@@ -649,22 +649,39 @@ func (ps *PriceService) TransformSpecialSupplierPrice(sku model.LySku, priceUs f ...@@ -649,22 +649,39 @@ func (ps *PriceService) TransformSpecialSupplierPrice(sku model.LySku, priceUs f
}() }()
usRatio, _ := redis.Float64(redisCon.Do("HGET", "erp_rate", 2)) usRatio, _ := redis.Float64(redisCon.Do("HGET", "erp_rate", 2))
var currency int var currency int
var currencyConfig string
if sku.SupplierId != 17 { 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 { } 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))
}
sku.DatabasePrice = sku.OriginalPrice
hasTax := false
symbol := ""
if currencyConfig != "" {
currency = int(gjson.Get(currencyConfig, "currency").Int())
if currency == 0 {
return sku
} }
//fmt.Println("进来的美金价格:", priceUs) hasTax = gjson.Get(currencyConfig, "has_tax").Bool()
if currency > 0 { symbol = gjson.Get(currencyConfig, "symbol").String()
//这里进行转换,因为这里都只能取到对应的币种转人民币的比率,我们没有直接各种币种转美金的数据,所以我这边要 //这里进行转换,因为这里都只能取到对应的币种转人民币的比率,我们没有直接各种币种转美金的数据,所以我这边要
//先根据对应币种转人民币,然后根据人民币转美金,才能得到不同币种对应美金的汇率 //先根据对应币种转人民币,然后根据人民币转美金,才能得到不同币种对应美金的汇率
rmbRatio, _ := redis.Float64(redisCon.Do("HGET", "erp_rate", currency)) rmbRatio, _ := redis.Float64(redisCon.Do("HGET", "erp_rate", currency))
//fmt.Println("特殊转换", rmbRatio) //fmt.Println("特殊转换", rmbRatio)
//fmt.Println(rmbRatio, usRatio) //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) priceUs = c.MyRound(c.MulFloat(priceUs, usRatio), 4)
if hasTax {
priceUs = c.MyRound(c.DivFloat(priceUs, 1.13), 4)
} }
return priceUs sku.LadderPrice[index].PriceUs = 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