gomod引用

This commit is contained in:
2025-12-12 18:16:28 +08:00
parent a4ba4dd715
commit 465c138f21
11 changed files with 340 additions and 403 deletions

View File

@@ -2,235 +2,76 @@ package controller
import (
"context"
"github.com/gogf/gf/v2/frame/g"
"github.com/gogf/gf/v2/net/ghttp"
"order/model/dto"
"order/service"
)
type PaymentConfigController struct{}
type paymentConfig struct{}
var PaymentConfig = &PaymentConfigController{}
// PaymentConfig 支付配置控制器
var PaymentConfig = new(paymentConfig)
// CreatePaymentConfig 创建支付配置
func (c *PaymentConfigController) CreatePaymentConfig(r *ghttp.Request) {
var req dto.CreatePaymentConfigReq
if err := r.Parse(&req); err != nil {
r.Response.WriteJsonExit(g.Map{
"code": 400,
"message": err.Error(),
"data": nil,
})
return
}
ctx := context.Background()
resp, err := service.PaymentConfig.CreatePaymentConfig(ctx, &req)
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,
})
// Create 创建支付配置
func (c *paymentConfig) Create(ctx context.Context, req *dto.CreatePaymentConfigReq) (res *dto.PaymentConfigResp, err error) {
// 创建支付配置
res, err = service.PaymentConfig.CreatePaymentConfig(ctx, req)
return
}
// UpdatePaymentConfig 更新支付配置
func (c *PaymentConfigController) UpdatePaymentConfig(r *ghttp.Request) {
var req dto.UpdatePaymentConfigReq
if err := r.Parse(&req); err != nil {
r.Response.WriteJsonExit(g.Map{
"code": 400,
"message": err.Error(),
"data": nil,
})
return
}
ctx := context.Background()
resp, err := service.PaymentConfig.UpdatePaymentConfig(ctx, &req)
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,
})
// Update 更新支付配置
func (c *paymentConfig) Update(ctx context.Context, req *dto.UpdatePaymentConfigReq) (res *dto.PaymentConfigResp, err error) {
// 更新支付配置
res, err = service.PaymentConfig.UpdatePaymentConfig(ctx, req)
return
}
// 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
}
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
}
r.Response.WriteJsonExit(g.Map{
"code": 200,
"message": "success",
"data": resp,
})
// Query 查询支付配置
func (c *paymentConfig) Query(ctx context.Context, req *dto.QueryPaymentConfigReq) (res *dto.PaymentConfigResp, err error) {
// 查询支付配置
res, err = service.PaymentConfig.GetPaymentConfig(ctx, req)
return
}
// 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)
// List 查询支付配置列表
func (c *paymentConfig) List(ctx context.Context, req *dto.ListPaymentConfigReq) (res *dto.PaymentConfigListResp, err error) {
// 查询支付配置列表
list, err := service.PaymentConfig.GetPaymentConfigList(ctx, req.TenantID)
if err != nil {
r.Response.WriteJsonExit(g.Map{
"code": 500,
"message": err.Error(),
"data": nil,
})
return
return nil, err
}
r.Response.WriteJsonExit(g.Map{
"code": 200,
"message": "success",
"data": resp,
})
return &dto.PaymentConfigListResp{
List: list,
Total: int64(len(list)),
}, nil
}
// 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(),
"data": nil,
})
return
}
r.Response.WriteJsonExit(g.Map{
"code": 200,
"message": "success",
"data": nil,
})
// Delete 删除支付配置
func (c *paymentConfig) Delete(ctx context.Context, req *dto.DeletePaymentConfigReq) (res *dto.CommonResp, err error) {
// 删除支付配置
err = service.PaymentConfig.DeletePaymentConfig(ctx, req.TenantID, req.ConfigID)
return &dto.CommonResp{
Success: err == nil,
Message: "删除成功",
}, err
}
// EnablePaymentConfig 启用支付配置
func (c *PaymentConfigController) EnablePaymentConfig(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.EnablePaymentConfig(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": nil,
})
// Enable 启用支付配置
func (c *paymentConfig) Enable(ctx context.Context, req *dto.EnablePaymentConfigReq) (res *dto.CommonResp, err error) {
// 启用支付配置
err = service.PaymentConfig.EnablePaymentConfig(ctx, req.TenantID, req.ConfigID)
return &dto.CommonResp{
Success: err == nil,
Message: "启用成功",
}, err
}
// 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
}
ctx := context.Background()
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": nil,
})
// Disable 禁用支付配置
func (c *paymentConfig) Disable(ctx context.Context, req *dto.DisablePaymentConfigReq) (res *dto.CommonResp, err error) {
// 禁用支付配置
err = service.PaymentConfig.DisablePaymentConfig(ctx, req.TenantID, req.ConfigID)
return &dto.CommonResp{
Success: err == nil,
Message: "禁用成功",
}, err
}