fix: pass operator id to audit logs

This commit is contained in:
2026-01-13 11:21:35 +08:00
parent 84c8d1b394
commit 4e35dff05c
3 changed files with 17 additions and 8 deletions

View File

@@ -1780,7 +1780,10 @@ func (s *super) ListWithdrawals(ctx context.Context, filter *super_dto.SuperOrde
}, nil
}
func (s *super) ApproveWithdrawal(ctx context.Context, id int64) error {
func (s *super) ApproveWithdrawal(ctx context.Context, operatorID, id int64) error {
if operatorID == 0 {
return errorx.ErrUnauthorized.WithMsg("缺少操作者信息")
}
o, err := models.OrderQuery.WithContext(ctx).Where(models.OrderQuery.ID.Eq(id)).First()
if err != nil {
return errorx.ErrRecordNotFound
@@ -1796,7 +1799,7 @@ func (s *super) ApproveWithdrawal(ctx context.Context, id int64) error {
UpdatedAt: time.Now(),
})
if err == nil && Audit != nil {
Audit.Log(ctx, 0, "approve_withdrawal", cast.ToString(id), "Approved withdrawal")
Audit.Log(ctx, operatorID, "approve_withdrawal", cast.ToString(id), "Approved withdrawal")
}
return err
}
@@ -1956,7 +1959,10 @@ func (s *super) formatTime(t time.Time) string {
return t.Format(time.RFC3339)
}
func (s *super) RejectWithdrawal(ctx context.Context, id int64, reason string) error {
func (s *super) RejectWithdrawal(ctx context.Context, operatorID, id int64, reason string) error {
if operatorID == 0 {
return errorx.ErrUnauthorized.WithMsg("缺少操作者信息")
}
err := models.Q.Transaction(func(tx *models.Query) error {
o, err := tx.Order.WithContext(ctx).Where(tx.Order.ID.Eq(id)).First()
if err != nil {
@@ -1990,7 +1996,7 @@ func (s *super) RejectWithdrawal(ctx context.Context, id int64, reason string) e
Type: consts.TenantLedgerTypeAdjustment,
Amount: o.AmountPaid,
Remark: "提现拒绝返还: " + reason,
OperatorUserID: 0, // System/Admin
OperatorUserID: operatorID,
IdempotencyKey: uuid.NewString(),
}
if err := tx.TenantLedger.WithContext(ctx).Create(ledger); err != nil {
@@ -2001,7 +2007,7 @@ func (s *super) RejectWithdrawal(ctx context.Context, id int64, reason string) e
})
if err == nil && Audit != nil {
Audit.Log(ctx, 0, "reject_withdrawal", cast.ToString(id), "Rejected: "+reason)
Audit.Log(ctx, operatorID, "reject_withdrawal", cast.ToString(id), "Rejected: "+reason)
}
return err
}