From 81086eea5216bdf3ba55f83973e7657a2044035f Mon Sep 17 00:00:00 2001 From: shanshanzhong Date: Wed, 29 Oct 2025 20:18:05 -0700 Subject: [PATCH] =?UTF-8?q?fix(=E8=AE=A2=E5=8D=95=E6=8A=98=E6=89=A3):=20?= =?UTF-8?q?=E5=B0=86=E6=8A=98=E6=89=A3=E8=AE=A1=E7=AE=97=E4=BB=8E=E6=95=B4?= =?UTF-8?q?=E6=95=B0=E7=99=BE=E5=88=86=E6=AF=94=E6=94=B9=E4=B8=BA=E6=B5=AE?= =?UTF-8?q?=E7=82=B9=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 修改 SubscribeDiscount 结构体中的 Discount 字段类型为 float64,并调整 getDiscount 函数逻辑以直接使用浮点数计算 --- internal/logic/public/order/getDiscount.go | 7 +++++-- internal/types/types.go | 4 ++-- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/internal/logic/public/order/getDiscount.go b/internal/logic/public/order/getDiscount.go index 34c16a9..d6bfe6e 100644 --- a/internal/logic/public/order/getDiscount.go +++ b/internal/logic/public/order/getDiscount.go @@ -2,8 +2,11 @@ package order import "github.com/perfect-panel/server/internal/types" +// getDiscount 计算最终价格倍数 +// 参数:discounts 折扣规则列表(数量阈值 + 折扣倍数);inputMonths 购买时长 +// 返回:最终价格倍数(如 0.95 表示按 95% 计价) func getDiscount(discounts []types.SubscribeDiscount, inputMonths int64) float64 { - var finalDiscount int64 = 100 + var finalDiscount float64 = 1.0 for _, discount := range discounts { if inputMonths >= discount.Quantity && discount.Discount < finalDiscount { @@ -11,5 +14,5 @@ func getDiscount(discounts []types.SubscribeDiscount, inputMonths int64) float64 } } - return float64(finalDiscount) / float64(100) + return finalDiscount } diff --git a/internal/types/types.go b/internal/types/types.go index ffe5161..9970643 100644 --- a/internal/types/types.go +++ b/internal/types/types.go @@ -2084,8 +2084,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 {