feat:修改收益的计算

This commit is contained in:
zerosaturation 2026-07-01 12:45:17 +08:00
parent 8d72b796fa
commit 355ac4393b

View File

@ -425,6 +425,19 @@ func CalculateBuff(likeCount int) int {
}
}
// roundHalfToEven 银行家四舍五入round half to even
// 当小数部分恰好为 0.5 时,向最近的偶数舍入,避免统计偏差
// 例如2.5 → 2, 3.5 → 4, 4.5 → 4, 5.5 → 6
func roundHalfToEven(numerator, denominator int64) int64 {
quotient := numerator / denominator
remainder := numerator % denominator
half := denominator / 2
if remainder > half || (remainder == half && quotient%2 != 0) {
quotient++
}
return quotient
}
// CalculateExhibitionRevenue 计算单次上架收益(参考实现,未被调用)
// 注意:实际收益计算在 OnExhibitionCompleted 中通过 AssetLevelService.CalculateRevenue 实现
// 此函数保留用于参考和测试场景
@ -449,9 +462,9 @@ func CalculateExhibitionRevenue(likeCount int, startTime, endTime int64, revenue
// 基础收益
baseRevenue := R0 * T
// 应用Buff加成
// 应用Buff加成(银行家四舍五入)
// R1 = R0 × T × (100% + Buff)
buffedRevenue := baseRevenue * (100 + int64(buff)) / 100
buffedRevenue := roundHalfToEven(baseRevenue*(100+int64(buff)), 100)
// 应用永久收益提升
if revenueBoostBps > 0 {