Commit dcf5b8be by 杨树贤

价格体系继续修改

parent c8399857
...@@ -2,18 +2,17 @@ package service ...@@ -2,18 +2,17 @@ package service
import ( import (
"encoding/json" "encoding/json"
"github.com/gomodule/redigo/redis"
_ "github.com/iancoleman/orderedmap"
"github.com/syyongx/php2go"
"github.com/tidwall/gjson"
"go_sku_server/model" "go_sku_server/model"
c "go_sku_server/pkg/common" c "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"
"strings"
"github.com/gomodule/redigo/redis"
_ "github.com/iancoleman/orderedmap"
"github.com/syyongx/php2go"
"github.com/tidwall/gjson"
_ "gopkg.in/mgo.v2/bson" _ "gopkg.in/mgo.v2/bson"
"strings"
) )
// 获取图片信息 // 获取图片信息
...@@ -37,7 +36,7 @@ func (ls *LyService) GetGoodsImages(sku model.LySku, spu string) model.LySku { ...@@ -37,7 +36,7 @@ func (ls *LyService) GetGoodsImages(sku model.LySku, spu string) model.LySku {
return sku return sku
} }
// 获取图片信息 // 获取PDF信息
func (ls *LyService) GetPdf(sku model.LySku, spu string) model.LySku { func (ls *LyService) GetPdf(sku model.LySku, spu string) model.LySku {
pdf := gjson.Get(spu, "pdf").String() pdf := gjson.Get(spu, "pdf").String()
if pdf != "" { if pdf != "" {
...@@ -192,7 +191,73 @@ func (ls *LyService) GetExtendFee(supplierId int64, canal string) interface{} { ...@@ -192,7 +191,73 @@ func (ls *LyService) GetExtendFee(supplierId int64, canal string) interface{} {
} }
} }
// 获取系数和总体价格 // 获取供应商货期
func (ls *LyService) GetDelivery(supplierId int64, canal string) (delivery map[string]string) {
delivery = make(map[string]string)
redisCon := gredis.Conn("default_r")
defer redisCon.Close()
if canal != "" {
supplierRatio, _ := redis.String(redisCon.Do("HGET", "supp_ratio", canal))
if supplierRatio != "" {
cnDeliveryTime := gjson.Get(supplierRatio, "cn_delivery_time").String()
usDeliveryTime := gjson.Get(supplierRatio, "us_delivery_time").String()
//为了兼容供应商修改的问题
if cnDeliveryTime != "周" && cnDeliveryTime != "天" {
delivery["cn_delivery"] = gjson.Get(supplierRatio, "cn_delivery_time").String()
} else {
delivery["cn_delivery"] = ""
}
if usDeliveryTime != "周" && usDeliveryTime != "天" {
delivery["hk_delivery"] = gjson.Get(supplierRatio, "us_delivery_time").String()
} else {
delivery["hk_delivery"] = ""
}
}
return
}
info, _ := redis.String(redisCon.Do("HGET", "SUPPLIER_REDIS_INFO_", supplierId))
cnDelivery := gjson.Get(info, "cn_delivery").String()
hkDelivery := gjson.Get(info, "hk_delivery").String()
if cnDelivery != "" || hkDelivery != "" {
delivery["cn_delivery"] = cnDelivery
delivery["hk_delivery"] = hkDelivery
return
}
return
}
// 判断能否购买
func (ls *LyService) GetIsBuy(sku model.LySku) (isBuy int) {
if sku.GoodsStatus != 1 {
return
}
if sku.Moq > sku.Stock {
return
}
if len(sku.LadderPrice) == 0 {
return
}
if sku.Stock == 0 {
return
}
return 1
}
// 合并spu的信息
func (ls *LyService) CombineSup(sku model.LySku, spuStr string) model.LySku {
sku.UpdateTime = gjson.Get(spuStr, "update_time").Int()
sku.ClassID1 = int(gjson.Get(spuStr, "class_id1").Int())
sku.ClassID2 = int(gjson.Get(spuStr, "class_id2").Int())
sku.SpuName = gjson.Get(spuStr, "spu_name").String()
sku.SpuBrief = gjson.Get(spuStr, "spu_brief").String()
sku.SpuDetail = gjson.Get(spuStr, "spu_detail").String()
sku.Status = int(gjson.Get(spuStr, "status").Int())
sku.Encap = gjson.Get(spuStr, "encap").String()
return sku
}
// 获取系数和总体价格,生成和处理价格的方法,很重要
func (ls *LyService) GetCoefficientAndPrice(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
...@@ -213,17 +278,25 @@ func (ls *LyService) GetCoefficientAndPrice(sku model.LySku) model.LySku { ...@@ -213,17 +278,25 @@ func (ls *LyService) GetCoefficientAndPrice(sku model.LySku) model.LySku {
ladderPrice = sku.LadderPrice ladderPrice = sku.LadderPrice
} }
} }
//获取折扣系数
sku = priceService.GetDiscountRatio(sku)
data = make([]model.LadderPrice, len(ladderPrice)) data = make([]model.LadderPrice, len(ladderPrice))
for key, price := range ladderPrice { for key, price := range ladderPrice {
if price.Purchases == 0 { if price.Purchases == 0 {
continue continue
} }
data[key].Purchases = price.Purchases data[key].Purchases = price.Purchases
//下面的价格,还要乘于折扣系数
if price.PriceUs != 0 { if price.PriceUs != 0 {
data[key].PriceUs = c.MyRound(price.PriceUs, 4) priceUs := c.MyRound(price.PriceUs, 4)
priceUs = c.MyRound(c.MulFloat(price.PriceUs, sku.DiscountRatio.RatioUsd), 4)
data[key].PriceUs = priceUs
} }
if price.PriceCn != 0 { if price.PriceCn != 0 {
data[key].PriceCn = c.MyRound(price.PriceCn, 4) priceCn := c.MyRound(price.PriceCn, 4)
priceCn = c.MyRound(c.MulFloat(price.PriceCn, sku.DiscountRatio.Ratio), 4)
data[key].PriceCn = priceCn
} }
//专卖成本价 //专卖成本价
...@@ -420,69 +493,3 @@ func (ls *LyService) GetCoefficientAndPrice(sku model.LySku) model.LySku { ...@@ -420,69 +493,3 @@ func (ls *LyService) GetCoefficientAndPrice(sku model.LySku) model.LySku {
} }
return sku return sku
} }
// 获取供应商货期
func (ls *LyService) GetDelivery(supplierId int64, canal string) (delivery map[string]string) {
delivery = make(map[string]string)
redisCon := gredis.Conn("default_r")
defer redisCon.Close()
if canal != "" {
supplierRatio, _ := redis.String(redisCon.Do("HGET", "supp_ratio", canal))
if supplierRatio != "" {
cnDeliveryTime := gjson.Get(supplierRatio, "cn_delivery_time").String()
usDeliveryTime := gjson.Get(supplierRatio, "us_delivery_time").String()
//为了兼容供应商修改的问题
if cnDeliveryTime != "周" && cnDeliveryTime != "天" {
delivery["cn_delivery"] = gjson.Get(supplierRatio, "cn_delivery_time").String()
} else {
delivery["cn_delivery"] = ""
}
if usDeliveryTime != "周" && usDeliveryTime != "天" {
delivery["hk_delivery"] = gjson.Get(supplierRatio, "us_delivery_time").String()
} else {
delivery["hk_delivery"] = ""
}
}
return
}
info, _ := redis.String(redisCon.Do("HGET", "SUPPLIER_REDIS_INFO_", supplierId))
cnDelivery := gjson.Get(info, "cn_delivery").String()
hkDelivery := gjson.Get(info, "hk_delivery").String()
if cnDelivery != "" || hkDelivery != "" {
delivery["cn_delivery"] = cnDelivery
delivery["hk_delivery"] = hkDelivery
return
}
return
}
// 判断能否购买
func (ls *LyService) GetIsBuy(sku model.LySku) (isBuy int) {
if sku.GoodsStatus != 1 {
return
}
if sku.Moq > sku.Stock {
return
}
if len(sku.LadderPrice) == 0 {
return
}
if sku.Stock == 0 {
return
}
return 1
}
// 合并spu的信息
func (ls *LyService) CombineSup(sku model.LySku, spuStr string) model.LySku {
sku.UpdateTime = gjson.Get(spuStr, "update_time").Int()
sku.ClassID1 = int(gjson.Get(spuStr, "class_id1").Int())
sku.ClassID2 = int(gjson.Get(spuStr, "class_id2").Int())
sku.SpuName = gjson.Get(spuStr, "spu_name").String()
sku.SpuBrief = gjson.Get(spuStr, "spu_brief").String()
sku.SpuDetail = gjson.Get(spuStr, "spu_detail").String()
sku.Status = int(gjson.Get(spuStr, "status").Int())
sku.Encap = gjson.Get(spuStr, "encap").String()
return sku
}
...@@ -17,7 +17,7 @@ import ( ...@@ -17,7 +17,7 @@ import (
type PriceService struct { type PriceService struct {
} }
// GenerateLadderPrice 构建专营的阶梯价,现在专营只会存一个简单的成本价,阶梯数量是1,所以我这边要根据专营的阶梯系数去构建具体的阶梯价 // 构建专营的阶梯价,现在专营只会存一个简单的成本价,阶梯数量是1,所以我这边要根据专营的阶梯系数去构建具体的阶梯价
func (ps *PriceService) GenerateLadderPrice(sku model.LySku) model.LySku { func (ps *PriceService) GenerateLadderPrice(sku model.LySku) model.LySku {
//先去找到对应的价格系数 //先去找到对应的价格系数
var ratioDataKey string var ratioDataKey string
...@@ -31,7 +31,7 @@ func (ps *PriceService) GenerateLadderPrice(sku model.LySku) model.LySku { ...@@ -31,7 +31,7 @@ func (ps *PriceService) GenerateLadderPrice(sku model.LySku) model.LySku {
defer redisCon.Close() defer redisCon.Close()
//找一个标志位,因为默认的全局折扣系数的数据格式和非全局的是不一样的 //找一个标志位,因为默认的全局折扣系数的数据格式和非全局的是不一样的
isDefaultPriceRatio := false isDefaultPriceRatio := false
priceRatioCache, _ := redis.String(redisCon.Do("HGET", "magic_cube_price_rule_v2", sku.SupplierId)) priceRatioCache, _ := redis.String(redisCon.Do("HGET", "magic_cube_price_rule_v2", sku.Canal))
//判断是否是空 //判断是否是空
checkNullRation := gjson.Get(priceRatioCache, ratioDataKey).String() checkNullRation := gjson.Get(priceRatioCache, ratioDataKey).String()
//如果这个渠道没有对应的折扣系数,那么就去读取全局的 //如果这个渠道没有对应的折扣系数,那么就去读取全局的
...@@ -154,13 +154,15 @@ func (ps *PriceService) GenerateLadderPrice(sku model.LySku) model.LySku { ...@@ -154,13 +154,15 @@ func (ps *PriceService) GenerateLadderPrice(sku model.LySku) model.LySku {
} }
//找不到特定的系数,那就去找全局的 //找不到特定的系数,那就去找全局的
if !foundRatio { if !foundRatio {
fmt.Println("去找默认系数")
priceRatioCache, _ = redis.String(redisCon.Do("GET", "magic_cube_price_rule_v2_default")) priceRatioCache, _ = redis.String(redisCon.Do("GET", "magic_cube_price_rule_v2_default"))
priceRatioArr := gjson.Get(priceRatioCache, ratioDataKey).Array() priceRatioArr := gjson.Get(priceRatioCache, ratioDataKey).Array()
priceRatioList = nil priceRatioList = nil
for _, value := range priceRatioArr { for _, value := range priceRatioArr {
var priceRatio model.PriceRatio var priceRatio model.PriceRatio
priceRatio.Ratio = gjson.Get(value.String(), "ratio").Float() priceRatio.Ratio = gjson.Get(value.String(), "price").Float()
priceRatio.RatioUsd = gjson.Get(value.String(), "ratio_usd").Float() priceRatio.RatioUsd = gjson.Get(value.String(), "price_usd").Float()
priceRatio.Purchases = gjson.Get(value.String(), "purchases").Int()
priceRatioList = append(priceRatioList, priceRatio) priceRatioList = append(priceRatioList, priceRatio)
} }
priceRatioSort = -1 priceRatioSort = -1
......
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