fix(订单折扣): 将折扣计算从整数百分比改为浮点数
Some checks failed
Build docker and publish / build (20.15.1) (push) Failing after 6m30s

修改 SubscribeDiscount 结构体中的 Discount 字段类型为 float64,并调整 getDiscount 函数逻辑以直接使用浮点数计算
This commit is contained in:
shanshanzhong 2025-10-29 20:18:05 -07:00
parent 1302accaf9
commit 81086eea52
2 changed files with 7 additions and 4 deletions

View File

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

View File

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