CaculateJxPriceByPricePack

This commit is contained in:
gazebo
2020-02-07 14:20:24 +08:00
parent 1855af8757
commit fbdd8849f6
2 changed files with 64 additions and 3 deletions

View File

@@ -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

View File

@@ -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
}
}
}