All checks were successful
构建并部署到测试环境(无 SSH) / build-and-deploy (push) Successful in 9m20s
- 新增 6 张表与成对迁移 000212,扩展企业微信审批场景业务类型白名单 - 后台线下套餐订单与两条代理线下充值入账路径在来源成功事务内建账,来源唯一键幂等 - 核销申请、审批尝试记录、账单分摊预占与驳回重提,审批业务类型 employee_collection_approval - 企业微信终态消费幂等:通过转已核销、驳回释放预占、通过后撤销不回滚并转异常终态 - 退款成功事务内按 bill_id+refund_id 幂等冲销账单或仅写退款关联提示 - 线下收款方式字典、账单查询/统计/关闭、申请查询与代办权限,均写入事务内审计 OpenSpec Change: add-employee-collection-bills
38 lines
1.7 KiB
Go
38 lines
1.7 KiB
Go
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
|
||
}
|