package employeecollection import ( "github.com/break/junhong_cmp_fiber/pkg/constants" "github.com/break/junhong_cmp_fiber/pkg/errors" ) // RefundOffsetDecision 是来源订单退款成功对账单的处理判定结果。 type RefundOffsetDecision struct { // Outcome 取值见 constants.EmployeeCollectionRefundOutcome*。 Outcome string // ReducedAmount 是本次实际冲减的应收金额(分),仅 reduced 时大于零。 ReducedAmount int64 } // DecideRefundOffset 判定来源订单本次退款成功金额对账单的处理方式。 // 判定顺序:已关闭账单与存在已通过或审批中分摊的账单只写退款关联提示, // 其余按退款成功金额与账单应收比较,等于或超过应收时关闭账单,小于应收时按退款金额冲减。 // 已通过分摊体现为 received_amount > 0,审批中分摊体现为 reserved_amount > 0; // 这两个金额只由本能力的条件更新维护,因此与「存在已通过或审批中分摊」等价。 func DecideRefundOffset(bill BillAmounts, refundAmount int64) (RefundOffsetDecision, error) { if refundAmount <= 0 { return RefundOffsetDecision{}, errors.New(errors.CodeInvalidParam, "退款成功金额必须大于零") } if err := bill.Validate(); err != nil { return RefundOffsetDecision{}, err } if bill.Closed || bill.Received > 0 || bill.Reserved > 0 { return RefundOffsetDecision{Outcome: constants.EmployeeCollectionRefundOutcomeHintOnly}, nil } if refundAmount >= bill.Receivable { return RefundOffsetDecision{Outcome: constants.EmployeeCollectionRefundOutcomeClosedFull}, nil } return RefundOffsetDecision{ Outcome: constants.EmployeeCollectionRefundOutcomeReduced, ReducedAmount: refundAmount, }, nil }