Files
video-factory/shortdrama/controller/payment_config_controller.go
T
2026-07-23 18:14:23 +08:00

72 lines
1.6 KiB
Go

package controller
import (
"context"
"video-factory/shortdrama/model/dto"
"video-factory/shortdrama/model/entity"
"video-factory/shortdrama/service"
)
type paymentConfig struct{}
var PaymentConfig = new(paymentConfig)
func (c *paymentConfig) Get(ctx context.Context, req *dto.GetPaymentConfigReq) (res *dto.GetPaymentConfigRes, err error) {
configs, err := service.PaymentConfigService.GetPaymentConfigs(ctx)
if err != nil {
return &dto.GetPaymentConfigRes{}, nil
}
res = &dto.GetPaymentConfigRes{}
for _, cfg := range configs {
switch cfg.Channel {
case "wechat":
if res.Wechat == nil {
res.Wechat = &dto.PaymentTypeConfig{}
}
switch cfg.ChannelType {
case "jsapi":
res.Wechat.Jsapi = cfg
case "h5":
res.Wechat.H5 = cfg
case "app":
res.Wechat.App = cfg
default:
res.Wechat.Jsapi = cfg
}
case "alipay":
if res.Alipay == nil {
res.Alipay = &dto.PaymentTypeConfig{}
}
switch cfg.ChannelType {
case "jsapi":
res.Alipay.Jsapi = cfg
case "h5":
res.Alipay.H5 = cfg
case "app":
res.Alipay.App = cfg
case "precreate":
res.Alipay.Precreate = cfg
default:
res.Alipay.Jsapi = cfg
}
case "offline":
res.Offline = cfg
}
}
return res, nil
}
func (c *paymentConfig) Save(ctx context.Context, req *dto.SavePaymentConfigReq) (res *struct{}, err error) {
return nil, service.PaymentConfigService.SavePaymentConfig(ctx, &entity.PaymentConfig{
Channel: req.Channel,
ChannelType: req.ChannelType,
AppId: req.AppId,
MchId: req.MchId,
ApiKey: req.ApiKey,
AppSecret: req.AppSecret,
PrivateKey: req.PrivateKey,
PublicKey: req.PublicKey,
})
}