初始化项目
This commit is contained in:
@@ -4,7 +4,6 @@ import (
|
||||
"context"
|
||||
"github.com/gogf/gf/v2/frame/g"
|
||||
"github.com/gogf/gf/v2/net/ghttp"
|
||||
"go.mongodb.org/mongo-driver/bson"
|
||||
"order/model/dto"
|
||||
"order/service"
|
||||
)
|
||||
@@ -27,45 +26,8 @@ func (c *PaymentConfigController) CreatePaymentConfig(r *ghttp.Request) {
|
||||
|
||||
ctx := context.Background()
|
||||
|
||||
// 构建支付配置实体
|
||||
config := &service.PaymentConfig{
|
||||
TenantID: req.TenantID,
|
||||
PayMethod: req.PayMethod,
|
||||
ConfigType: req.ConfigType,
|
||||
Environment: req.Environment,
|
||||
IsEnabled: req.IsEnabled,
|
||||
}
|
||||
|
||||
if req.WechatConfig != nil {
|
||||
config.WechatConfig = &service.WechatConfig{
|
||||
AppID: req.WechatConfig.AppID,
|
||||
MchID: req.WechatConfig.MchID,
|
||||
APIKey: req.WechatConfig.APIKey,
|
||||
APIClientCert: req.WechatConfig.APIClientCert,
|
||||
APIClientKey: req.WechatConfig.APIClientKey,
|
||||
NotifyURL: req.WechatConfig.NotifyURL,
|
||||
RefundNotifyURL: req.WechatConfig.RefundNotifyURL,
|
||||
SubAppID: req.WechatConfig.SubAppID,
|
||||
SubMchID: req.WechatConfig.SubMchID,
|
||||
}
|
||||
}
|
||||
|
||||
if req.AlipayConfig != nil {
|
||||
config.AlipayConfig = &service.AlipayConfig{
|
||||
AppID: req.AlipayConfig.AppID,
|
||||
PrivateKey: req.AlipayConfig.PrivateKey,
|
||||
PublicKey: req.AlipayConfig.PublicKey,
|
||||
AlipayPublicKey: req.AlipayConfig.AlipayPublicKey,
|
||||
NotifyURL: req.AlipayConfig.NotifyURL,
|
||||
RefundNotifyURL: req.AlipayConfig.RefundNotifyURL,
|
||||
Format: req.AlipayConfig.Format,
|
||||
Charset: req.AlipayConfig.Charset,
|
||||
SignType: req.AlipayConfig.SignType,
|
||||
IsSandbox: req.AlipayConfig.IsSandbox,
|
||||
}
|
||||
}
|
||||
|
||||
if err := service.PaymentService.CreatePaymentConfig(ctx, config); err != nil {
|
||||
resp, err := service.PaymentConfig.CreatePaymentConfig(ctx, &req)
|
||||
if err != nil {
|
||||
r.Response.WriteJsonExit(g.Map{
|
||||
"code": 500,
|
||||
"message": err.Error(),
|
||||
@@ -77,7 +39,7 @@ func (c *PaymentConfigController) CreatePaymentConfig(r *ghttp.Request) {
|
||||
r.Response.WriteJsonExit(g.Map{
|
||||
"code": 200,
|
||||
"message": "success",
|
||||
"data": nil,
|
||||
"data": resp,
|
||||
})
|
||||
}
|
||||
|
||||
@@ -95,85 +57,103 @@ func (c *PaymentConfigController) UpdatePaymentConfig(r *ghttp.Request) {
|
||||
|
||||
ctx := context.Background()
|
||||
|
||||
update := bson.M{}
|
||||
if req.ConfigType != "" {
|
||||
update["config_type"] = req.ConfigType
|
||||
}
|
||||
if req.Environment != "" {
|
||||
update["environment"] = req.Environment
|
||||
}
|
||||
if req.IsEnabled != nil {
|
||||
update["is_enabled"] = *req.IsEnabled
|
||||
resp, err := service.PaymentConfig.UpdatePaymentConfig(ctx, &req)
|
||||
if err != nil {
|
||||
r.Response.WriteJsonExit(g.Map{
|
||||
"code": 500,
|
||||
"message": err.Error(),
|
||||
"data": nil,
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
if req.WechatConfig != nil {
|
||||
wechatConfig := bson.M{}
|
||||
if req.WechatConfig.AppID != "" {
|
||||
wechatConfig["app_id"] = req.WechatConfig.AppID
|
||||
}
|
||||
if req.WechatConfig.MchID != "" {
|
||||
wechatConfig["mch_id"] = req.WechatConfig.MchID
|
||||
}
|
||||
if req.WechatConfig.APIKey != "" {
|
||||
wechatConfig["api_key"] = req.WechatConfig.APIKey
|
||||
}
|
||||
if req.WechatConfig.APIClientCert != "" {
|
||||
wechatConfig["api_client_cert"] = req.WechatConfig.APIClientCert
|
||||
}
|
||||
if req.WechatConfig.APIClientKey != "" {
|
||||
wechatConfig["api_client_key"] = req.WechatConfig.APIClientKey
|
||||
}
|
||||
if req.WechatConfig.NotifyURL != "" {
|
||||
wechatConfig["notify_url"] = req.WechatConfig.NotifyURL
|
||||
}
|
||||
if req.WechatConfig.RefundNotifyURL != "" {
|
||||
wechatConfig["refund_notify_url"] = req.WechatConfig.RefundNotifyURL
|
||||
}
|
||||
if req.WechatConfig.SubAppID != "" {
|
||||
wechatConfig["sub_app_id"] = req.WechatConfig.SubAppID
|
||||
}
|
||||
if req.WechatConfig.SubMchID != "" {
|
||||
wechatConfig["sub_mch_id"] = req.WechatConfig.SubMchID
|
||||
}
|
||||
update["wechat_config"] = wechatConfig
|
||||
r.Response.WriteJsonExit(g.Map{
|
||||
"code": 200,
|
||||
"message": "success",
|
||||
"data": resp,
|
||||
})
|
||||
}
|
||||
|
||||
// GetPaymentConfig 获取支付配置
|
||||
func (c *PaymentConfigController) GetPaymentConfig(r *ghttp.Request) {
|
||||
var req dto.QueryPaymentConfigReq
|
||||
if err := r.Parse(&req); err != nil {
|
||||
r.Response.WriteJsonExit(g.Map{
|
||||
"code": 400,
|
||||
"message": err.Error(),
|
||||
"data": nil,
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
if req.AlipayConfig != nil {
|
||||
alipayConfig := bson.M{}
|
||||
if req.AlipayConfig.AppID != "" {
|
||||
alipayConfig["app_id"] = req.AlipayConfig.AppID
|
||||
}
|
||||
if req.AlipayConfig.PrivateKey != "" {
|
||||
alipayConfig["private_key"] = req.AlipayConfig.PrivateKey
|
||||
}
|
||||
if req.AlipayConfig.PublicKey != "" {
|
||||
alipayConfig["public_key"] = req.AlipayConfig.PublicKey
|
||||
}
|
||||
if req.AlipayConfig.AlipayPublicKey != "" {
|
||||
alipayConfig["alipay_public_key"] = req.AlipayConfig.AlipayPublicKey
|
||||
}
|
||||
if req.AlipayConfig.NotifyURL != "" {
|
||||
alipayConfig["notify_url"] = req.AlipayConfig.NotifyURL
|
||||
}
|
||||
if req.AlipayConfig.RefundNotifyURL != "" {
|
||||
alipayConfig["refund_notify_url"] = req.AlipayConfig.RefundNotifyURL
|
||||
}
|
||||
if req.AlipayConfig.Format != "" {
|
||||
alipayConfig["format"] = req.AlipayConfig.Format
|
||||
}
|
||||
if req.AlipayConfig.Charset != "" {
|
||||
alipayConfig["charset"] = req.AlipayConfig.Charset
|
||||
}
|
||||
if req.AlipayConfig.SignType != "" {
|
||||
alipayConfig["sign_type"] = req.AlipayConfig.SignType
|
||||
}
|
||||
if req.AlipayConfig.IsSandbox != false {
|
||||
alipayConfig["is_sandbox"] = req.AlipayConfig.IsSandbox
|
||||
}
|
||||
update["alipay_config"] = alipayConfig
|
||||
ctx := context.Background()
|
||||
|
||||
resp, err := service.PaymentConfig.GetPaymentConfig(ctx, &req)
|
||||
if err != nil {
|
||||
r.Response.WriteJsonExit(g.Map{
|
||||
"code": 500,
|
||||
"message": err.Error(),
|
||||
"data": nil,
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
if err := service.PaymentService.UpdatePaymentConfig(ctx, req.ID, update); err != nil {
|
||||
r.Response.WriteJsonExit(g.Map{
|
||||
"code": 200,
|
||||
"message": "success",
|
||||
"data": resp,
|
||||
})
|
||||
}
|
||||
|
||||
// GetPaymentConfigList 获取支付配置列表
|
||||
func (c *PaymentConfigController) GetPaymentConfigList(r *ghttp.Request) {
|
||||
tenantID := r.Get("tenant_id").String()
|
||||
if tenantID == "" {
|
||||
r.Response.WriteJsonExit(g.Map{
|
||||
"code": 400,
|
||||
"message": "租户ID不能为空",
|
||||
"data": nil,
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
ctx := context.Background()
|
||||
|
||||
resp, err := service.PaymentConfig.GetPaymentConfigList(ctx, tenantID)
|
||||
if err != nil {
|
||||
r.Response.WriteJsonExit(g.Map{
|
||||
"code": 500,
|
||||
"message": err.Error(),
|
||||
"data": nil,
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
r.Response.WriteJsonExit(g.Map{
|
||||
"code": 200,
|
||||
"message": "success",
|
||||
"data": resp,
|
||||
})
|
||||
}
|
||||
|
||||
// DeletePaymentConfig 删除支付配置
|
||||
func (c *PaymentConfigController) DeletePaymentConfig(r *ghttp.Request) {
|
||||
tenantID := r.Get("tenant_id").String()
|
||||
configID := r.Get("config_id").String()
|
||||
|
||||
if tenantID == "" || configID == "" {
|
||||
r.Response.WriteJsonExit(g.Map{
|
||||
"code": 400,
|
||||
"message": "租户ID和配置ID不能为空",
|
||||
"data": nil,
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
ctx := context.Background()
|
||||
|
||||
err := service.PaymentConfig.DeletePaymentConfig(ctx, tenantID, configID)
|
||||
if err != nil {
|
||||
r.Response.WriteJsonExit(g.Map{
|
||||
"code": 500,
|
||||
"message": err.Error(),
|
||||
@@ -189,39 +169,15 @@ func (c *PaymentConfigController) UpdatePaymentConfig(r *ghttp.Request) {
|
||||
})
|
||||
}
|
||||
|
||||
// QueryPaymentConfig 查询支付配置
|
||||
func (c *PaymentConfigController) QueryPaymentConfig(r *ghttp.Request) {
|
||||
tentID := r.Get("tenant_id").String()
|
||||
payMethod := r.Get("pay_method").String()
|
||||
configType := r.Get("config_type").String()
|
||||
environment := r.Get("environment").String()
|
||||
// EnablePaymentConfig 启用支付配置
|
||||
func (c *PaymentConfigController) EnablePaymentConfig(r *ghttp.Request) {
|
||||
tenantID := r.Get("tenant_id").String()
|
||||
configID := r.Get("config_id").String()
|
||||
|
||||
ctx := context.Background()
|
||||
|
||||
config, err := service.PaymentService.QueryPaymentConfig(ctx, tentID, payMethod, configType, environment)
|
||||
if err != nil {
|
||||
r.Response.WriteJsonExit(g.Map{
|
||||
"code": 500,
|
||||
"message": err.Error(),
|
||||
"data": nil,
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
r.Response.WriteJsonExit(g.Map{
|
||||
"code": 200,
|
||||
"message": "success",
|
||||
"data": config,
|
||||
})
|
||||
}
|
||||
|
||||
// ListPaymentConfigs 查询支付配置列表
|
||||
func (c *PaymentConfigController) ListPaymentConfigs(r *ghttp.Request) {
|
||||
var req dto.QueryPaymentConfigReq
|
||||
if err := r.Parse(&req); err != nil {
|
||||
if tenantID == "" || configID == "" {
|
||||
r.Response.WriteJsonExit(g.Map{
|
||||
"code": 400,
|
||||
"message": err.Error(),
|
||||
"message": "租户ID和配置ID不能为空",
|
||||
"data": nil,
|
||||
})
|
||||
return
|
||||
@@ -229,28 +185,7 @@ func (c *PaymentConfigController) ListPaymentConfigs(r *ghttp.Request) {
|
||||
|
||||
ctx := context.Background()
|
||||
|
||||
filter := bson.M{"tenant_id": req.TenantID}
|
||||
if req.PayMethod != "" {
|
||||
filter["pay_method"] = req.PayMethod
|
||||
}
|
||||
if req.ConfigType != "" {
|
||||
filter["config_type"] = req.ConfigType
|
||||
}
|
||||
if req.Environment != "" {
|
||||
filter["environment"] = req.Environment
|
||||
}
|
||||
if req.IsEnabled != nil {
|
||||
filter["is_enabled"] = *req.IsEnabled
|
||||
}
|
||||
|
||||
if req.Page <= 0 {
|
||||
req.Page = 1
|
||||
}
|
||||
if req.PageSize <= 0 {
|
||||
req.PageSize = 10
|
||||
}
|
||||
|
||||
configs, total, err := service.PaymentService.ListPaymentConfigs(ctx, filter, req.Page, req.PageSize)
|
||||
err := service.PaymentConfig.EnablePaymentConfig(ctx, tenantID, configID)
|
||||
if err != nil {
|
||||
r.Response.WriteJsonExit(g.Map{
|
||||
"code": 500,
|
||||
@@ -260,57 +195,42 @@ func (c *PaymentConfigController) ListPaymentConfigs(r *ghttp.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
resp := dto.PaymentConfigListResp{
|
||||
List: make([]dto.PaymentConfigResp, 0, len(configs)),
|
||||
Total: total,
|
||||
Page: req.Page,
|
||||
PageSize: req.PageSize,
|
||||
TotalPage: int((total + int64(req.PageSize) - 1) / int64(req.PageSize)),
|
||||
r.Response.WriteJsonExit(g.Map{
|
||||
"code": 200,
|
||||
"message": "success",
|
||||
"data": nil,
|
||||
})
|
||||
}
|
||||
|
||||
// DisablePaymentConfig 禁用支付配置
|
||||
func (c *PaymentConfigController) DisablePaymentConfig(r *ghttp.Request) {
|
||||
tenantID := r.Get("tenant_id").String()
|
||||
configID := r.Get("config_id").String()
|
||||
|
||||
if tenantID == "" || configID == "" {
|
||||
r.Response.WriteJsonExit(g.Map{
|
||||
"code": 400,
|
||||
"message": "租户ID和配置ID不能为空",
|
||||
"data": nil,
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
for _, config := range configs {
|
||||
configResp := dto.PaymentConfigResp{
|
||||
ID: config.ID.Hex(),
|
||||
TenantID: config.TenantID,
|
||||
PayMethod: config.PayMethod,
|
||||
ConfigType: config.ConfigType,
|
||||
Environment: config.Environment,
|
||||
IsEnabled: config.IsEnabled,
|
||||
CreatedAt: config.CreatedAt,
|
||||
UpdatedAt: config.UpdatedAt,
|
||||
CreatedBy: config.CreatedBy,
|
||||
UpdatedBy: config.UpdatedBy,
|
||||
}
|
||||
ctx := context.Background()
|
||||
|
||||
if config.WechatConfig != nil {
|
||||
configResp.WechatConfig = &dto.WechatConfigResp{
|
||||
AppID: config.WechatConfig.AppID,
|
||||
MchID: config.WechatConfig.MchID,
|
||||
NotifyURL: config.WechatConfig.NotifyURL,
|
||||
RefundNotifyURL: config.WechatConfig.RefundNotifyURL,
|
||||
SubAppID: config.WechatConfig.SubAppID,
|
||||
SubMchID: config.WechatConfig.SubMchID,
|
||||
}
|
||||
}
|
||||
|
||||
if config.AlipayConfig != nil {
|
||||
configResp.AlipayConfig = &dto.AlipayConfigResp{
|
||||
AppID: config.AlipayConfig.AppID,
|
||||
NotifyURL: config.AlipayConfig.NotifyURL,
|
||||
RefundNotifyURL: config.AlipayConfig.RefundNotifyURL,
|
||||
Format: config.AlipayConfig.Format,
|
||||
Charset: config.AlipayConfig.Charset,
|
||||
SignType: config.AlipayConfig.SignType,
|
||||
IsSandbox: config.AlipayConfig.IsSandbox,
|
||||
}
|
||||
}
|
||||
|
||||
resp.List = append(resp.List, configResp)
|
||||
err := service.PaymentConfig.DisablePaymentConfig(ctx, tenantID, configID)
|
||||
if err != nil {
|
||||
r.Response.WriteJsonExit(g.Map{
|
||||
"code": 500,
|
||||
"message": err.Error(),
|
||||
"data": nil,
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
r.Response.WriteJsonExit(g.Map{
|
||||
"code": 200,
|
||||
"message": "success",
|
||||
"data": resp,
|
||||
"data": nil,
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user