119 lines
3.3 KiB
Go
119 lines
3.3 KiB
Go
package controller
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
|
|
"video-factory/shortdrama/middleware"
|
|
"video-factory/shortdrama/model/dto"
|
|
"video-factory/shortdrama/model/entity"
|
|
"video-factory/shortdrama/service"
|
|
|
|
"github.com/gogf/gf/v2/frame/g"
|
|
)
|
|
|
|
type config struct{}
|
|
|
|
var Config = new(config)
|
|
|
|
func (c *config) GetModelList(ctx context.Context, req *dto.GetModelConfigListReq) (res *dto.GetModelConfigListRes, err error) {
|
|
list, total, err := service.ConfigService.GetModelListPage(ctx, req.Page, req.PageSize, req.ModelType, req.Keyword)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return &dto.GetModelConfigListRes{List: list, Total: total}, nil
|
|
}
|
|
|
|
func (c *config) SaveModelConfig(ctx context.Context, req *dto.SaveModelConfigReq) (res *struct{}, err error) {
|
|
return nil, service.ConfigService.SaveModelConfig(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
|
|
case "precreate":
|
|
res.Alipay.Precreate = cfg
|
|
default:
|
|
res.Alipay.Jsapi = cfg
|
|
}
|
|
case "offline":
|
|
res.Offline = cfg
|
|
}
|
|
}
|
|
return res, nil
|
|
}
|
|
|
|
func (c *config) GetUserConfig(ctx context.Context, req *dto.GetUserModelConfigReq) (res *dto.GetUserModelConfigRes, err error) {
|
|
r := g.RequestFromCtx(ctx)
|
|
userId := middleware.GetUserId(r)
|
|
if userId <= 0 {
|
|
return nil, fmt.Errorf("未登录")
|
|
}
|
|
cfg := service.ConfigService.GetUserConfig(ctx, userId, req.ModelType)
|
|
return &dto.GetUserModelConfigRes{UserModelConfig: cfg}, nil
|
|
}
|
|
|
|
func (c *config) SaveUserConfig(ctx context.Context, req *dto.SaveUserModelConfigReq) (res *struct{}, err error) {
|
|
r := g.RequestFromCtx(ctx)
|
|
userId := middleware.GetUserId(r)
|
|
if userId <= 0 {
|
|
return nil, fmt.Errorf("未登录")
|
|
}
|
|
return nil, service.ConfigService.SaveUserConfigs(ctx, userId, req.Configs)
|
|
}
|
|
|
|
func (c *config) GetUserModelList(ctx context.Context, req *dto.GetUserModelListReq) (res *dto.GetUserModelListRes, err error) {
|
|
r := g.RequestFromCtx(ctx)
|
|
userId := middleware.GetUserId(r)
|
|
if req.Page <= 0 {
|
|
req.Page = 1
|
|
}
|
|
if req.PageSize <= 0 {
|
|
req.PageSize = 20
|
|
}
|
|
return service.ConfigService.GetUserModelListPage(ctx, userId, req.Page, req.PageSize, req.ModelType, req.Keyword), 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,
|
|
})
|
|
}
|