Some checks failed
Build docker and publish / build (20.15.1) (push) Failing after 6m30s
修改 SubscribeDiscount 结构体中的 Discount 字段类型为 float64,并调整 getDiscount 函数逻辑以直接使用浮点数计算
19 lines
580 B
Go
19 lines
580 B
Go
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
|
||
}
|