feat: 支持 0 元退款(仅作废权益不退钱)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
邹进
2026-10-22 11:17:29 +09:00
parent 44a05cf687
commit 1ffc923b94
5 changed files with 60 additions and 15 deletions

View File

@@ -41,9 +41,13 @@ func (s *RefundOffsetService) ApplyInTx(ctx context.Context, tx *gorm.DB, source
if s == nil || tx == nil || s.audit == nil {
return errors.New(errors.CodeInternalError, "员工代收款退款冲销能力未配置")
}
if source.RefundID == 0 || source.OrderID == 0 || source.RefundAmount <= 0 {
if source.RefundID == 0 || source.OrderID == 0 || source.RefundAmount < 0 {
return errors.New(errors.CodeInvalidParam, "员工代收款退款冲销参数无效")
}
// 0 元退款只作废权益、不退钱:不冲减、不关闭账单、不写冲销记录,也不能让退款事务失败。
if source.RefundAmount == 0 {
return nil
}
var bill model.EmployeeCollectionBill
if err := tx.WithContext(ctx).Clauses(clause.Locking{Strength: "UPDATE"}).
Where("source_key = ?", employeecollectiondomain.OrderSourceKey(source.OrderID)).