feat: add withdrawal snapshot for review

This commit is contained in:
2026-01-16 07:38:30 +08:00
parent b3fc226bbe
commit f7db11a4df
6 changed files with 86 additions and 7 deletions

View File

@@ -2,6 +2,7 @@ package services
import (
"context"
"encoding/json"
"errors"
"strconv"
"time"
@@ -939,13 +940,26 @@ func (s *creator) Withdraw(ctx context.Context, tenantID, userID int64, form *cr
}
// Validate Payout Account
_, err = models.PayoutAccountQuery.WithContext(ctx).
account, err := models.PayoutAccountQuery.WithContext(ctx).
Where(models.PayoutAccountQuery.ID.Eq(form.AccountID), models.PayoutAccountQuery.TenantID.Eq(tid)).
First()
if err != nil {
return errorx.ErrRecordNotFound.WithMsg("收款账户不存在")
}
// 将收款账户快照写入订单,便于超管审核与打款核对。
snapshotPayload, err := json.Marshal(fields.OrdersWithdrawalSnapshot{
Method: form.Method,
AccountID: account.ID,
AccountType: account.Type,
AccountName: account.Name,
Account: account.Account,
AccountRealname: account.Realname,
})
if err != nil {
return errorx.ErrInternalError.WithCause(err).WithMsg("构建提现快照失败")
}
return models.Q.Transaction(func(tx *models.Query) error {
// 1. Deduct Balance
info, err := tx.User.WithContext(ctx).
@@ -968,7 +982,10 @@ func (s *creator) Withdraw(ctx context.Context, tenantID, userID int64, form *cr
AmountOriginal: amount,
AmountPaid: amount, // Actually Amount Withdrawn
IdempotencyKey: uuid.NewString(),
Snapshot: types.NewJSONType(fields.OrdersSnapshot{}), // Can store account details here
Snapshot: types.NewJSONType(fields.OrdersSnapshot{
Kind: "withdrawal",
Data: snapshotPayload,
}),
}
if err := tx.Order.WithContext(ctx).Create(order); err != nil {
return err