fix(订单折扣): 将折扣计算从整数百分比改为浮点数
Some checks failed
Build docker and publish / build (20.15.1) (push) Failing after 6m30s
Some checks failed
Build docker and publish / build (20.15.1) (push) Failing after 6m30s
修改 SubscribeDiscount 结构体中的 Discount 字段类型为 float64,并调整 getDiscount 函数逻辑以直接使用浮点数计算
This commit is contained in:
parent
1302accaf9
commit
81086eea52
@ -2,8 +2,11 @@ package order
|
|||||||
|
|
||||||
import "github.com/perfect-panel/server/internal/types"
|
import "github.com/perfect-panel/server/internal/types"
|
||||||
|
|
||||||
|
// getDiscount 计算最终价格倍数
|
||||||
|
// 参数:discounts 折扣规则列表(数量阈值 + 折扣倍数);inputMonths 购买时长
|
||||||
|
// 返回:最终价格倍数(如 0.95 表示按 95% 计价)
|
||||||
func getDiscount(discounts []types.SubscribeDiscount, inputMonths int64) float64 {
|
func getDiscount(discounts []types.SubscribeDiscount, inputMonths int64) float64 {
|
||||||
var finalDiscount int64 = 100
|
var finalDiscount float64 = 1.0
|
||||||
|
|
||||||
for _, discount := range discounts {
|
for _, discount := range discounts {
|
||||||
if inputMonths >= discount.Quantity && discount.Discount < finalDiscount {
|
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
|
||||||
}
|
}
|
||||||
|
|||||||
@ -2084,8 +2084,8 @@ type SubscribeConfig struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type SubscribeDiscount struct {
|
type SubscribeDiscount struct {
|
||||||
Quantity int64 `json:"quantity"`
|
Quantity int64 `json:"quantity"`
|
||||||
Discount int64 `json:"discount"`
|
Discount float64 `json:"discount"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type SubscribeGroup struct {
|
type SubscribeGroup struct {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user