Files
hfb_sys/backend/internal/modules/wallet/service.go
T
2026-06-10 02:12:02 +08:00

63 lines
1.7 KiB
Go

package wallet
import (
"context"
"errors"
)
var (
ErrDependencyUnavailable = errors.New("dependency unavailable")
ErrInvalidAmount = errors.New("invalid amount")
ErrInsufficientBalance = errors.New("insufficient balance")
ErrFeaturePending = errors.New("feature pending")
ErrRechargeDisabled = errors.New("wallet recharge disabled")
)
// MinRechargeAmountCent 最小充值金额:1分
const MinRechargeAmountCent = 1
type Service struct {
repo *Repository
}
func NewService(repo *Repository) *Service {
return &Service{repo: repo}
}
func (s *Service) Account(ctx context.Context, userID uint64) (*AccountDTO, error) {
if s.repo == nil {
return nil, ErrDependencyUnavailable
}
return s.repo.Account(ctx, userID)
}
func (s *Service) Ledger(ctx context.Context, userID uint64, page, pageSize int) (*PaginatedResult, error) {
if s.repo == nil {
return nil, ErrDependencyUnavailable
}
return s.repo.Ledger(ctx, userID, page, pageSize)
}
func (s *Service) Recharge(ctx context.Context, userID uint64, req RechargeRequest) (*AccountDTO, error) {
if s.repo == nil {
return nil, ErrDependencyUnavailable
}
return nil, ErrRechargeDisabled
}
func (s *Service) Withdraw(ctx context.Context, userID uint64, req WithdrawRequest) (*AccountDTO, error) {
if s.repo == nil {
return nil, ErrDependencyUnavailable
}
// 提现功能已迁移到 withdrawal 模块
// 用户应通过 /api/withdrawals 接口提交提现申请
return nil, ErrFeaturePending
}
func (s *Service) AdminLedger(ctx context.Context, query AdminLedgerQuery) (*PaginatedResult, error) {
if s.repo == nil {
return nil, ErrDependencyUnavailable
}
return s.repo.AdminLedger(ctx, query)
}