StoreSkuBind添加JxPrice

This commit is contained in:
gazebo
2019-11-13 15:16:11 +08:00
parent 2ca58bd582
commit 7f231d1f6a
8 changed files with 146 additions and 38 deletions

View File

@@ -245,10 +245,15 @@ func CaculateUnitPrice(skuPrice int, specQuality float32, specUnit string, skuNa
return unitPrice
}
func CaculateSkuVendorPrice(price, percentage, priceAdd int) (vendorPrice int) {
if percentage <= 10 || percentage >= 400 {
percentage = 100
func ConstrainPricePercentage(percentage int) int {
if percentage <= model.MinVendorPricePercentage || percentage >= model.MaxVendorPricePercentage {
percentage = model.DefVendorPricePercentage
}
return percentage
}
func CaculateSkuVendorPrice(price, percentage, priceAdd int) (vendorPrice int) {
percentage = ConstrainPricePercentage(percentage)
vendorPrice = int(math.Round(float64(price*percentage)/100)) + priceAdd
if vendorPrice < 1 {
vendorPrice = 1
@@ -257,9 +262,7 @@ func CaculateSkuVendorPrice(price, percentage, priceAdd int) (vendorPrice int) {
}
func CaculateSkuPriceFromVendor(vendorPrice, percentage, priceAdd int) (price int) {
if percentage <= 10 || percentage >= 400 {
percentage = 100
}
percentage = ConstrainPricePercentage(percentage)
price = int(math.Round(float64(vendorPrice-priceAdd) * 100 / float64(percentage)))
if price < 0 {
price = 0
@@ -269,18 +272,28 @@ func CaculateSkuPriceFromVendor(vendorPrice, percentage, priceAdd int) (price in
func GetPricePercentage(l model.PricePercentagePack, price int, defPricePercentage int) (pricePercentage, priceAdd int) {
pricePercentage = defPricePercentage
if len(l) > 0 {
var lastItem *model.PricePercentageItem
for _, v := range l {
if v.BeginPrice > price {
itemLen := len(l)
if itemLen > 0 {
low := 0
high := itemLen - 1
mid := 0
for low <= high {
mid = low + (high-low)/2
if mid == 0 || mid == itemLen-1 {
break
}
lastItem = v
}
if lastItem != nil {
pricePercentage = lastItem.PricePercentage
priceAdd = lastItem.PriceAdd
if price >= l[mid].BeginPrice {
if price < l[mid+1].BeginPrice {
break
} else {
low = mid + 1
}
} else {
high = mid - 1
}
}
pricePercentage = l[mid].PricePercentage
priceAdd = l[mid].PriceAdd
}
return pricePercentage, priceAdd
}
@@ -303,6 +316,11 @@ func GetPricePercentageByVendorPrice(l model.PricePercentagePack, vendorPrice in
return pricePercentage, priceAdd
}
func CaculatePriceByPricePack(l model.PricePercentagePack, defPricePercentage, price int) (outPrice int) {
pricePercentage, priceAdd := GetPricePercentage(l, price, defPricePercentage)
return CaculateSkuVendorPrice(price, pricePercentage, priceAdd)
}
func IsSkuSpecial(specQuality float32, specUnit string) bool {
return int(specQuality) == model.SpecialSpecQuality && (specUnit == model.SpecialSpecUnit || specUnit == model.SpecialSpecUnit2)
}