update: Added support for floating-point calculations for discounts

This commit is contained in:
EUForest 2025-11-21 17:39:57 +08:00
parent ff2d3f85f3
commit c1efb23354
3 changed files with 5 additions and 5 deletions

View File

@ -207,7 +207,7 @@ type (
}
SubscribeDiscount {
Quantity int64 `json:"quantity"`
Discount int64 `json:"discount"`
Discount float64 `json:"discount"`
}
Subscribe {
Id int64 `json:"id"`

View File

@ -7,14 +7,14 @@ import (
)
func getDiscount(discounts []types.SubscribeDiscount, inputMonths int64) float64 {
var finalDiscount int64 = 100
var finalDiscount float64 = 100
for _, discount := range discounts {
if inputMonths >= discount.Quantity && discount.Discount < finalDiscount {
finalDiscount = discount.Discount
}
}
return float64(finalDiscount) / float64(100)
return finalDiscount / float64(100)
}
func calculateCoupon(amount int64, couponInfo *coupon.Coupon) int64 {

View File

@ -2076,8 +2076,8 @@ type SubscribeConfig struct {
}
type SubscribeDiscount struct {
Quantity int64 `json:"quantity"`
Discount int64 `json:"discount"`
Quantity int64 `json:"quantity"`
Discount float64 `json:"discount"`
}
type SubscribeGroup struct {