diff --git a/business/jxutils/jxutils_cms.go b/business/jxutils/jxutils_cms.go index 110bdd1fe..774fe54a3 100644 --- a/business/jxutils/jxutils_cms.go +++ b/business/jxutils/jxutils_cms.go @@ -253,7 +253,7 @@ func CaculateUnitPrice(skuPrice int, specQuality float32, specUnit string, skuNa } func ConstrainPricePercentage(percentage int) int { - if percentage <= model.MinVendorPricePercentage || percentage >= model.MaxVendorPricePercentage { + if percentage < model.MinVendorPricePercentage || percentage > model.MaxVendorPricePercentage { percentage = model.DefVendorPricePercentage } return percentage @@ -271,8 +271,8 @@ func CaculateSkuVendorPrice(price, percentage, priceAdd int) (vendorPrice int) { func CaculateSkuPriceFromVendor(vendorPrice, percentage, priceAdd int) (price int) { percentage = ConstrainPricePercentage(percentage) price = int(math.Round(float64(vendorPrice-priceAdd) * 100 / float64(percentage))) - if price < 0 { - price = 0 + if price < 1 { + price = 1 } return price } @@ -330,6 +330,12 @@ func CaculatePriceByPricePack(l model.PricePercentagePack, defPricePercentage, p return CaculateSkuVendorPrice(price, pricePercentage, priceAdd) } +func CaculateJxPriceByPricePack(l model.PricePercentagePack, defPricePercentage, vendorPrice int) (jxPrice int) { + pricePercentage, priceAdd := GetPricePercentageByVendorPrice(l, vendorPrice, defPricePercentage) + jxPrice = CaculateSkuPriceFromVendor(vendorPrice, pricePercentage, priceAdd) + return jxPrice +} + func ConstrainPayPercentage(payPerCentage int) int { if payPerCentage <= 50 { payPerCentage = 70 diff --git a/business/jxutils/jxutils_cms_test.go b/business/jxutils/jxutils_cms_test.go index 864bdd23c..fe078858e 100644 --- a/business/jxutils/jxutils_cms_test.go +++ b/business/jxutils/jxutils_cms_test.go @@ -214,5 +214,60 @@ func TestGetPricePercentage(t *testing.T) { t.Errorf("price:%d, defPricePercentage:%d, expected pricePercentage:%d, priceAdd:%d, actual pricePercentage:%d, priceAdd:%d", v[2], v[3], v[0], v[1], pricePercentage, priceAdd) } + t.Logf("%d %d,%d,%d\n", CaculateSkuVendorPrice(v[2], pricePercentage, priceAdd), v[2], pricePercentage, priceAdd) + } +} + +func TestCaculateJxPriceByPricePack(t *testing.T) { + type tTestInfo struct { + DesiredPrice int + UnitPrice int + SpecQuality float32 + SpecUnit string + Unit string + } + + l := []*model.PricePercentageItem{ + &model.PricePercentageItem{ + BeginPrice: 0, + PricePercentage: 0, + PriceAdd: 0, + }, + &model.PricePercentageItem{ + BeginPrice: 10, + PricePercentage: 10, + PriceAdd: 1, + }, + &model.PricePercentageItem{ + BeginPrice: 20, + PricePercentage: 20, + PriceAdd: 2, + }, + &model.PricePercentageItem{ + BeginPrice: 30, + PricePercentage: 30, + PriceAdd: 3, + }, + &model.PricePercentageItem{ + BeginPrice: 60, + PricePercentage: 60, + PriceAdd: 6, + }, + } + + for _, v := range [][]int{ + []int{1, 1, 88}, + []int{1, 1, 0}, + []int{40, 15, 0}, + []int{25, 7, 0}, + []int{10, 2, 0}, + []int{60, 42, 0}, + []int{1000, 606, 10}, + } { + jxPrice := CaculateJxPriceByPricePack(l, v[2], v[1]) + if CaculatePriceByPricePack(l, v[2], jxPrice) != v[1] { + t.Fatalf("vendorPrice:%d, defPercentage:%d, expected:%d, actual:%d", v[1], v[2], v[0], jxPrice) + break + } } }