七月迭代短暂完结,还有很多后端的关键东西没有弄,这是一版赶时间做的东西
All checks were successful
构建并部署到测试环境(无 SSH) / build-and-deploy (push) Successful in 8m26s
All checks were successful
构建并部署到测试环境(无 SSH) / build-and-deploy (push) Successful in 8m26s
This commit is contained in:
36
internal/bootstrap/payment_method_config.go
Normal file
36
internal/bootstrap/payment_method_config.go
Normal file
@@ -0,0 +1,36 @@
|
||||
package bootstrap
|
||||
|
||||
import (
|
||||
"go.uber.org/zap"
|
||||
|
||||
"github.com/break/junhong_cmp_fiber/internal/infrastructure/systemconfig"
|
||||
"github.com/break/junhong_cmp_fiber/internal/service/paymentmethod"
|
||||
"github.com/break/junhong_cmp_fiber/pkg/constants"
|
||||
)
|
||||
|
||||
func registerPaymentMethodConfigDefinitions(registry *systemconfig.Registry, logger *zap.Logger) {
|
||||
if registry == nil {
|
||||
return
|
||||
}
|
||||
definitions := []systemconfig.Definition{
|
||||
{Key: constants.SystemConfigPaymentAllowedCard, Module: constants.SystemConfigModulePayment, ValueType: constants.SystemConfigTypeJSON, DefaultValue: `["wallet","wechat","alipay"]`, Description: "卡资产允许的C端支付方式", Control: "payment_methods", Validator: paymentmethod.ValidateConfigValue},
|
||||
{Key: constants.SystemConfigPaymentAllowedDevice, Module: constants.SystemConfigModulePayment, ValueType: constants.SystemConfigTypeJSON, DefaultValue: `["wallet","wechat","alipay"]`, Description: "设备资产允许的C端支付方式", Control: "payment_methods", Validator: paymentmethod.ValidateConfigValue},
|
||||
}
|
||||
for _, definition := range definitions {
|
||||
if existing, exists := registry.Get(definition.Key); exists {
|
||||
if existing.ValueType != definition.ValueType || existing.Module != definition.Module {
|
||||
logPaymentMethodConfigRegistrationError(logger, definition.Key, "配置 Key 已被其他类型或模块注册")
|
||||
}
|
||||
continue
|
||||
}
|
||||
if err := registry.Register(definition); err != nil {
|
||||
logPaymentMethodConfigRegistrationError(logger, definition.Key, err.Error())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func logPaymentMethodConfigRegistrationError(logger *zap.Logger, key, reason string) {
|
||||
if logger != nil {
|
||||
logger.Error("注册支付方式系统配置失败,C端支付将失败关闭", zap.String("config_key", key), zap.String("reason", reason))
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user