Commit ac56533f by mushishixian

修复bug

parent 003c8941
The file could not be displayed because it is too large.
...@@ -39,18 +39,14 @@ require ( ...@@ -39,18 +39,14 @@ require (
github.com/tidwall/gjson v1.6.1 github.com/tidwall/gjson v1.6.1
github.com/tidwall/sjson v1.1.1 github.com/tidwall/sjson v1.1.1
github.com/uniplaces/carbon v0.1.6 // indirect github.com/uniplaces/carbon v0.1.6 // indirect
go.etcd.io/bbolt v1.3.4 // indirect
go.mongodb.org/mongo-driver v1.3.5 // indirect go.mongodb.org/mongo-driver v1.3.5 // indirect
go.uber.org/zap v1.14.1 // indirect go.uber.org/zap v1.14.1 // indirect
golang.org/x/tools v0.0.0-20191216173652-a0e659d51361 // indirect
google.golang.org/genproto v0.0.0-20200527145253-8367513e4ece // indirect google.golang.org/genproto v0.0.0-20200527145253-8367513e4ece // indirect
google.golang.org/grpc v1.29.1 // indirect google.golang.org/grpc v1.29.1 // indirect
google.golang.org/protobuf v1.24.0 // indirect
gopkg.in/ini.v1 v1.51.0 // indirect gopkg.in/ini.v1 v1.51.0 // indirect
gopkg.in/mgo.v2 v2.0.0-20190816093944-a6b53ec6cb22 gopkg.in/mgo.v2 v2.0.0-20190816093944-a6b53ec6cb22
gopkg.in/olivere/elastic.v5 v5.0.85 gopkg.in/olivere/elastic.v5 v5.0.85
sigs.k8s.io/yaml v1.2.0 // indirect sigs.k8s.io/yaml v1.2.0 // indirect
xorm.io/core v0.7.2-0.20190928055935-90aeac8d08eb // indirect
) )
replace google.golang.org/grpc => google.golang.org/grpc v1.26.0 replace google.golang.org/grpc => google.golang.org/grpc v1.26.0
...@@ -6,6 +6,7 @@ import ( ...@@ -6,6 +6,7 @@ import (
//联营sku结构体 //联营sku结构体
type LySku struct { type LySku struct {
LadderPrice []LadderPrice `json:"-"`
SpuId string `json:"spu_id"` SpuId string `json:"spu_id"`
OldGoodsId int64 `json:"old_goods_id"` OldGoodsId int64 `json:"old_goods_id"`
UpdateTime int64 `json:"update_time"` UpdateTime int64 `json:"update_time"`
...@@ -20,7 +21,7 @@ type LySku struct { ...@@ -20,7 +21,7 @@ type LySku struct {
Stock int64 `json:"stock"` Stock int64 `json:"stock"`
HkDeliveryTime string `json:"hk_delivery_time"` HkDeliveryTime string `json:"hk_delivery_time"`
CnDeliveryTime string `json:"cn_delivery_time"` CnDeliveryTime string `json:"cn_delivery_time"`
LadderPrice []LadderPrice `json:"ladder_price"` LadderPriceResult interface{} `json:"ladder_price"`
GoodsImages string `json:"goods_images"` GoodsImages string `json:"goods_images"`
Canal string `json:"canal"` Canal string `json:"canal"`
Packing string `json:"packing"` Packing string `json:"packing"`
......
...@@ -53,6 +53,10 @@ func (ls *LyService) LyGoodsDetail(ctx *gin.Context, goodsIds []string, ch chan ...@@ -53,6 +53,10 @@ func (ls *LyService) LyGoodsDetail(ctx *gin.Context, goodsIds []string, ch chan
GoodsRes := sync.Map{} GoodsRes := sync.Map{}
for goodsId, skuStr := range skuArr { for goodsId, skuStr := range skuArr {
if skuStr == "" {
GoodsRes.Store(goodsId, false)
continue
}
//初始化有序map,拼接data 数据 //初始化有序map,拼接data 数据
//A := orderedmap.New() //A := orderedmap.New()
sku := model.InitSkuData(skuStr) sku := model.InitSkuData(skuStr)
...@@ -125,7 +129,6 @@ func (ls *LyService) LyGoodsDetail(ctx *gin.Context, goodsIds []string, ch chan ...@@ -125,7 +129,6 @@ func (ls *LyService) LyGoodsDetail(ctx *gin.Context, goodsIds []string, ch chan
hasActivity = true hasActivity = true
} }
} }
//获取活动价 //获取活动价
if !hasActivity { if !hasActivity {
sku = ls.GetActivityPrice(sku, "", power) sku = ls.GetActivityPrice(sku, "", power)
...@@ -141,7 +144,6 @@ func (ls *LyService) LyGoodsDetail(ctx *gin.Context, goodsIds []string, ch chan ...@@ -141,7 +144,6 @@ func (ls *LyService) LyGoodsDetail(ctx *gin.Context, goodsIds []string, ch chan
hasActivity = true hasActivity = true
} }
} }
//处理阶梯价数据 //处理阶梯价数据
if len(sku.LadderPrice) > 0 { if len(sku.LadderPrice) > 0 {
//排序 //排序
...@@ -152,7 +154,6 @@ func (ls *LyService) LyGoodsDetail(ctx *gin.Context, goodsIds []string, ch chan ...@@ -152,7 +154,6 @@ func (ls *LyService) LyGoodsDetail(ctx *gin.Context, goodsIds []string, ch chan
sku.Moq = purchases sku.Moq = purchases
} }
} }
//获取系数 //获取系数
sku = ls.GetCoefficient(sku) sku = ls.GetCoefficient(sku)
...@@ -161,12 +162,14 @@ func (ls *LyService) LyGoodsDetail(ctx *gin.Context, goodsIds []string, ch chan ...@@ -161,12 +162,14 @@ func (ls *LyService) LyGoodsDetail(ctx *gin.Context, goodsIds []string, ch chan
if sku.SupplierId != 0 { if sku.SupplierId != 0 {
sku.SuppExtendFee = ls.GetExtendFee(sku.SupplierId, sku.Canal) sku.SuppExtendFee = ls.GetExtendFee(sku.SupplierId, sku.Canal)
} }
//还要处理货期 //还要处理货期
delivery := ls.GetDelivery(sku.SupplierId, sku.Canal) delivery := ls.GetDelivery(sku.SupplierId, sku.Canal)
if delivery["cn_delivery"] != "" {
sku.CnDeliveryTime = delivery["cn_delivery"] sku.CnDeliveryTime = delivery["cn_delivery"]
}
if delivery["hk_delivery"] != "" {
sku.HkDeliveryTime = delivery["hk_delivery"] sku.HkDeliveryTime = delivery["hk_delivery"]
}
} }
//处理是否可以购买 //处理是否可以购买
...@@ -174,6 +177,12 @@ func (ls *LyService) LyGoodsDetail(ctx *gin.Context, goodsIds []string, ch chan ...@@ -174,6 +177,12 @@ func (ls *LyService) LyGoodsDetail(ctx *gin.Context, goodsIds []string, ch chan
sku.Mpq = 1 sku.Mpq = 1
} }
if len(sku.LadderPrice) > 0 {
sku.LadderPriceResult = sku.LadderPrice
} else {
sku.LadderPriceResult = []int{}
}
//判断是否可以购买 //判断是否可以购买
sku.IsBuy = ls.GetIsBuy(sku) sku.IsBuy = ls.GetIsBuy(sku)
...@@ -181,7 +190,6 @@ func (ls *LyService) LyGoodsDetail(ctx *gin.Context, goodsIds []string, ch chan ...@@ -181,7 +190,6 @@ func (ls *LyService) LyGoodsDetail(ctx *gin.Context, goodsIds []string, ch chan
sku = ls.CombineSup(sku, spu) sku = ls.CombineSup(sku, spu)
//最后一步,将sku的全部信息放到有序map里面 //最后一步,将sku的全部信息放到有序map里面
GoodsRes.Store(goodsId, sku) GoodsRes.Store(goodsId, sku)
//(*goodsRes)[goodsId] = A //(*goodsRes)[goodsId] = A
......
...@@ -196,6 +196,7 @@ func (ls *LyService) GetCoefficient(sku model.LySku) model.LySku { ...@@ -196,6 +196,7 @@ func (ls *LyService) GetCoefficient(sku model.LySku) model.LySku {
return sku return sku
} }
flag := 0 flag := 0
data := make([]model.LadderPrice, len(sku.LadderPrice))
//专卖 //专卖
if sku.SupplierId == 17 { if sku.SupplierId == 17 {
ladderPrice := sku.LadderPrice ladderPrice := sku.LadderPrice
...@@ -203,19 +204,23 @@ func (ls *LyService) GetCoefficient(sku model.LySku) model.LySku { ...@@ -203,19 +204,23 @@ func (ls *LyService) GetCoefficient(sku model.LySku) model.LySku {
if price.Purchases == 0 { if price.Purchases == 0 {
continue continue
} }
ladderPrice[key].PriceUs = common.MyRound(price.PriceUs, 4) data[key].Purchases = price.Purchases
ladderPrice[key].PriceCn = common.MyRound(price.PriceCn, 4) if price.PriceUs != 0 {
data[key].PriceUs = common.MyRound(price.PriceUs, 4)
}
if price.PriceCn != 0 {
data[key].PriceCn = common.MyRound(price.PriceCn, 4)
}
//联营或者专卖 同时 存在活动价格 //联营或者专卖 同时 存在活动价格
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 {
acPrice := price.PriceCn tempAcPrice := common.MyRound(price.PriceCn*(sku.Ratio/100), 4)
ladderPrice[key].PriceAc = common.MyRound(price.PriceCn*(sku.Ratio/100), 4) data[key].PriceAc = tempAcPrice
//优惠价后等于0,就代表没有搞活动 //优惠价后等于0,就代表没有搞活动
if ladderPrice[key].PriceAc <= 0 { if tempAcPrice <= 0 {
sku.AcType = 0 sku.AcType = 0
} }
//价格与原价一样 //价格与原价一样
if acPrice == ladderPrice[key].PriceAc && key < 2 { if data[key].PriceCn == tempAcPrice && key < 2 {
flag++ flag++
if flag >= 2 || (len(ladderPrice) < 2) { if flag >= 2 || (len(ladderPrice) < 2) {
sku.AcType = 0 sku.AcType = 0
...@@ -279,61 +284,63 @@ func (ls *LyService) GetCoefficient(sku model.LySku) model.LySku { ...@@ -279,61 +284,63 @@ func (ls *LyService) GetCoefficient(sku model.LySku) model.LySku {
if !hasCoefficient { if !hasCoefficient {
coefficient = defaultCoefficient coefficient = defaultCoefficient
} }
// 为何是固定的1.13,关税基本不会变,有变的话跟产品沟通手动修改即可 // 为何是固定的1.13,关税基本不会变,有变的话跟产品沟通手动修改即可
//$tax = config('website.tax'); //$tax = config('website.tax');
tax := 1.13 tax := 1.13
for key, price := range sku.LadderPrice { for key, price := range sku.LadderPrice {
if price.Purchases == 0 { if price.Purchases == 0 {
continue continue
} }
data[key].Purchases = price.Purchases
//根据系数处理美金 //根据系数处理美金
sku.LadderPrice[key].PriceUs = common.MyRound(price.PriceUs*coefficient.ExtraRatio*coefficient.Hk, 4) data[key].PriceUs = common.MyRound(price.PriceUs*coefficient.ExtraRatio*coefficient.Hk, 4)
//处理人民币 //处理人民币
sku.LadderPrice[key].PriceCn = common.MyRound(price.PriceUs*coefficient.ExtraRatio*coefficient.Cn*coefficient.Ratio*tax, 4) data[key].PriceCn = common.MyRound(price.PriceUs*coefficient.ExtraRatio*coefficient.Cn*coefficient.Ratio*tax, 4)
//处理mouser的成本价 //处理mouser的成本价
//mouser成本价是什么,斌哥同步过来的成本价 //mouser成本价是什么,斌哥同步过来的成本价
//price.CostPrice是专门针对贸泽(mouser)的 //sku.LadderPrice[key].CostPrice是专门针对贸泽(mouser)的
if sku.AcType == 2 && sku.SupplierId == 14 { if sku.AcType == 2 && sku.SupplierId == 14 {
if price.CostPrice != 0 { if price.CostPrice != 0 {
sku.LadderPrice[key].PriceAc = common.MyRound(price.CostPrice*coefficient.ExtraRatio*coefficient.Cn*coefficient.Ratio, 4) data[key].PriceAc = common.MyRound(price.CostPrice*coefficient.ExtraRatio*coefficient.Cn*coefficient.Ratio, 4)
sku.LadderPrice[key].PriceUs = common.MyRound(price.CostPrice*coefficient.ExtraRatio*coefficient.Hk, 4) data[key].PriceUs = common.MyRound(price.CostPrice*coefficient.ExtraRatio*coefficient.Hk, 4)
} else { } else {
sku.LadderPrice[key].PriceAc = price.PriceCn data[key].PriceAc = data[key].PriceCn
} }
continue continue
} }
//处理活动价和原价相同的情况 //处理活动价和原价相同的情况
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(price.PriceCn*(sku.Ratio/100), 4) priceAc := common.MyRound(data[key].PriceCn*(sku.Ratio/100), 4)
sku.LadderPrice[key].PriceAc = priceAc data[key].PriceAc = priceAc
if priceAc <= 0 { if priceAc <= 0 {
sku.AcType = 0 sku.AcType = 0
break break
} else { } else {
if sku.AcType == 4 { if sku.AcType == 4 {
sku.LadderPrice[key].PriceCn = priceAc data[key].PriceCn = priceAc
sku.AcType = 0 sku.AcType = 0
} }
} }
//为什么$kp < 2,如果第一阶梯或第二阶梯价格和活动价一样,就不输出活动价了 //为什么$kp < 2,如果第一阶梯或第二阶梯价格和活动价一样,就不输出活动价了
//活动价都是有样式的和平时不一样,如果价格一样,但是样子是活动价,客户会迷惑,所以不输出即可,保持原来的样式 //活动价都是有样式的和平时不一样,如果价格一样,但是样子是活动价,客户会迷惑,所以不输出即可,保持原来的样式
if sku.LadderPrice[key].PriceCn == priceAc && key < 2 { if data[key].PriceCn == priceAc && key < 2 {
flag++ flag++
if flag >= 2 { if flag >= 2 {
sku.AcType = 0 sku.AcType = 0
} }
if len(sku.LadderPrice) > 1 { if len(data) > 1 {
if sku.LadderPrice[1].PriceCn == 0 { if data[1].PriceCn == 0 {
sku.AcType = 0 sku.AcType = 0
} }
} }
} }
} }
} }
if len(data) > 0 {
sku.LadderPrice = data
}
//输出税费到前端 //输出税费到前端
coefficient.Tax = tax coefficient.Tax = tax
sku.Coefficient = coefficient sku.Coefficient = coefficient
...@@ -348,7 +355,6 @@ func (ls *LyService) GetDelivery(supplierId int64, canal string) (delivery map[s ...@@ -348,7 +355,6 @@ func (ls *LyService) GetDelivery(supplierId int64, canal string) (delivery map[s
defer redisCon.Close() defer redisCon.Close()
if canal != "" { if canal != "" {
supplierRatio, _ := redis.String(redisCon.Do("HGET", "supp_ratio", canal)) supplierRatio, _ := redis.String(redisCon.Do("HGET", "supp_ratio", canal))
fmt.Println(supplierRatio)
if supplierRatio != "" { if supplierRatio != "" {
delivery["cn_delivery"] = gjson.Get(supplierRatio, "cn_delivery_time").String() delivery["cn_delivery"] = gjson.Get(supplierRatio, "cn_delivery_time").String()
delivery["hk_delivery"] = gjson.Get(supplierRatio, "us_delivery_time").String() delivery["hk_delivery"] = gjson.Get(supplierRatio, "us_delivery_time").String()
......
...@@ -28,7 +28,7 @@ func (ls *LyService) GetActivityPrice(sku model.LySku, suffix string, power Powe ...@@ -28,7 +28,7 @@ func (ls *LyService) GetActivityPrice(sku model.LySku, suffix string, power Powe
redisCon := gredis.Conn("default_r") redisCon := gredis.Conn("default_r")
defer redisCon.Close() defer redisCon.Close()
supplierIdStr := strconv.Itoa(int(sku.SupplierId)) supplierIdStr := strconv.Itoa(int(sku.SupplierId))
activityInfo, _ := redis.String(redisCon.Do("HGET", "Self_ActivityPrice_"+supplierIdStr+suffix)) activityInfo, _ := redis.String(redisCon.Do("GET", "Self_ActivityPrice_"+supplierIdStr+suffix))
//找不到对应的活动价格信息,就直接返回空 //找不到对应的活动价格信息,就直接返回空
if activityInfo == "" { if activityInfo == "" {
return sku return sku
...@@ -46,8 +46,10 @@ func (ls *LyService) GetActivityPrice(sku model.LySku, suffix string, power Powe ...@@ -46,8 +46,10 @@ func (ls *LyService) GetActivityPrice(sku model.LySku, suffix string, power Powe
brandIdArray := gjson.Get(activityInfo, "brand_id").Array() brandIdArray := gjson.Get(activityInfo, "brand_id").Array()
var brandIds []string var brandIds []string
for _, brandId := range brandIdArray { for _, brandId := range brandIdArray {
if brandId.String() != "" {
brandIds = append(brandIds, brandId.String()) brandIds = append(brandIds, brandId.String())
} }
}
goodsNameArray := gjson.Get(activityInfo, "goods_name").Array() goodsNameArray := gjson.Get(activityInfo, "goods_name").Array()
var goodsNames []string var goodsNames []string
for _, goodsName := range goodsNameArray { for _, goodsName := range goodsNameArray {
...@@ -183,7 +185,6 @@ func (ls *LyService) GetActivityPrice(sku model.LySku, suffix string, power Powe ...@@ -183,7 +185,6 @@ func (ls *LyService) GetActivityPrice(sku model.LySku, suffix string, power Powe
//} //}
} }
} }
//判断是否有活动 //判断是否有活动
if !hasActivity { if !hasActivity {
return sku 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