Files
video-factory/shortdrama/controller/config_controller.go
T
2026-07-15 14:34:57 +08:00

82 lines
2.0 KiB
Go

package controller
import (
"context"
"video-factory/shortdrama/model/dto"
"video-factory/shortdrama/model/entity"
"video-factory/shortdrama/service"
)
type config struct{}
var Config = new(config)
func (c *config) Get(ctx context.Context, req *dto.GetModelConfigReq) (res *dto.GetModelConfigRes, err error) {
return service.ConfigService.GetResponse(ctx), nil
}
func (c *config) Save(ctx context.Context, req *dto.SaveModelConfigReq) (res *struct{}, err error) {
return nil, service.ConfigService.Save(ctx, req)
}
func (c *config) GetPayment(ctx context.Context, req *dto.GetPaymentConfigReq) (res *dto.GetPaymentConfigRes, err error) {
configs, err := service.ConfigService.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
case "native":
res.Wechat.Native = 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 *config) SavePayment(ctx context.Context, req *dto.SavePaymentConfigReq) (res *struct{}, err error) {
return nil, service.ConfigService.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,
})
}