From 83f94933523bc545c2fe62f359d3f1cfad2e990e Mon Sep 17 00:00:00 2001 From: gazebo Date: Mon, 11 Nov 2019 09:20:14 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BB=B7=E6=A0=BC=E5=8C=85=E5=8F=82=E6=95=B0?= =?UTF-8?q?=E6=B7=BB=E5=8A=A0priceAdd?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- business/jxstore/act/act.go | 4 +--- business/jxstore/cms/store_sku.go | 6 +++--- business/jxstore/cms/sync_store_sku.go | 4 ++-- business/jxutils/jxutils_cms.go | 20 +++++++++++--------- business/model/store.go | 1 + 5 files changed, 18 insertions(+), 17 deletions(-) diff --git a/business/jxstore/act/act.go b/business/jxstore/act/act.go index 7f62439dd..9e78f07e1 100644 --- a/business/jxstore/act/act.go +++ b/business/jxstore/act/act.go @@ -146,8 +146,6 @@ func ActStoreSkuParam2Model(ctx *jxcontext.Context, db *dao.DaoDB, act *model.Ac storeSkuInfo := storeSkuMap[jxutils.Combine2Int(v.StoreID, v.SkuID)] if storeSkuInfo != nil { jxPrice := storeSkuInfo.Price - // pricePercentage := jxutils.GetPricePercentage(storeDetail.PricePercentagePackObj, jxPrice, int(storeDetail.PricePercentage)) - // actSkuMap.VendorPrice = int64(jxutils.CaculateSkuVendorPrice(jxPrice, pricePercentage)) actSkuMap.VendorPrice = int64(getVendorPriceFromStoreSkuBind(storeSkuInfo, vendorID)) v.OriginalPrice = int64(jxPrice) } @@ -166,7 +164,7 @@ func ActStoreSkuParam2Model(ctx *jxcontext.Context, db *dao.DaoDB, act *model.Ac if v.PricePercentage != 0 { percentage = v.PricePercentage } - actSkuMap.ActualActPrice = int64(jxutils.CaculateSkuVendorPrice(int(actSkuMap.VendorPrice), percentage)) + actSkuMap.ActualActPrice = int64(jxutils.CaculateSkuVendorPrice(int(actSkuMap.VendorPrice), percentage, 0)) if actSkuMap.ActualActPrice > 10 { actSkuMap.ActualActPrice = int64(math.Floor(float64(actSkuMap.ActualActPrice)/10) * 10) } diff --git a/business/jxstore/cms/store_sku.go b/business/jxstore/cms/store_sku.go index a5f9aac13..4df3422c2 100644 --- a/business/jxstore/cms/store_sku.go +++ b/business/jxstore/cms/store_sku.go @@ -1888,10 +1888,10 @@ func RefreshStoresSkuByVendor(ctx *jxcontext.Context, storeIDs []int, vendorID i } } for _, v := range storeSkuList { - pricePercentage := jxutils.GetPricePercentageByVendorPrice(storeMap[v.StoreID].PricePercentagePackObj, v.Price, int(storeMap[v.StoreID].PricePercentage)) + pricePercentage, priceAdd := jxutils.GetPricePercentageByVendorPrice(storeMap[v.StoreID].PricePercentagePackObj, v.Price, int(storeMap[v.StoreID].PricePercentage)) skuName := skuNameMap[skuMap[v.SkuID].NameID] - v.Price = jxutils.CaculateSkuPriceFromVendor(v.Price, pricePercentage) - v.UnitPrice = jxutils.CaculateSkuPriceFromVendor(skuName.Price, pricePercentage) + v.Price = jxutils.CaculateSkuPriceFromVendor(v.Price, pricePercentage, priceAdd) + v.UnitPrice = jxutils.CaculateSkuPriceFromVendor(skuName.Price, pricePercentage, priceAdd) dao.WrapAddIDCULDEntity(v, ctx.GetUserName()) setStoreSkuBindStatus(v, model.SyncFlagNewMask) v.JdSyncStatus = 0 diff --git a/business/jxstore/cms/sync_store_sku.go b/business/jxstore/cms/sync_store_sku.go index f98939ebc..cf92145b1 100644 --- a/business/jxstore/cms/sync_store_sku.go +++ b/business/jxstore/cms/sync_store_sku.go @@ -213,8 +213,8 @@ func storeSkuSyncInfo2Bare(inSku *dao.StoreSkuSyncInfo) (outSku *partner.StoreSk func calVendorPrice4StoreSku(inSku *dao.StoreSkuSyncInfo, pricePercentagePack model.PricePercentagePack, pricePercentage int) (outSku *dao.StoreSkuSyncInfo) { if inSku.VendorPrice <= 0 { // 避免重新计算 - pricePercentage = jxutils.GetPricePercentage(pricePercentagePack, int(inSku.Price), pricePercentage) - inSku.VendorPrice = int64(jxutils.CaculateSkuVendorPrice(int(inSku.Price), pricePercentage)) + pricePercentage2, priceAdd2 := jxutils.GetPricePercentage(pricePercentagePack, int(inSku.Price), pricePercentage) + inSku.VendorPrice = int64(jxutils.CaculateSkuVendorPrice(int(inSku.Price), pricePercentage2, priceAdd2)) if inSku.VendorPrice <= 0 { inSku.VendorPrice = 1 // 最少1分钱 } diff --git a/business/jxutils/jxutils_cms.go b/business/jxutils/jxutils_cms.go index f9e01d968..5c54e00e4 100644 --- a/business/jxutils/jxutils_cms.go +++ b/business/jxutils/jxutils_cms.go @@ -245,29 +245,29 @@ func CaculateUnitPrice(skuPrice int, specQuality float32, specUnit string, skuNa return unitPrice } -func CaculateSkuVendorPrice(price, percentage int) (vendorPrice int) { +func CaculateSkuVendorPrice(price, percentage, priceAdd int) (vendorPrice int) { if percentage <= 10 || percentage >= 400 { percentage = 100 } - vendorPrice = int(math.Round(float64(price*percentage) / 100)) + vendorPrice = int(math.Round(float64(price*percentage)/100)) + priceAdd if vendorPrice < 1 { vendorPrice = 1 } return vendorPrice } -func CaculateSkuPriceFromVendor(vendorPrice, percentage int) (price int) { +func CaculateSkuPriceFromVendor(vendorPrice, percentage, priceAdd int) (price int) { if percentage <= 10 || percentage >= 400 { percentage = 100 } - price = int(math.Round(float64(vendorPrice) * 100 / float64(percentage))) + price = int(math.Round(float64(vendorPrice-priceAdd) * 100 / float64(percentage))) if price < 0 { price = 0 } return price } -func GetPricePercentage(l model.PricePercentagePack, price int, defPricePercentage int) (pricePercentage int) { +func GetPricePercentage(l model.PricePercentagePack, price int, defPricePercentage int) (pricePercentage, priceAdd int) { pricePercentage = defPricePercentage if len(l) > 0 { var lastItem *model.PricePercentageItem @@ -279,26 +279,28 @@ func GetPricePercentage(l model.PricePercentagePack, price int, defPricePercenta } if lastItem != nil { pricePercentage = lastItem.PricePercentage + priceAdd = lastItem.PriceAdd } } - return pricePercentage + return pricePercentage, priceAdd } -func GetPricePercentageByVendorPrice(l model.PricePercentagePack, vendorPrice int, defPricePercentage int) (pricePercentage int) { +func GetPricePercentageByVendorPrice(l model.PricePercentagePack, vendorPrice int, defPricePercentage int) (pricePercentage, priceAdd int) { pricePercentage = defPricePercentage if len(l) > 0 { var lastItem *model.PricePercentageItem for _, v := range l { - if CaculateSkuVendorPrice(v.BeginPrice, v.PricePercentage) > vendorPrice { + if CaculateSkuVendorPrice(v.BeginPrice, v.PricePercentage, v.PriceAdd) > vendorPrice { break } lastItem = v } if lastItem != nil { pricePercentage = lastItem.PricePercentage + priceAdd = lastItem.PriceAdd } } - return pricePercentage + return pricePercentage, priceAdd } func IsSkuSpecial(specQuality float32, specUnit string) bool { diff --git a/business/model/store.go b/business/model/store.go index 2bbab4956..43541594f 100644 --- a/business/model/store.go +++ b/business/model/store.go @@ -465,6 +465,7 @@ func (v *VendorStoreSnapshot) CompareOperationTime(s2 *VendorStoreSnapshot) int type PricePercentageItem struct { BeginPrice int `json:"beginPrice"` // 起始价格区间(包括) PricePercentage int `json:"pricePercentage"` // 调价比例 + PriceAdd int `json:"priceAdd"` // 调价额定值 } type PricePercentagePack []*PricePercentageItem