fix: 折扣匹配改为精确匹配 quantity,不再取全局最小值
Build docker and publish / build (20.15.1) (push) Successful in 7m44s

将 getDiscount 和 isNewUserOnlyForQuantity 的匹配逻辑从
inputMonths >= discount.Quantity 改为 inputMonths == discount.Quantity,
买多少天就用多少天对应的折扣,避免错误配置导致折扣泄漏。
同时增加 discount 值合法性校验(>0 且 <100)。

Co-Authored-By: claude-flow <ruv@ruv.net>
This commit is contained in:
2026-03-26 04:18:45 -07:00
parent de6fbcb518
commit c431393266
3 changed files with 12 additions and 24 deletions
+3 -5
View File
@@ -7,17 +7,15 @@ import (
)
func getDiscount(discounts []types.SubscribeDiscount, inputMonths int64, isNewUser bool) float64 {
var finalDiscount float64 = 100
for _, discount := range discounts {
if discount.NewUserOnly && !isNewUser {
continue
}
if inputMonths >= discount.Quantity && discount.Discount < finalDiscount {
finalDiscount = discount.Discount
if inputMonths == discount.Quantity && discount.Discount > 0 && discount.Discount < 100 {
return discount.Discount / float64(100)
}
}
return finalDiscount / float64(100)
return 1
}
func calculateCoupon(amount int64, couponInfo *coupon.Coupon) int64 {