Commit c83cbe27 by mushishixian

Merge branch 'ysx-魔方改版-20230313' into dev

parents 2e918fed 434aa3a2
...@@ -15,6 +15,7 @@ type Activity struct { ...@@ -15,6 +15,7 @@ type Activity struct {
Canals string `json:"canals"` Canals string `json:"canals"`
CanalList []string CanalList []string
Ratio float64 `json:"ratio"` Ratio float64 `json:"ratio"`
RatioUs float64 `json:"ratio_us"`
StartTime int `json:"start_time"` StartTime int `json:"start_time"`
EndTime int `json:"end_time"` EndTime int `json:"end_time"`
AddTime int `json:"add_time"` AddTime int `json:"add_time"`
......
...@@ -6,12 +6,16 @@ type LyResponse struct { ...@@ -6,12 +6,16 @@ type LyResponse struct {
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"` //数量对应的英文价格
PriceCn float64 `json:"price_cn"` //数量对应的中文价格 PriceCn float64 `json:"price_cn"` //数量对应的中文价格
PriceAc float64 `json:"price_ac,omitempty"` PriceCostUs float64 `json:"price_cost_us"` //成本价美金
PriceCostCn float64 `json:"price_cost_cn"` //成本价人民币
PriceAc float64 `json:"price_ac,omitempty"` //活动价人民币
PriceAcUs float64 `json:"price_ac_us"` //活动价美金
CostPrice float64 `json:"-"` CostPrice float64 `json:"-"`
} }
......
...@@ -60,6 +60,7 @@ type LySku struct { ...@@ -60,6 +60,7 @@ type LySku struct {
ClassName2 string `json:"class_name2,omitempty"` ClassName2 string `json:"class_name2,omitempty"`
ClassName3 string `json:"class_name3,omitempty"` ClassName3 string `json:"class_name3,omitempty"`
Ratio float64 `json:"ratio,omitempty"` Ratio float64 `json:"ratio,omitempty"`
RatioUs float64 `json:"ratio_us,omitempty"`
SpuDetail string `json:"spu_detail,omitempty"` SpuDetail string `json:"spu_detail,omitempty"`
AcType int `json:"ac_type"` AcType int `json:"ac_type"`
...@@ -70,11 +71,13 @@ type LySku struct { ...@@ -70,11 +71,13 @@ type LySku struct {
StandardBrand StandardBrand `json:"standard_brand"` StandardBrand StandardBrand `json:"standard_brand"`
GoodsTag GoodsTag `json:"goods_tag"` GoodsTag GoodsTag `json:"goods_tag"`
StockInfo interface{} `json:"stock_info"` StockInfo interface{} `json:"stock_info"`
Eccn string `json:"eccn"`
} }
type PriceActivity struct { type PriceActivity struct {
ActivityCommon ActivityCommon
Ratio float64 `json:"ratio,omitempty"` Ratio float64 `json:"ratio,omitempty"`
RatioUs float64 `json:"ratio_us,omitempty"`
SignText string `json:"sign_text,omitempty"` SignText string `json:"sign_text,omitempty"`
Sign string `json:"sign,omitempty"` Sign string `json:"sign,omitempty"`
ShowName string `json:"show_name,omitempty"` ShowName string `json:"show_name,omitempty"`
...@@ -155,6 +158,9 @@ func InitSkuData(sku string) (data LySku) { ...@@ -155,6 +158,9 @@ func InitSkuData(sku string) (data LySku) {
stock := gjson.Get(sku, "stock").Int() stock := gjson.Get(sku, "stock").Int()
data.Stock = stock data.Stock = stock
eccn := gjson.Get(sku, "eccn").String()
data.Eccn = eccn
isExpire := gjson.Get(sku, "is_expire").Int() isExpire := gjson.Get(sku, "is_expire").Int()
data.IsExpire = int(isExpire) data.IsExpire = int(isExpire)
......
...@@ -198,6 +198,11 @@ func (as *ActivityService) GetPriceActivity(checkData model.ActivityCheckData, a ...@@ -198,6 +198,11 @@ func (as *ActivityService) GetPriceActivity(checkData model.ActivityCheckData, a
UserScope: activity.UserScope, UserScope: activity.UserScope,
}, },
} }
if activity.RatioUs > 0 {
priceActivity.RatioUs = activity.RatioUs
} else {
priceActivity.RatioUs = 1
}
break break
} }
} }
......
...@@ -133,6 +133,7 @@ func (ls *LyService) LyGoodsDetail(ctx *gin.Context, goodsIds []string, ch chan ...@@ -133,6 +133,7 @@ func (ls *LyService) LyGoodsDetail(ctx *gin.Context, goodsIds []string, ch chan
sku.AllowCoupon = 1 sku.AllowCoupon = 1
sku.BrandId = brandId sku.BrandId = brandId
//这里获取活动价格和活动类型
sku = ls.GetActivity(sku) sku = ls.GetActivity(sku)
//处理阶梯价数据 //处理阶梯价数据
...@@ -146,7 +147,7 @@ func (ls *LyService) LyGoodsDetail(ctx *gin.Context, goodsIds []string, ch chan ...@@ -146,7 +147,7 @@ func (ls *LyService) LyGoodsDetail(ctx *gin.Context, goodsIds []string, ch chan
} }
} }
//获取系数 //获取系数
sku = ls.GetCoefficient(sku) sku = ls.GetCoefficientAndPrice(sku)
//仅提供价格和库存 //仅提供价格和库存
if fast != "1" { if fast != "1" {
...@@ -215,6 +216,8 @@ func (ls *LyService) GetActivity(sku model.LySku) model.LySku { ...@@ -215,6 +216,8 @@ func (ls *LyService) GetActivity(sku model.LySku) model.LySku {
if priceActivity.HasActivity { if priceActivity.HasActivity {
sku.AcType = 10 sku.AcType = 10
sku.Ratio = priceActivity.Ratio sku.Ratio = priceActivity.Ratio
sku.RatioUs = priceActivity.RatioUs
sku.ActivityInfo = priceActivity sku.ActivityInfo = priceActivity
} }
if giftActivity.HasActivity { if giftActivity.HasActivity {
......
...@@ -2,11 +2,14 @@ package service ...@@ -2,11 +2,14 @@ package service
import ( import (
"encoding/json" "encoding/json"
"fmt"
"go_sku_server/model" "go_sku_server/model"
"go_sku_server/pkg/common" "go_sku_server/pkg/common"
"go_sku_server/pkg/gredis" "go_sku_server/pkg/gredis"
"go_sku_server/pkg/logger" "go_sku_server/pkg/logger"
_ "go_sku_server/pkg/mongo" _ "go_sku_server/pkg/mongo"
"go_sku_server/service/sorter"
"strconv"
"strings" "strings"
"github.com/gomodule/redigo/redis" "github.com/gomodule/redigo/redis"
...@@ -179,7 +182,7 @@ func (ls *LyService) GetExtendFee(supplierId int64, canal string) interface{} { ...@@ -179,7 +182,7 @@ func (ls *LyService) GetExtendFee(supplierId int64, canal string) interface{} {
} }
//获取系数 //获取系数
func (ls *LyService) GetCoefficient(sku model.LySku) model.LySku { func (ls *LyService) GetCoefficientAndPrice(sku model.LySku) model.LySku {
if len(sku.LadderPrice) == 0 { if len(sku.LadderPrice) == 0 {
sku.Original = nil sku.Original = nil
return sku return sku
...@@ -218,16 +221,150 @@ func (ls *LyService) GetCoefficient(sku model.LySku) model.LySku { ...@@ -218,16 +221,150 @@ func (ls *LyService) GetCoefficient(sku model.LySku) model.LySku {
} }
} }
} else { } else {
//去获取系数 //去获取各种系数(成本折扣系数,售价组系数,供应商系数)
redisCon := gredis.Conn("default_r") redisCon := gredis.Conn("default_r")
defer redisCon.Close() defer redisCon.Close()
ratio, _ := redis.String(redisCon.Do("HGET", "pool_supplier_ratio", sku.SupplierId))
//先去读取成本折扣系数
//找一个标志位,因为默认的全局折扣系数的数据格式和非全局的是不一样的
isDefaultDiscoutRatio := false
discountRatio, _ := redis.String(redisCon.Do("HGET", "magic_cube_channel_discount_daigou", sku.SupplierId))
//如果这个渠道没有对应的折扣系数,那么就去读取全局的
if discountRatio == "" {
isDefaultDiscoutRatio = true
discountRatio, _ = redis.String(redisCon.Do("GET", "magic_cube_channel_discount_default_zhuanying"))
}
var cnDiscountRatio float64
var usDiscountRatio float64
//如果有默认系数,那么就去找默认系数
if isDefaultDiscoutRatio {
cnDiscountRatio = gjson.Get(discountRatio, "ration").Float()
usDiscountRatio = gjson.Get(discountRatio, "ration_usd").Float()
} else {
//拿到系数以后,就要去计算
//拿出里面的所有排序,以人民币系数为准
ration := gjson.Get(discountRatio, "ration").Map()
var sortNumbers []int
for sortNumberString, _ := range ration {
sortNumber, _ := strconv.Atoi(sortNumberString)
sortNumbers = append(sortNumbers, sortNumber)
}
//然后确定排序
sortNumbers = sorter.IntSliceSortDesc(sortNumbers)
//确定排序以后,就可以进行按排序(从大到小)取系数
for _, sortNumber := range sortNumbers {
sortString := strconv.Itoa(sortNumber)
cnDiscountRatio = gjson.Get(discountRatio, "ration."+sortString).Float()
usDiscountRatio = gjson.Get(discountRatio, "ration_usd."+sortString).Float()
//判断是否有符合的商品名称
goodsNames := gjson.Get(discountRatio, "goods_name").String()
goodsNameList := strings.Split(goodsNames, "€")
//找到有对应的商品名称,那么优先级肯定是最高的了
if php2go.InArray(sku.GoodsName, goodsNameList) {
break
}
//判断是否有符合的品牌名称
brandIds := gjson.Get(discountRatio, "brand").String()
standardBrandIdList := strings.Split(brandIds, "€")
standardBrandId := strconv.Itoa(sku.StandardBrand.StandardBrandId)
//找到有对应的品牌,那么优先级肯定是最高的了
if php2go.InArray(standardBrandId, standardBrandIdList) {
break
}
//如果没有设置品牌和商品,那么这个优先级高的就会覆盖下面的了,不需要再去判断品牌和型号了
if len(goodsNameList) == 0 && len(standardBrandIdList) == 0 {
break
}
}
}
cnDiscountRatio += 1
usDiscountRatio += 1
//再去找售价组系数
//找一个标志位,因为默认的全局折扣系数的数据格式和非全局的是不一样的
isDefaultPriceRatio := false
priceRatioCache, _ := redis.String(redisCon.Do("HGET", "magic_cube_price_rule_channel", sku.SupplierId))
//如果这个渠道没有对应的折扣系数,那么就去读取全局的
if priceRatioCache == "" {
isDefaultPriceRatio = true
priceRatioCache, _ = redis.String(redisCon.Do("GET", "magic_cube_price_rule_channel_default"))
}
type PriceRatio struct {
Ratio float64
RatioUsd float64
}
//这个就是最终要获取到的价格系数
var priceRatioList []PriceRatio
//如果只有默认系数,那么就去找默认系数
if isDefaultPriceRatio {
priceRatioArr := gjson.Get(priceRatioCache, "ladder_price").Array()
for _, value := range priceRatioArr {
priceRatioList = nil
var priceRatio PriceRatio
priceRatio.Ratio = gjson.Get(value.String(), "ratio").Float()
priceRatio.RatioUsd = gjson.Get(value.String(), "ratio_usd").Float()
priceRatioList = append(priceRatioList, priceRatio)
}
} else {
//拿到系数以后,就要去计算
//拿出里面的所有排序
priceRatioSortMap := gjson.Get(priceRatioCache, "ladder_price").Map()
var sortNumbers []int
for sortNumberString, _ := range priceRatioSortMap {
sortNumber, _ := strconv.Atoi(sortNumberString)
sortNumbers = append(sortNumbers, sortNumber)
}
//然后确定排序
sortNumbers = sorter.IntSliceSortDesc(sortNumbers)
//确定排序以后,就可以进行按排序(从大到小)取系数
for _, sortNumber := range sortNumbers {
priceRatioList = nil
sortString := strconv.Itoa(sortNumber)
priceRatioArr := gjson.Get(priceRatioCache, "ladder_price."+sortString).Array()
for _, value := range priceRatioArr {
var priceRatio PriceRatio
priceRatio.Ratio = gjson.Get(value.String(), "ratio").Float()
priceRatio.RatioUsd = gjson.Get(value.String(), "ratio_usd").Float()
priceRatioList = append(priceRatioList, priceRatio)
}
//判断是否有符合的商品名称
goodsNames := gjson.Get(priceRatioCache, "goods_name."+sortString).String()
goodsNameList := strings.Split(goodsNames, "€")
//找到有对应的商品名称,那么优先级肯定是最高的了
if php2go.InArray(sku.GoodsName, goodsNameList) {
break
}
//判断是否有符合的标准品牌ID
brandIds := gjson.Get(priceRatioCache, "brand"+sortString).String()
standardBrandIdList := strings.Split(brandIds, "€")
standardBrandId := strconv.Itoa(sku.StandardBrand.StandardBrandId)
//找到有对应的品牌,那么优先级肯定是最高的了
if php2go.InArray(standardBrandId, standardBrandIdList) {
break
}
//判断是否有符合的eccn
eccns := gjson.Get(priceRatioCache, "eccn"+sortString).String()
eccnList := strings.Split(eccns, "€")
//找到有对应的eccn,那么优先级肯定是最高的了
for _, eccn := range eccnList {
if strings.Contains(sku.Eccn, eccn) {
break
}
}
//如果没有设置品牌和商品,那么这个优先级高的就会覆盖下面的了,不需要再去判断品牌和型号了
if len(goodsNameList) == 0 && len(standardBrandIdList) == 0 && len(eccnList) == 0 {
break
}
}
}
//这里是供应商系数,先保留这块逻辑
ratio, _ := redis.String(redisCon.Do("HGET", "pool_supplier_ratio", sku.SupplierId))
if ratio == "" { if ratio == "" {
logger.Select("sku_query").Error("系数获取异常,供应商:" + common.ToString(sku.SupplierId)) logger.Select("sku_query").Error("系数获取异常,供应商:" + common.ToString(sku.SupplierId))
return sku return sku
} }
ratios := gjson.Parse(ratio).Array() ratios := gjson.Parse(ratio).Array()
var defaultCoefficient, coefficient model.Coefficient var defaultCoefficient, coefficient model.Coefficient
var hasDefault, hasCoefficient bool var hasDefault, hasCoefficient bool
...@@ -259,7 +396,7 @@ func (ls *LyService) GetCoefficient(sku model.LySku) model.LySku { ...@@ -259,7 +396,7 @@ func (ls *LyService) GetCoefficient(sku model.LySku) model.LySku {
} }
//存在goods_name的对比吗,为什么,因为系数可以单独针对型号配置,所以要去判断型号 //存在goods_name的对比吗,为什么,因为系数可以单独针对型号配置,所以要去判断型号
//http://footstone.ichunt.net/web/SavePoolCoefficient?id=1 //http://footstone.ichunt.net/web/SavePoolCoefficient?id=1
if brandName != "" && strings.Contains(goodsName, sku.GoodsName) { if goodsName != "" && strings.Contains(goodsName, sku.GoodsName) {
coefficient = ratioInfo coefficient = ratioInfo
hasCoefficient = true hasCoefficient = true
break break
...@@ -269,10 +406,12 @@ func (ls *LyService) GetCoefficient(sku model.LySku) model.LySku { ...@@ -269,10 +406,12 @@ func (ls *LyService) GetCoefficient(sku model.LySku) model.LySku {
logger.Select("sku_query").Error("系数获取异常,供应商:" + common.ToString(sku.SupplierId)) logger.Select("sku_query").Error("系数获取异常,供应商:" + common.ToString(sku.SupplierId))
return sku return sku
} }
if !hasCoefficient { if !hasCoefficient {
coefficient = defaultCoefficient coefficient = defaultCoefficient
} }
//下面是计算价格
//价格计算文档 https://docs.qq.com/doc/DR3RJcnNPeUNkWHRk
// 为何是固定的1.13,关税基本不会变,有变的话跟产品沟通手动修改即可 // 为何是固定的1.13,关税基本不会变,有变的话跟产品沟通手动修改即可
//$tax = config('website.tax'); //$tax = config('website.tax');
tax := 1.13 tax := 1.13
...@@ -281,10 +420,31 @@ func (ls *LyService) GetCoefficient(sku model.LySku) model.LySku { ...@@ -281,10 +420,31 @@ func (ls *LyService) GetCoefficient(sku model.LySku) model.LySku {
continue continue
} }
data[key].Purchases = price.Purchases data[key].Purchases = price.Purchases
//根据系数处理美金 //找出对应的阶梯,从$priceRatioList找到对应的售价组系数
data[key].PriceUs = common.MyRound(price.PriceUs*coefficient.ExtraRatio*coefficient.Hk, 4) //这个是为了怕后台存的数据格式不对导致无法获取到对应的系数
var priceRatio PriceRatio
if len(priceRatioList) > key {
priceRatio = priceRatioList[key]
} else {
priceRatio = PriceRatio{
Ratio: 1,
RatioUsd: 1,
}
}
//美金成本价
priceCostUs := price.PriceUs * usDiscountRatio
//美金售价
priceUs := priceCostUs * priceRatio.RatioUsd
//人民币成本价
priceCostCn := price.PriceUs * coefficient.Ratio * cnDiscountRatio
//人民币售价
priceCn := priceCostCn * priceRatio.Ratio * tax
data[key].PriceUs = common.MyRound(priceUs, 4)
data[key].PriceCostUs = common.MyRound(priceCostUs, 4)
//处理人民币 //处理人民币
data[key].PriceCn = common.MyRound(price.PriceUs*coefficient.ExtraRatio*coefficient.Cn*coefficient.Ratio*tax, 4) data[key].PriceCn = common.MyRound(priceCn, 4)
data[key].PriceCostCn = common.MyRound(priceCostCn, 4)
fmt.Println(data[key])
//处理mouser的成本价 //处理mouser的成本价
//mouser成本价是什么,斌哥同步过来的成本价 //mouser成本价是什么,斌哥同步过来的成本价
//sku.LadderPrice[key].CostPrice是专门针对贸泽(mouser)的 //sku.LadderPrice[key].CostPrice是专门针对贸泽(mouser)的
...@@ -302,6 +462,8 @@ func (ls *LyService) GetCoefficient(sku model.LySku) model.LySku { ...@@ -302,6 +462,8 @@ func (ls *LyService) GetCoefficient(sku model.LySku) model.LySku {
if (sku.GoodsType == 1 || sku.GoodsType == 2) && sku.AcType > 1 && sku.Ratio > 0 { if (sku.GoodsType == 1 || sku.GoodsType == 2) && sku.AcType > 1 && sku.Ratio > 0 {
priceAc := common.MyRound(data[key].PriceCn*(sku.Ratio/100), 4) priceAc := common.MyRound(data[key].PriceCn*(sku.Ratio/100), 4)
data[key].PriceAc = priceAc data[key].PriceAc = priceAc
priceAcUs := common.MyRound(data[key].PriceCn*(sku.RatioUs/100), 4)
data[key].PriceAcUs = priceAcUs
if priceAc <= 0 { if priceAc <= 0 {
sku.AcType = 0 sku.AcType = 0
......
package sorter
import "sort"
// Define a custom type and methods to implement sort.Interface
type DescendingInts []int
func (d DescendingInts) Len() int { return len(d) }
func (d DescendingInts) Swap(i, j int) { d[i], d[j] = d[j], d[i] }
func (d DescendingInts) Less(i, j int) bool { return d[i] > d[j] }
func IntSliceSortDesc(numbers []int) []int {
sort.Sort(DescendingInts(numbers))
return numbers
}
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