feat: add balance and ledger endpoints for tenant

- Implemented MyBalance and MyLedgerPage methods in the ledger service to retrieve current user balance and transaction history for a specified tenant.
- Added corresponding test cases for MyBalance and MyLedgerPage methods in the ledger test suite.
- Created DTOs for balance response and ledger items to structure the response data.
- Updated Swagger documentation to include new endpoints for retrieving tenant balance and ledgers.
- Added HTTP tests for the new endpoints to ensure proper functionality.
This commit is contained in:
2025-12-18 16:24:37 +08:00
parent 435e541dbe
commit 3249e405ac
13 changed files with 990 additions and 33 deletions

View File

@@ -0,0 +1,31 @@
package dto
import (
"time"
"quyun/v2/app/requests"
"quyun/v2/database/models"
"quyun/v2/pkg/consts"
)
// MyLedgerListFilter 定义“我的余额流水”查询条件。
type MyLedgerListFilter struct {
// Pagination 分页参数page/limit
requests.Pagination `json:",inline" query:",inline"`
// Type 按流水类型过滤(可选)。
Type *consts.TenantLedgerType `json:"type,omitempty" query:"type"`
// OrderID 按关联订单过滤(可选)。
OrderID *int64 `json:"order_id,omitempty" query:"order_id"`
// CreatedAtFrom 创建时间起(可选)。
CreatedAtFrom *time.Time `json:"created_at_from,omitempty" query:"created_at_from"`
// CreatedAtTo 创建时间止(可选)。
CreatedAtTo *time.Time `json:"created_at_to,omitempty" query:"created_at_to"`
}
// MyLedgerItem 返回一条余额流水,并补充展示字段。
type MyLedgerItem struct {
// Ledger 流水记录(租户内隔离)。
Ledger *models.TenantLedger `json:"ledger"`
// TypeDescription 流水类型中文说明(用于前端展示)。
TypeDescription string `json:"type_description"`
}

View File

@@ -0,0 +1,19 @@
package dto
import (
"time"
"quyun/v2/pkg/consts"
)
// MeBalanceResponse 返回当前用户在当前租户下的余额信息(租户内隔离)。
type MeBalanceResponse struct {
// Currency 币种:当前固定 CNY金额单位为分
Currency consts.Currency `json:"currency"`
// Balance 可用余额:可用于购买/消费。
Balance int64 `json:"balance"`
// BalanceFrozen 冻结余额:用于下单冻结/争议期等。
BalanceFrozen int64 `json:"balance_frozen"`
// UpdatedAt 更新时间:余额变更时更新。
UpdatedAt time.Time `json:"updated_at"`
}