52 lines
1.6 KiB
Go
52 lines
1.6 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) {
|
|
cfg := service.ConfigService.GetPaymentConfig(ctx)
|
|
if cfg == nil {
|
|
return &dto.GetPaymentConfigRes{PaymentConfig: &entity.PaymentConfig{}}, nil
|
|
}
|
|
return &dto.GetPaymentConfigRes{PaymentConfig: cfg}, nil
|
|
}
|
|
|
|
func (c *config) SavePayment(ctx context.Context, req *dto.SavePaymentConfigReq) (res *struct{}, err error) {
|
|
return nil, service.ConfigService.SavePaymentConfig(ctx, &entity.PaymentConfig{
|
|
WechatAppId: req.WechatAppId,
|
|
WechatMchId: req.WechatMchId,
|
|
WechatApiKey: req.WechatApiKey,
|
|
WechatAppSecret: req.WechatAppSecret,
|
|
AlipayAppId: req.AlipayAppId,
|
|
AlipayPrivateKey: req.AlipayPrivateKey,
|
|
AlipayPublicKey: req.AlipayPublicKey,
|
|
})
|
|
}
|