Commit 8f652631 by huangchengyi
parents 723ef51b d667a385
......@@ -39,18 +39,14 @@ require (
github.com/tidwall/gjson v1.6.1
github.com/tidwall/sjson v1.1.1
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.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/grpc v1.29.1 // indirect
google.golang.org/protobuf v1.24.0 // indirect
gopkg.in/ini.v1 v1.51.0 // indirect
gopkg.in/mgo.v2 v2.0.0-20190816093944-a6b53ec6cb22
gopkg.in/olivere/elastic.v5 v5.0.85
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
......@@ -6,33 +6,34 @@ import (
//联营sku结构体
type LySku struct {
SpuId string `json:"spu_id"`
OldGoodsId int64 `json:"old_goods_id"`
UpdateTime int64 `json:"update_time"`
CpTime int64 `json:"cp_time"`
GoodsStatus int64 `json:"goods_status"`
GoodsType int64 `json:"goods_type"`
SupplierId int64 `json:"supplier_id"`
Encoded string `json:"encoded"`
BatchSn string `json:"batch_sn"`
Moq int64 `json:"moq"`
Mpq int64 `json:"mpq"`
Stock int64 `json:"stock"`
HkDeliveryTime string `json:"hk_delivery_time"`
CnDeliveryTime string `json:"cn_delivery_time"`
LadderPrice []LadderPrice `json:"ladder_price"`
GoodsImages string `json:"goods_images"`
Canal string `json:"canal"`
Packing string `json:"packing"`
GoodsId string `json:"goods_id"`
GoodsName string `json:"goods_name"`
BrandName string `json:"brand_name"`
SupplierName string `json:"supplier_name"`
Attrs interface{} `json:"attrs"`
ScmBrand interface{} `json:"scm_brand"`
AcType int `json:"ac_type"`
AllowCoupon int `json:"allow_coupon"`
BrandId int64 `json:"brand_id"`
LadderPrice []LadderPrice `json:"-"`
SpuId string `json:"spu_id"`
OldGoodsId int64 `json:"old_goods_id"`
UpdateTime int64 `json:"update_time"`
CpTime int64 `json:"cp_time"`
GoodsStatus int64 `json:"goods_status"`
GoodsType int64 `json:"goods_type"`
SupplierId int64 `json:"supplier_id"`
Encoded string `json:"encoded"`
BatchSn string `json:"batch_sn"`
Moq int64 `json:"moq"`
Mpq int64 `json:"mpq"`
Stock int64 `json:"stock"`
HkDeliveryTime string `json:"hk_delivery_time"`
CnDeliveryTime string `json:"cn_delivery_time"`
LadderPriceResult interface{} `json:"ladder_price"`
GoodsImages string `json:"goods_images"`
Canal string `json:"canal"`
Packing string `json:"packing"`
GoodsId string `json:"goods_id"`
GoodsName string `json:"goods_name"`
BrandName string `json:"brand_name"`
SupplierName string `json:"supplier_name"`
Attrs interface{} `json:"attrs"`
ScmBrand interface{} `json:"scm_brand"`
AcType int `json:"ac_type"`
AllowCoupon int `json:"allow_coupon"`
BrandId int64 `json:"brand_id"`
//系数相关
Coefficient interface{} `json:"coefficient,omitempty"`
Original interface{} `json:"original_price"`
......
......@@ -53,6 +53,10 @@ func (ls *LyService) LyGoodsDetail(ctx *gin.Context, goodsIds []string, ch chan
GoodsRes := sync.Map{}
for goodsId, skuStr := range skuArr {
if skuStr == "" {
GoodsRes.Store(goodsId, false)
continue
}
//初始化有序map,拼接data 数据
//A := orderedmap.New()
sku := model.InitSkuData(skuStr)
......@@ -125,7 +129,6 @@ func (ls *LyService) LyGoodsDetail(ctx *gin.Context, goodsIds []string, ch chan
hasActivity = true
}
}
//获取活动价
if !hasActivity {
sku = ls.GetActivityPrice(sku, "", power)
......@@ -141,7 +144,6 @@ func (ls *LyService) LyGoodsDetail(ctx *gin.Context, goodsIds []string, ch chan
hasActivity = true
}
}
//处理阶梯价数据
if len(sku.LadderPrice) > 0 {
//排序
......@@ -152,7 +154,6 @@ func (ls *LyService) LyGoodsDetail(ctx *gin.Context, goodsIds []string, ch chan
sku.Moq = purchases
}
}
//获取系数
sku = ls.GetCoefficient(sku)
......@@ -161,12 +162,14 @@ func (ls *LyService) LyGoodsDetail(ctx *gin.Context, goodsIds []string, ch chan
if sku.SupplierId != 0 {
sku.SuppExtendFee = ls.GetExtendFee(sku.SupplierId, sku.Canal)
}
//还要处理货期
delivery := ls.GetDelivery(sku.SupplierId, sku.Canal)
sku.CnDeliveryTime = delivery["cn_delivery"]
sku.HkDeliveryTime = delivery["hk_delivery"]
if delivery["cn_delivery"] != "" {
sku.CnDeliveryTime = delivery["cn_delivery"]
}
if delivery["hk_delivery"] != "" {
sku.HkDeliveryTime = delivery["hk_delivery"]
}
}
//处理是否可以购买
......@@ -174,6 +177,12 @@ func (ls *LyService) LyGoodsDetail(ctx *gin.Context, goodsIds []string, ch chan
sku.Mpq = 1
}
if len(sku.LadderPrice) > 0 {
sku.LadderPriceResult = sku.LadderPrice
} else {
sku.LadderPriceResult = []int{}
}
//判断是否可以购买
sku.IsBuy = ls.GetIsBuy(sku)
......@@ -181,7 +190,6 @@ func (ls *LyService) LyGoodsDetail(ctx *gin.Context, goodsIds []string, ch chan
sku = ls.CombineSup(sku, spu)
//最后一步,将sku的全部信息放到有序map里面
GoodsRes.Store(goodsId, sku)
//(*goodsRes)[goodsId] = A
......
......@@ -196,6 +196,7 @@ func (ls *LyService) GetCoefficient(sku model.LySku) model.LySku {
return sku
}
flag := 0
data := make([]model.LadderPrice, len(sku.LadderPrice))
//专卖
if sku.SupplierId == 17 {
ladderPrice := sku.LadderPrice
......@@ -203,19 +204,23 @@ func (ls *LyService) GetCoefficient(sku model.LySku) model.LySku {
if price.Purchases == 0 {
continue
}
ladderPrice[key].PriceUs = common.MyRound(price.PriceUs, 4)
ladderPrice[key].PriceCn = common.MyRound(price.PriceCn, 4)
data[key].Purchases = price.Purchases
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 {
acPrice := price.PriceCn
ladderPrice[key].PriceAc = common.MyRound(price.PriceCn*(sku.Ratio/100), 4)
tempAcPrice := common.MyRound(price.PriceCn*(sku.Ratio/100), 4)
data[key].PriceAc = tempAcPrice
//优惠价后等于0,就代表没有搞活动
if ladderPrice[key].PriceAc <= 0 {
if tempAcPrice <= 0 {
sku.AcType = 0
}
//价格与原价一样
if acPrice == ladderPrice[key].PriceAc && key < 2 {
if data[key].PriceCn == tempAcPrice && key < 2 {
flag++
if flag >= 2 || (len(ladderPrice) < 2) {
sku.AcType = 0
......@@ -279,61 +284,63 @@ func (ls *LyService) GetCoefficient(sku model.LySku) model.LySku {
if !hasCoefficient {
coefficient = defaultCoefficient
}
// 为何是固定的1.13,关税基本不会变,有变的话跟产品沟通手动修改即可
//$tax = config('website.tax');
tax := 1.13
for key, price := range sku.LadderPrice {
if price.Purchases == 0 {
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成本价是什么,斌哥同步过来的成本价
//price.CostPrice是专门针对贸泽(mouser)的
//sku.LadderPrice[key].CostPrice是专门针对贸泽(mouser)的
if sku.AcType == 2 && sku.SupplierId == 14 {
if price.CostPrice != 0 {
sku.LadderPrice[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].PriceAc = common.MyRound(price.CostPrice*coefficient.ExtraRatio*coefficient.Cn*coefficient.Ratio, 4)
data[key].PriceUs = common.MyRound(price.CostPrice*coefficient.ExtraRatio*coefficient.Hk, 4)
} else {
sku.LadderPrice[key].PriceAc = price.PriceCn
data[key].PriceAc = data[key].PriceCn
}
continue
}
//处理活动价和原价相同的情况
if (sku.GoodsType == 1 || sku.GoodsType == 2) && sku.AcType > 1 && sku.Ratio > 0 {
priceAc := common.MyRound(price.PriceCn*(sku.Ratio/100), 4)
sku.LadderPrice[key].PriceAc = priceAc
priceAc := common.MyRound(data[key].PriceCn*(sku.Ratio/100), 4)
data[key].PriceAc = priceAc
if priceAc <= 0 {
sku.AcType = 0
break
} else {
if sku.AcType == 4 {
sku.LadderPrice[key].PriceCn = priceAc
data[key].PriceCn = priceAc
sku.AcType = 0
}
}
//为什么$kp < 2,如果第一阶梯或第二阶梯价格和活动价一样,就不输出活动价了
//活动价都是有样式的和平时不一样,如果价格一样,但是样子是活动价,客户会迷惑,所以不输出即可,保持原来的样式
if sku.LadderPrice[key].PriceCn == priceAc && key < 2 {
if data[key].PriceCn == priceAc && key < 2 {
flag++
if flag >= 2 {
sku.AcType = 0
}
if len(sku.LadderPrice) > 1 {
if sku.LadderPrice[1].PriceCn == 0 {
if len(data) > 1 {
if data[1].PriceCn == 0 {
sku.AcType = 0
}
}
}
}
}
if len(data) > 0 {
sku.LadderPrice = data
}
//输出税费到前端
coefficient.Tax = tax
sku.Coefficient = coefficient
......@@ -348,7 +355,6 @@ func (ls *LyService) GetDelivery(supplierId int64, canal string) (delivery map[s
defer redisCon.Close()
if canal != "" {
supplierRatio, _ := redis.String(redisCon.Do("HGET", "supp_ratio", canal))
fmt.Println(supplierRatio)
if supplierRatio != "" {
delivery["cn_delivery"] = gjson.Get(supplierRatio, "cn_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
redisCon := gredis.Conn("default_r")
defer redisCon.Close()
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 == "" {
return sku
......@@ -46,7 +46,9 @@ func (ls *LyService) GetActivityPrice(sku model.LySku, suffix string, power Powe
brandIdArray := gjson.Get(activityInfo, "brand_id").Array()
var brandIds []string
for _, brandId := range brandIdArray {
brandIds = append(brandIds, brandId.String())
if brandId.String() != "" {
brandIds = append(brandIds, brandId.String())
}
}
goodsNameArray := gjson.Get(activityInfo, "goods_name").Array()
var goodsNames []string
......@@ -183,7 +185,6 @@ func (ls *LyService) GetActivityPrice(sku model.LySku, suffix string, power Powe
//}
}
}
//判断是否有活动
if !hasActivity {
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