Commit a0e974c3 by 杨树贤

对比价格比例功能

添加对比价格比例字段和计算逻辑,从Redis获取compare_price_ratio配置,根据price_limit_on类型对阶梯价格进行比例调整
parent 465ee58b
......@@ -94,6 +94,7 @@ type LySku struct {
AbilityLevel int `json:"ability_level"`
BrandPack string `json:"brand_pack"`
OnwayStock int `json:"onway_stock"`
CompareRatio float64 `json:"compare_ratio"`
}
type DiscountRatio struct {
......
......@@ -265,6 +265,8 @@ func (ls *LyService) LyGoodsDetail(ctx context.Context, params RequestParams, go
sku = priceService.GetActivityPrice(sku)
}
sku = priceService.GetComparePrice(sku)
//仅提供价格和库存
if fast != "1" {
if sku.SupplierId != 0 {
......@@ -329,7 +331,6 @@ func (ls *LyService) LyGoodsDetail(ctx context.Context, params RequestParams, go
}
//最后一步,将sku的全部信息放到有序map里面
GoodsRes.Store(goodsId, sku)
//(*goodsRes)[goodsId] = A
}
// 发送结果时也要检查 context,避免在超时后阻塞
......
......@@ -919,3 +919,29 @@ func (ps *PriceService) GetActivityPrice(sku model.LySku) model.LySku {
}
return sku
}
// compare_price_ratio
func (ps *PriceService) GetComparePrice(sku model.LySku) model.LySku {
redisCon := gredis.Conn("default_r")
//判断是否存在
compareData, _ := redis.String(redisCon.Do("HGET", "compare_price_ratio", sku.GoodsId))
if compareData == "" {
return sku
}
priceLimitOn := gjson.Get(compareData, "price_limit_on").Int()
ratio := gjson.Get(compareData, "ratio").Float()
//最后价格还要处理一遍
ladderPrice := sku.LadderPrice
for index, ladder := range ladderPrice {
if priceLimitOn == 2 {
ladder.PriceAc = c.MyRound(c.MulFloat(ladder.PriceAc, ratio), 4)
} else {
ladder.PriceCn = c.MyRound(c.MulFloat(ladder.PriceCn, ratio), 4)
}
sku.LadderPrice[index] = ladder
}
sku.CompareRatio = ratio
sku.LadderPriceResult = sku.LadderPrice
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