fix: getDiscount 新人取折扣最大档,非新人取折扣最小档
Some checks failed
Build docker and publish / build (20.15.1) (push) Failing after 7m31s
Some checks failed
Build docker and publish / build (20.15.1) (push) Failing after 7m31s
- 新人:所有匹配 quantity 的条目中取 discount 值最小的(折扣力度最大) - 非新人:所有匹配 quantity 的条目中取 discount 值最大的(折扣力度最小,接近原价) - 不再按 new_user_only 过滤,由 isNewUserOnlyForQuantity 在上层控制准入 Co-Authored-By: claude-flow <ruv@ruv.net>
This commit is contained in:
parent
c8f172dc0e
commit
e51dbea7c7
@ -4,25 +4,21 @@ import "github.com/perfect-panel/server/internal/types"
|
|||||||
|
|
||||||
// getDiscount returns the discount factor for the given quantity.
|
// getDiscount returns the discount factor for the given quantity.
|
||||||
//
|
//
|
||||||
// - New user: pick the tier with the lowest discount value (best deal) among all matching tiers.
|
// - New user: pick the tier with the lowest discount value (biggest saving).
|
||||||
// - Non-new user: pick the tier with the highest discount value (most expensive / least discount)
|
// - Non-new user: pick the tier with the highest discount value (least saving / closest to full price).
|
||||||
// among tiers where new_user_only=false only.
|
|
||||||
func getDiscount(discounts []types.SubscribeDiscount, inputMonths int64, isNewUser bool) float64 {
|
func getDiscount(discounts []types.SubscribeDiscount, inputMonths int64, isNewUser bool) float64 {
|
||||||
best := float64(-1)
|
best := float64(-1)
|
||||||
for _, d := range discounts {
|
for _, d := range discounts {
|
||||||
if d.Quantity != inputMonths || d.Discount <= 0 || d.Discount >= 100 {
|
if d.Quantity != inputMonths || d.Discount <= 0 || d.Discount >= 100 {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if !isNewUser && d.NewUserOnly {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
if isNewUser {
|
if isNewUser {
|
||||||
// lowest discount value = biggest saving
|
// lowest discount value = biggest saving
|
||||||
if best < 0 || d.Discount < best {
|
if best < 0 || d.Discount < best {
|
||||||
best = d.Discount
|
best = d.Discount
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// highest discount value = least discount (closest to original price)
|
// highest discount value = least saving (closest to original price)
|
||||||
if best < 0 || d.Discount > best {
|
if best < 0 || d.Discount > best {
|
||||||
best = d.Discount
|
best = d.Discount
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user