update: Added support for floating-point calculations for discounts
This commit is contained in:
parent
ff2d3f85f3
commit
c1efb23354
@ -207,7 +207,7 @@ type (
|
|||||||
}
|
}
|
||||||
SubscribeDiscount {
|
SubscribeDiscount {
|
||||||
Quantity int64 `json:"quantity"`
|
Quantity int64 `json:"quantity"`
|
||||||
Discount int64 `json:"discount"`
|
Discount float64 `json:"discount"`
|
||||||
}
|
}
|
||||||
Subscribe {
|
Subscribe {
|
||||||
Id int64 `json:"id"`
|
Id int64 `json:"id"`
|
||||||
|
|||||||
@ -7,14 +7,14 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func getDiscount(discounts []types.SubscribeDiscount, inputMonths int64) float64 {
|
func getDiscount(discounts []types.SubscribeDiscount, inputMonths int64) float64 {
|
||||||
var finalDiscount int64 = 100
|
var finalDiscount float64 = 100
|
||||||
|
|
||||||
for _, discount := range discounts {
|
for _, discount := range discounts {
|
||||||
if inputMonths >= discount.Quantity && discount.Discount < finalDiscount {
|
if inputMonths >= discount.Quantity && discount.Discount < finalDiscount {
|
||||||
finalDiscount = discount.Discount
|
finalDiscount = discount.Discount
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return float64(finalDiscount) / float64(100)
|
return finalDiscount / float64(100)
|
||||||
}
|
}
|
||||||
|
|
||||||
func calculateCoupon(amount int64, couponInfo *coupon.Coupon) int64 {
|
func calculateCoupon(amount int64, couponInfo *coupon.Coupon) int64 {
|
||||||
|
|||||||
@ -2076,8 +2076,8 @@ type SubscribeConfig struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type SubscribeDiscount struct {
|
type SubscribeDiscount struct {
|
||||||
Quantity int64 `json:"quantity"`
|
Quantity int64 `json:"quantity"`
|
||||||
Discount int64 `json:"discount"`
|
Discount float64 `json:"discount"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type SubscribeGroup struct {
|
type SubscribeGroup struct {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user