v0.1
This commit is contained in:
@@ -0,0 +1,20 @@
|
||||
package repositories
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"tyapi-server/internal/domains/finance/entities"
|
||||
)
|
||||
|
||||
// AlipayOrderRepository 支付宝订单仓储接口
|
||||
type AlipayOrderRepository interface {
|
||||
Create(ctx context.Context, order entities.AlipayOrder) (entities.AlipayOrder, error)
|
||||
GetByID(ctx context.Context, id string) (entities.AlipayOrder, error)
|
||||
GetByOutTradeNo(ctx context.Context, outTradeNo string) (*entities.AlipayOrder, error)
|
||||
GetByRechargeID(ctx context.Context, rechargeID string) (*entities.AlipayOrder, error)
|
||||
GetByUserID(ctx context.Context, userID string) ([]entities.AlipayOrder, error)
|
||||
Update(ctx context.Context, order entities.AlipayOrder) error
|
||||
UpdateStatus(ctx context.Context, id string, status entities.AlipayOrderStatus) error
|
||||
Delete(ctx context.Context, id string) error
|
||||
Exists(ctx context.Context, id string) (bool, error)
|
||||
}
|
||||
@@ -1,57 +0,0 @@
|
||||
package repositories
|
||||
|
||||
import (
|
||||
"context"
|
||||
"tyapi-server/internal/domains/finance/entities"
|
||||
"tyapi-server/internal/domains/finance/repositories/queries"
|
||||
"tyapi-server/internal/shared/interfaces"
|
||||
)
|
||||
|
||||
// FinanceStats 财务统计信息
|
||||
type FinanceStats struct {
|
||||
TotalWallets int64
|
||||
ActiveWallets int64
|
||||
TotalBalance string
|
||||
TodayTransactions int64
|
||||
}
|
||||
|
||||
// WalletRepository 钱包仓储接口
|
||||
type WalletRepository interface {
|
||||
interfaces.Repository[entities.Wallet]
|
||||
|
||||
// 基础查询 - 直接使用实体
|
||||
GetByUserID(ctx context.Context, userID string) (*entities.Wallet, error)
|
||||
GetByWalletAddress(ctx context.Context, walletAddress string) (*entities.Wallet, error)
|
||||
GetByWalletType(ctx context.Context, userID string, walletType string) (*entities.Wallet, error)
|
||||
|
||||
// 复杂查询 - 使用查询参数
|
||||
ListWallets(ctx context.Context, query *queries.ListWalletsQuery) ([]*entities.Wallet, int64, error)
|
||||
|
||||
// 业务操作
|
||||
UpdateBalance(ctx context.Context, walletID string, balance string) error
|
||||
AddBalance(ctx context.Context, walletID string, amount string) error
|
||||
SubtractBalance(ctx context.Context, walletID string, amount string) error
|
||||
ActivateWallet(ctx context.Context, walletID string) error
|
||||
DeactivateWallet(ctx context.Context, walletID string) error
|
||||
|
||||
// 统计信息
|
||||
GetStats(ctx context.Context) (*FinanceStats, error)
|
||||
GetUserWalletStats(ctx context.Context, userID string) (*FinanceStats, error)
|
||||
}
|
||||
|
||||
// UserSecretsRepository 用户密钥仓储接口
|
||||
type UserSecretsRepository interface {
|
||||
interfaces.Repository[entities.UserSecrets]
|
||||
|
||||
// 基础查询 - 直接使用实体
|
||||
GetByUserID(ctx context.Context, userID string) (*entities.UserSecrets, error)
|
||||
GetBySecretType(ctx context.Context, userID string, secretType string) (*entities.UserSecrets, error)
|
||||
|
||||
// 复杂查询 - 使用查询参数
|
||||
ListUserSecrets(ctx context.Context, query *queries.ListUserSecretsQuery) ([]*entities.UserSecrets, int64, error)
|
||||
|
||||
// 业务操作
|
||||
UpdateSecret(ctx context.Context, userID string, secretType string, secretValue string) error
|
||||
DeleteSecret(ctx context.Context, userID string, secretType string) error
|
||||
ValidateSecret(ctx context.Context, userID string, secretType string, secretValue string) (bool, error)
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
package repositories
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"tyapi-server/internal/domains/finance/entities"
|
||||
"tyapi-server/internal/shared/interfaces"
|
||||
)
|
||||
|
||||
// RechargeRecordRepository 充值记录仓储接口
|
||||
type RechargeRecordRepository interface {
|
||||
Create(ctx context.Context, record entities.RechargeRecord) (entities.RechargeRecord, error)
|
||||
GetByID(ctx context.Context, id string) (entities.RechargeRecord, error)
|
||||
GetByUserID(ctx context.Context, userID string) ([]entities.RechargeRecord, error)
|
||||
GetByAlipayOrderID(ctx context.Context, alipayOrderID string) (*entities.RechargeRecord, error)
|
||||
GetByTransferOrderID(ctx context.Context, transferOrderID string) (*entities.RechargeRecord, error)
|
||||
Update(ctx context.Context, record entities.RechargeRecord) error
|
||||
UpdateStatus(ctx context.Context, id string, status entities.RechargeStatus) error
|
||||
|
||||
// 管理员查询方法
|
||||
List(ctx context.Context, options interfaces.ListOptions) ([]entities.RechargeRecord, error)
|
||||
Count(ctx context.Context, options interfaces.CountOptions) (int64, error)
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
package repositories
|
||||
|
||||
import (
|
||||
"context"
|
||||
"tyapi-server/internal/domains/finance/entities"
|
||||
"tyapi-server/internal/shared/interfaces"
|
||||
)
|
||||
|
||||
// FinanceStats 财务统计信息
|
||||
type FinanceStats struct {
|
||||
TotalWallets int64
|
||||
ActiveWallets int64
|
||||
TotalBalance string
|
||||
TodayTransactions int64
|
||||
}
|
||||
|
||||
// WalletRepository 钱包仓储接口
|
||||
// 只保留核心方法,聚合服务负责业务规则
|
||||
// 业务操作只保留乐观锁更新和基础更新
|
||||
|
||||
type WalletRepository interface {
|
||||
interfaces.Repository[entities.Wallet]
|
||||
|
||||
// 基础查询
|
||||
GetByUserID(ctx context.Context, userID string) (*entities.Wallet, error)
|
||||
|
||||
// 乐观锁更新(自动重试)
|
||||
UpdateBalanceWithVersion(ctx context.Context, walletID string, newBalance string, oldVersion int64) (bool, error)
|
||||
|
||||
// 状态操作
|
||||
ActivateWallet(ctx context.Context, walletID string) error
|
||||
DeactivateWallet(ctx context.Context, walletID string) error
|
||||
|
||||
// 统计
|
||||
GetStats(ctx context.Context) (*FinanceStats, error)
|
||||
GetUserWalletStats(ctx context.Context, userID string) (*FinanceStats, error)
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
package repositories
|
||||
|
||||
import (
|
||||
"context"
|
||||
"tyapi-server/internal/domains/finance/entities"
|
||||
"tyapi-server/internal/shared/interfaces"
|
||||
)
|
||||
|
||||
// WalletTransactionRepository 钱包扣款记录仓储接口
|
||||
type WalletTransactionRepository interface {
|
||||
interfaces.Repository[entities.WalletTransaction]
|
||||
|
||||
// 基础查询
|
||||
GetByUserID(ctx context.Context, userID string, limit, offset int) ([]*entities.WalletTransaction, error)
|
||||
GetByApiCallID(ctx context.Context, apiCallID string) (*entities.WalletTransaction, error)
|
||||
|
||||
// 新增:分页查询用户钱包交易记录
|
||||
ListByUserId(ctx context.Context, userId string, options interfaces.ListOptions) ([]*entities.WalletTransaction, int64, error)
|
||||
|
||||
// 新增:根据条件筛选钱包交易记录
|
||||
ListByUserIdWithFilters(ctx context.Context, userId string, filters map[string]interface{}, options interfaces.ListOptions) ([]*entities.WalletTransaction, int64, error)
|
||||
|
||||
// 新增:根据条件筛选钱包交易记录(包含产品名称)
|
||||
ListByUserIdWithFiltersAndProductName(ctx context.Context, userId string, filters map[string]interface{}, options interfaces.ListOptions) (map[string]string, []*entities.WalletTransaction, int64, error)
|
||||
|
||||
// 新增:统计用户钱包交易次数
|
||||
CountByUserId(ctx context.Context, userId string) (int64, error)
|
||||
}
|
||||
Reference in New Issue
Block a user