支持后台支付配置管理
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
package router
|
||||
|
||||
import (
|
||||
"os"
|
||||
"strings"
|
||||
|
||||
"hfb_sys/backend/internal/config"
|
||||
@@ -23,11 +24,12 @@ import (
|
||||
"hfb_sys/backend/internal/modules/notification"
|
||||
"hfb_sys/backend/internal/modules/order"
|
||||
"hfb_sys/backend/internal/modules/payment"
|
||||
"hfb_sys/backend/internal/modules/paymentaccount"
|
||||
"hfb_sys/backend/internal/modules/paymentconfig"
|
||||
"hfb_sys/backend/internal/modules/realname"
|
||||
"hfb_sys/backend/internal/modules/systemconfig"
|
||||
"hfb_sys/backend/internal/modules/user"
|
||||
"hfb_sys/backend/internal/modules/wallet"
|
||||
"hfb_sys/backend/internal/modules/paymentaccount"
|
||||
"hfb_sys/backend/internal/modules/withdrawal"
|
||||
|
||||
_ "hfb_sys/backend/docs" // Swagger 文档
|
||||
@@ -123,9 +125,32 @@ func New(cfg config.Config, deps Dependencies, logger *zap.Logger) *gin.Engine {
|
||||
}
|
||||
withdrawalService := withdrawal.NewService(withdrawalRepo)
|
||||
withdrawalHandler := withdrawal.NewHandler(withdrawalService)
|
||||
|
||||
// 支付配置管理
|
||||
var paymentConfigRepo *paymentconfig.Repository
|
||||
var paymentConfigService *paymentconfig.Service
|
||||
var paymentConfigHandler *paymentconfig.Handler
|
||||
if deps.DB != nil {
|
||||
// 从环境变量获取加密密钥,如果没有则使用 MockEncryptor
|
||||
encryptionKey := os.Getenv("PAYMENT_CONFIG_ENCRYPTION_KEY")
|
||||
var encryptor paymentconfig.Encryptor
|
||||
if encryptionKey != "" {
|
||||
if aesEncryptor, err := paymentconfig.NewAESEncryptor(encryptionKey); err == nil {
|
||||
encryptor = aesEncryptor
|
||||
}
|
||||
}
|
||||
if encryptor == nil {
|
||||
encryptor = &paymentconfig.MockEncryptor{}
|
||||
logger.Warn("PAYMENT_CONFIG_ENCRYPTION_KEY not set or invalid, using MockEncryptor")
|
||||
}
|
||||
paymentConfigRepo = paymentconfig.NewRepository(deps.DB, encryptor)
|
||||
paymentConfigService = paymentconfig.NewService(paymentConfigRepo)
|
||||
paymentConfigHandler = paymentconfig.NewHandler(paymentConfigService)
|
||||
}
|
||||
|
||||
var paymentRepo *payment.Repository
|
||||
if deps.DB != nil {
|
||||
paymentRepo = payment.NewRepository(deps.DB, cfg.Payment, orderRepo, walletRepo)
|
||||
paymentRepo = payment.NewRepository(deps.DB, paymentConfigRepo, orderRepo, walletRepo)
|
||||
}
|
||||
paymentService := payment.NewService(paymentRepo)
|
||||
paymentHandler := payment.NewHandler(paymentService)
|
||||
@@ -395,6 +420,15 @@ func New(cfg config.Config, deps Dependencies, logger *zap.Logger) *gin.Engine {
|
||||
adminRoutes.POST("/withdrawals/:id/review", requirePerm("withdrawal:review"), withdrawalHandler.Review)
|
||||
adminRoutes.POST("/withdrawals/:id/confirm-payment", requirePerm("withdrawal:pay"), withdrawalHandler.ConfirmPayment)
|
||||
|
||||
// 支付配置管理
|
||||
if paymentConfigHandler != nil {
|
||||
adminRoutes.GET("/payment-configs", requirePerm("payment_config:list"), paymentConfigHandler.List)
|
||||
adminRoutes.GET("/payment-configs/:id", requirePerm("payment_config:list"), paymentConfigHandler.Get)
|
||||
adminRoutes.POST("/payment-configs", requirePerm("payment_config:create"), paymentConfigHandler.Create)
|
||||
adminRoutes.PUT("/payment-configs/:id", requirePerm("payment_config:update"), paymentConfigHandler.Update)
|
||||
adminRoutes.DELETE("/payment-configs/:id", requirePerm("payment_config:delete"), paymentConfigHandler.Delete)
|
||||
}
|
||||
|
||||
adminRoutes.GET("/system-configs", requirePerm("system_config:view"), systemConfigHandler.List)
|
||||
adminRoutes.PUT("/system-configs/:key", requirePerm("system_config:update"), systemConfigHandler.Update)
|
||||
adminRoutes.GET("/audit-logs", requirePerm("audit_log:view"), adminAuditHandler.List)
|
||||
|
||||
Reference in New Issue
Block a user