shanshanzhong 81086eea52
Some checks failed
Build docker and publish / build (20.15.1) (push) Failing after 6m30s
fix(订单折扣): 将折扣计算从整数百分比改为浮点数
修改 SubscribeDiscount 结构体中的 Discount 字段类型为 float64,并调整 getDiscount 函数逻辑以直接使用浮点数计算
2025-10-29 20:18:05 -07:00

19 lines
580 B
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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 float64 = 1.0
for _, discount := range discounts {
if inputMonths >= discount.Quantity && discount.Discount < finalDiscount {
finalDiscount = discount.Discount
}
}
return finalDiscount
}