退款纠纷分配
This commit is contained in:
@@ -5,6 +5,7 @@ import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"log"
|
||||
"math"
|
||||
"time"
|
||||
|
||||
"hfb_sys/backend/internal/listingstatus"
|
||||
@@ -246,7 +247,11 @@ func buildArbitrationSettlement(order model.RentalOrder, req ArbitrateRequest, r
|
||||
addRenterRefund(req.AmountCent, "仲裁部分退款")
|
||||
// 部分退款为合并金额,无法精确拆分租金/押金,按押金优先归类以便暂扣。
|
||||
settlement.RenterDepositRefundCent = money.MinCent(req.AmountCent, depositAmountCent)
|
||||
addOwnerIncome(money.MinCent(totalCent-req.AmountCent, ownerRentAmountCent+depositAmountCent), "仲裁剩余金额结算给号主")
|
||||
// 号主仅拿「未退租金中的号主份额 + 未退押金」,平台加价按未退租金比例预留,避免整笔剩余进号主。
|
||||
addOwnerIncome(
|
||||
partialRefundOwnerIncomeCent(rentAmountCent, ownerRentAmountCent, depositAmountCent, req.AmountCent),
|
||||
"仲裁剩余金额结算给号主",
|
||||
)
|
||||
case "release_deposit":
|
||||
addOwnerIncome(ownerRentAmountCent, "仲裁确认订单金额结算给号主")
|
||||
addRenterRefund(depositAmountCent, "仲裁释放押金给租客")
|
||||
@@ -273,6 +278,66 @@ func buildArbitrationSettlement(order model.RentalOrder, req ArbitrateRequest, r
|
||||
return settlement, nil
|
||||
}
|
||||
|
||||
// partialRefundOwnerIncomeCent 计算部分退款后号主应得。
|
||||
// 退款优先冲押金,其余冲租金;未退租金按预收结构拆分:
|
||||
// 平台费 = 租客租金 − 号主租金,并按 未退租金/预收租金 比例预留,剩余才归号主。
|
||||
// 这样可避免「剩余金额整笔给号主」把平台加价分给用户。
|
||||
func partialRefundOwnerIncomeCent(rentAmountCent, ownerRentAmountCent, depositAmountCent, renterRefundCent int64) int64 {
|
||||
if renterRefundCent < 0 {
|
||||
renterRefundCent = 0
|
||||
}
|
||||
totalCent := rentAmountCent + depositAmountCent
|
||||
if renterRefundCent > totalCent {
|
||||
renterRefundCent = totalCent
|
||||
}
|
||||
if ownerRentAmountCent < 0 {
|
||||
ownerRentAmountCent = 0
|
||||
}
|
||||
if ownerRentAmountCent > rentAmountCent {
|
||||
ownerRentAmountCent = rentAmountCent
|
||||
}
|
||||
|
||||
// 退款优先视为押金退还,其余视为租金退还(与 RenterDepositRefundCent 归类一致)
|
||||
depositRefunded := money.MinCent(renterRefundCent, depositAmountCent)
|
||||
rentRefunded := renterRefundCent - depositRefunded
|
||||
rentLeft := rentAmountCent - rentRefunded
|
||||
if rentLeft < 0 {
|
||||
rentLeft = 0
|
||||
}
|
||||
depositLeft := depositAmountCent - depositRefunded
|
||||
|
||||
platformFeeCent := rentAmountCent - ownerRentAmountCent
|
||||
if platformFeeCent < 0 {
|
||||
platformFeeCent = 0
|
||||
}
|
||||
|
||||
// 按未退租金占比预留平台费
|
||||
platformKeepCent := int64(0)
|
||||
if rentAmountCent > 0 && rentLeft > 0 && platformFeeCent > 0 {
|
||||
platformKeepCent = int64(math.Round(float64(platformFeeCent) * float64(rentLeft) / float64(rentAmountCent)))
|
||||
platformKeepCent = money.MinCent(platformKeepCent, rentLeft)
|
||||
platformKeepCent = money.MinCent(platformKeepCent, platformFeeCent)
|
||||
}
|
||||
|
||||
ownerFromRent := rentLeft - platformKeepCent
|
||||
if ownerFromRent > ownerRentAmountCent {
|
||||
ownerFromRent = ownerRentAmountCent
|
||||
}
|
||||
if ownerFromRent < 0 {
|
||||
ownerFromRent = 0
|
||||
}
|
||||
|
||||
ownerIncome := ownerFromRent + depositLeft
|
||||
remaining := totalCent - renterRefundCent
|
||||
if ownerIncome > remaining {
|
||||
ownerIncome = remaining
|
||||
}
|
||||
if ownerIncome < 0 {
|
||||
return 0
|
||||
}
|
||||
return ownerIncome
|
||||
}
|
||||
|
||||
func (r *Repository) prepareRefund(order *model.RentalOrder, amountCent int64, bizType string, remark string) (*refundAction, error) {
|
||||
if amountCent <= 0 {
|
||||
return nil, nil
|
||||
|
||||
Reference in New Issue
Block a user