88 lines
2.2 KiB
Go
88 lines
2.2 KiB
Go
package controller
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
|
|
"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) {
|
|
if req.MinSingleDuration < 1 {
|
|
return nil, fmt.Errorf("单次生成最小时长必须大于等于1")
|
|
}
|
|
if req.MaxSingleDuration < 1 {
|
|
return nil, fmt.Errorf("单次生成最大时长必须大于等于1")
|
|
}
|
|
if req.MinSingleDuration > req.MaxSingleDuration {
|
|
return nil, fmt.Errorf("单次生成最小时长不能大于最大时长")
|
|
}
|
|
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
|
|
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
|
|
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,
|
|
})
|
|
}
|