feat(discount): change discount type to float64 for improved precision

This commit is contained in:
Tension 2025-12-28 22:04:50 +08:00
parent 495c4529ed
commit 7a2000f696
4 changed files with 8 additions and 8 deletions

View File

@ -204,8 +204,8 @@ type (
CurrencySymbol string `json:"currency_symbol"` CurrencySymbol string `json:"currency_symbol"`
} }
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"`

View File

@ -3,7 +3,7 @@ package order
import "github.com/perfect-panel/server/internal/types" import "github.com/perfect-panel/server/internal/types"
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 {
@ -11,5 +11,5 @@ func getDiscount(discounts []types.SubscribeDiscount, inputMonths int64) float64
} }
} }
return float64(finalDiscount) / float64(100) return finalDiscount / float64(100)
} }

View File

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

View File

@ -2117,8 +2117,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 {