chore: seed migration objects batch 52

This commit is contained in:
dev
2026-10-18 13:38:08 +08:00
parent f440b9e0e8
commit 042fd3f826
23 changed files with 793 additions and 99 deletions
+82 -7
View File
@@ -55,6 +55,7 @@ type Repository interface {
CreateRecharge(context.Context, store.RechargeCreation) (*store.RechargeOrder, error)
RechargeOrders(context.Context, int64, int64, int, int, int) (*store.RechargePage, error)
RechargeOrder(context.Context, int64, int64, int64) (*store.RechargeOrder, error)
WalletLedgers(context.Context, int64, int64, string, int, int, int) (*store.WalletLedgerPage, error)
}
type Service struct {
@@ -209,6 +210,29 @@ type RechargePage struct {
HasNext bool `json:"has_next"`
}
type WalletLedger struct {
ID int64 `json:"id"`
LedgerNo string `json:"ledger_no"`
BizType string `json:"biz_type"`
BizNo string `json:"biz_no"`
EntryType string `json:"entry_type"`
Direction string `json:"direction"`
Amount int64 `json:"amount"`
BeforeAmount int64 `json:"before_amount"`
AfterAmount int64 `json:"after_amount"`
Currency string `json:"currency"`
Remark string `json:"remark"`
OccurredAt string `json:"occurred_at"`
}
type WalletLedgerPage struct {
Items []WalletLedger `json:"items"`
Page int `json:"page"`
PageSize int `json:"page_size"`
Total int64 `json:"total"`
HasNext bool `json:"has_next"`
}
func New(repository Repository, redisClient *redis.Client, cfg config.AuthConfig) *Service {
service := &Service{repository: repository, redis: redisClient, now: time.Now}
encryptionKey, encryptionErr := decodeKey(cfg.DataEncryptionKey)
@@ -231,7 +255,7 @@ func New(repository Repository, redisClient *redis.Client, cfg config.AuthConfig
}
func (s *Service) PaymentAccounts(ctx context.Context, tenantID, memberID int64) ([]PaymentAccount, error) {
if !s.ready {
if s.repository == nil {
return nil, ErrUnavailable
}
rows, err := s.repository.PaymentAccounts(ctx, tenantID, memberID)
@@ -368,7 +392,7 @@ func (s *Service) CreateWithdrawal(ctx context.Context, tenantID, memberID int64
}
func (s *Service) WithdrawalOrders(ctx context.Context, tenantID, memberID int64, page, pageSize int, status string) (*WithdrawalPage, error) {
if !s.ready {
if s.repository == nil {
return nil, ErrUnavailable
}
if page == 0 {
@@ -399,7 +423,7 @@ func (s *Service) WithdrawalOrders(ctx context.Context, tenantID, memberID int64
}
func (s *Service) WithdrawalOrder(ctx context.Context, tenantID, memberID, orderID int64) (*Withdrawal, error) {
if !s.ready {
if s.repository == nil {
return nil, ErrUnavailable
}
if orderID <= 0 {
@@ -414,7 +438,7 @@ func (s *Service) WithdrawalOrder(ctx context.Context, tenantID, memberID, order
}
func (s *Service) RechargeChannels(ctx context.Context, tenantID int64) ([]RechargeChannel, error) {
if !s.ready {
if s.repository == nil {
return nil, ErrUnavailable
}
rows, err := s.repository.RechargeChannels(ctx, tenantID)
@@ -432,7 +456,7 @@ func (s *Service) RechargeChannels(ctx context.Context, tenantID int64) ([]Recha
}
func (s *Service) CreateRecharge(ctx context.Context, tenantID, memberID int64, input CreateRechargeInput) (*Recharge, error) {
if !s.ready {
if s.repository == nil {
return nil, ErrUnavailable
}
input.Currency = strings.ToUpper(strings.TrimSpace(input.Currency))
@@ -495,7 +519,7 @@ func (s *Service) CreateRecharge(ctx context.Context, tenantID, memberID int64,
}
func (s *Service) RechargeOrders(ctx context.Context, tenantID, memberID int64, page, pageSize int, status string) (*RechargePage, error) {
if !s.ready {
if s.repository == nil {
return nil, ErrUnavailable
}
if page == 0 {
@@ -527,7 +551,7 @@ func (s *Service) RechargeOrders(ctx context.Context, tenantID, memberID int64,
}
func (s *Service) RechargeOrder(ctx context.Context, tenantID, memberID, orderID int64) (*Recharge, error) {
if !s.ready {
if s.repository == nil {
return nil, ErrUnavailable
}
if orderID <= 0 {
@@ -541,6 +565,57 @@ func (s *Service) RechargeOrder(ctx context.Context, tenantID, memberID, orderID
return &result, nil
}
func (s *Service) WalletLedgers(ctx context.Context, tenantID, memberID int64, page, pageSize int, bizType, direction string) (*WalletLedgerPage, error) {
if s.repository == nil {
return nil, ErrUnavailable
}
if page == 0 {
page = 1
}
if pageSize == 0 {
pageSize = defaultPageSize
}
if page < 1 {
return nil, ErrPageInvalid
}
if pageSize < 1 || pageSize > maxPageSize {
return nil, ErrPageSizeInvalid
}
bizType = strings.TrimSpace(bizType)
if len(bizType) > 32 {
return nil, ErrLedgerFilterInvalid
}
directionCode := 0
switch strings.ToLower(strings.TrimSpace(direction)) {
case "", "all":
case "income":
directionCode = 1
case "expense":
directionCode = 2
default:
return nil, ErrLedgerFilterInvalid
}
rows, err := s.repository.WalletLedgers(ctx, tenantID, memberID, bizType, directionCode, (page-1)*pageSize, pageSize)
if err != nil {
return nil, err
}
items := make([]WalletLedger, 0, len(rows.Items))
for _, row := range rows.Items {
directionName := "expense"
if row.Direction == 1 {
directionName = "income"
}
items = append(items, WalletLedger{
ID: row.ID, LedgerNo: row.LedgerNo, BizType: row.BizType, BizNo: row.BizNo,
EntryType: row.EntryType, Direction: directionName, Amount: row.Amount,
BeforeAmount: row.BeforeAmount, AfterAmount: row.AfterAmount, Currency: row.Currency,
Remark: row.Remark, OccurredAt: row.OccurredAt,
})
}
return &WalletLedgerPage{Items: items, Page: page, PageSize: pageSize, Total: rows.Total,
HasNext: int64(page*pageSize) < rows.Total}, nil
}
func (s *Service) quote(ctx context.Context, tenantID, memberID int64, input QuoteInput) (*Quote, error) {
quote, _, _, err := s.quoteData(ctx, tenantID, memberID, input)
return quote, err