feat: 实现平台抽成、提现审批、异步任务集成及安全审计功能

This commit is contained in:
2025-12-30 14:54:19 +08:00
parent 5e8dbec806
commit ee1acae3ed
25 changed files with 985 additions and 60 deletions

View File

@@ -98,3 +98,66 @@ func (s *SuperTestSuite) Test_CreateTenant() {
})
})
}
func (s *SuperTestSuite) Test_WithdrawalApproval() {
Convey("Withdrawal Approval", s.T(), func() {
ctx := s.T().Context()
database.Truncate(ctx, s.DB, models.TableNameOrder, models.TableNameUser, models.TableNameTenantLedger)
u := &models.User{Username: "user_w", Balance: 1000} // Initial 10.00
models.UserQuery.WithContext(ctx).Create(u)
// Create Withdrawal Order (Pending)
o1 := &models.Order{
UserID: u.ID,
Type: consts.OrderTypeWithdrawal,
Status: consts.OrderStatusCreated,
AmountPaid: 500,
}
models.OrderQuery.WithContext(ctx).Create(o1)
Convey("should list withdrawals", func() {
filter := &super_dto.SuperOrderListFilter{Pagination: requests.Pagination{Page: 1, Limit: 10}}
res, err := Super.ListWithdrawals(ctx, filter)
So(err, ShouldBeNil)
So(res.Total, ShouldEqual, 1)
})
Convey("should approve withdrawal", func() {
err := Super.ApproveWithdrawal(ctx, o1.ID)
So(err, ShouldBeNil)
oReload, _ := models.OrderQuery.WithContext(ctx).Where(models.OrderQuery.ID.Eq(o1.ID)).First()
So(oReload.Status, ShouldEqual, consts.OrderStatusPaid)
})
Convey("should reject withdrawal and refund", func() {
// Another order
o2 := &models.Order{
UserID: u.ID,
Type: consts.OrderTypeWithdrawal,
Status: consts.OrderStatusCreated,
AmountPaid: 200,
}
models.OrderQuery.WithContext(ctx).Create(o2)
// Assuming user balance was deducted when o2 was created (logic in creator service)
// But here we set balance manually to 1000. Let's assume it was 1200 before.
// Current balance 1000. Refund 200 -> Expect 1200.
err := Super.RejectWithdrawal(ctx, o2.ID, "Invalid account")
So(err, ShouldBeNil)
oReload, _ := models.OrderQuery.WithContext(ctx).Where(models.OrderQuery.ID.Eq(o2.ID)).First()
So(oReload.Status, ShouldEqual, consts.OrderStatusFailed)
uReload, _ := models.UserQuery.WithContext(ctx).Where(models.UserQuery.ID.Eq(u.ID)).First()
So(uReload.Balance, ShouldEqual, 1200)
// Check Ledger
l, _ := models.TenantLedgerQuery.WithContext(ctx).Where(models.TenantLedgerQuery.OrderID.Eq(o2.ID)).First()
So(l, ShouldNotBeNil)
So(l.Type, ShouldEqual, consts.TenantLedgerTypeAdjustment)
})
})
}