mirror of
https://github.com/bufanyun/hotgo.git
synced 2025-01-23 02:40:23 +08:00
refactor(api/api):符合gf gen ctrl规范
This commit is contained in:
parent
09026a606b
commit
d9b57e6c62
@ -1,16 +1,15 @@
|
||||
// Package member
|
||||
// @Link https://github.com/bufanyun/hotgo
|
||||
// @Copyright Copyright (c) 2023 HotGo CLI
|
||||
// @Author Ms <133814250@qq.com>
|
||||
// @License https://github.com/bufanyun/hotgo/blob/master/LICENSE
|
||||
// =================================================================================
|
||||
// Code generated and maintained by GoFrame CLI tool. DO NOT EDIT.
|
||||
// =================================================================================
|
||||
|
||||
package member
|
||||
|
||||
import "github.com/gogf/gf/v2/frame/g"
|
||||
import (
|
||||
"context"
|
||||
|
||||
// GetIdByCodeReq 通过邀请码获取用户ID
|
||||
type GetIdByCodeReq struct {
|
||||
g.Meta `path:"/member/getIdByCode" method:"post" tags:"用户" summary:"通过邀请码获取用户ID"`
|
||||
Code string `json:"code" dc:"邀请码"`
|
||||
"hotgo/api/api/member/v1"
|
||||
)
|
||||
|
||||
type IMemberV1 interface {
|
||||
GetIdByCode(ctx context.Context, req *v1.GetIdByCodeReq) (res *v1.GetIdByCodeRes, err error)
|
||||
}
|
||||
|
||||
type GetIdByCodeRes struct{}
|
||||
|
16
server/api/api/member/v1/member.go
Normal file
16
server/api/api/member/v1/member.go
Normal file
@ -0,0 +1,16 @@
|
||||
// Package member
|
||||
// @Link https://github.com/bufanyun/hotgo
|
||||
// @Copyright Copyright (c) 2023 HotGo CLI
|
||||
// @Author Ms <133814250@qq.com>
|
||||
// @License https://github.com/bufanyun/hotgo/blob/master/LICENSE
|
||||
package v1
|
||||
|
||||
import "github.com/gogf/gf/v2/frame/g"
|
||||
|
||||
// GetIdByCodeReq 通过邀请码获取用户ID
|
||||
type GetIdByCodeReq struct {
|
||||
g.Meta `path:"/member/getIdByCode" method:"post" tags:"用户" summary:"通过邀请码获取用户ID"`
|
||||
Code string `json:"code" dc:"邀请码"`
|
||||
}
|
||||
|
||||
type GetIdByCodeRes struct{}
|
17
server/api/api/pay/pay.go
Normal file
17
server/api/api/pay/pay.go
Normal file
@ -0,0 +1,17 @@
|
||||
// =================================================================================
|
||||
// Code generated and maintained by GoFrame CLI tool. DO NOT EDIT.
|
||||
// =================================================================================
|
||||
|
||||
package pay
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"hotgo/api/api/pay/v1"
|
||||
)
|
||||
|
||||
type IPayV1 interface {
|
||||
NotifyAliPay(ctx context.Context, req *v1.NotifyAliPayReq) (res *v1.NotifyAliPayRes, err error)
|
||||
NotifyWxPay(ctx context.Context, req *v1.NotifyWxPayReq) (res *v1.NotifyWxPayRes, err error)
|
||||
NotifyQQPay(ctx context.Context, req *v1.NotifyQQPayReq) (res *v1.NotifyQQPayRes, err error)
|
||||
}
|
@ -3,11 +3,12 @@
|
||||
// @Copyright Copyright (c) 2023 HotGo CLI
|
||||
// @Author Ms <133814250@qq.com>
|
||||
// @License https://github.com/bufanyun/hotgo/blob/master/LICENSE
|
||||
package pay
|
||||
package v1
|
||||
|
||||
import (
|
||||
"github.com/gogf/gf/v2/frame/g"
|
||||
"hotgo/internal/model/input/payin"
|
||||
|
||||
"github.com/gogf/gf/v2/frame/g"
|
||||
)
|
||||
|
||||
// NotifyAliPayReq 支付宝回调
|
@ -38,4 +38,10 @@ gfcli:
|
||||
# srcFolder: "internal/logic"
|
||||
# dstFolder: "internal/service"
|
||||
# dstFileNameCase: "CamelLower"
|
||||
# clear: true
|
||||
# clear: true
|
||||
ctrl:
|
||||
# api/api下的接口可以使用gf gen ctrl自动生成控制器相关代码
|
||||
srcFolder: "api/api"
|
||||
dstFolder: "internal/controller/api"
|
||||
clear: true
|
||||
merge: false
|
||||
|
@ -1,23 +1,5 @@
|
||||
// Package member
|
||||
// @Link https://github.com/bufanyun/hotgo
|
||||
// @Copyright Copyright (c) 2023 HotGo CLI
|
||||
// @Author Ms <133814250@qq.com>
|
||||
// @License https://github.com/bufanyun/hotgo/blob/master/LICENSE
|
||||
// =================================================================================
|
||||
// This is auto-generated by GoFrame CLI tool only once. Fill this file as you wish.
|
||||
// =================================================================================
|
||||
|
||||
package member
|
||||
|
||||
import (
|
||||
"context"
|
||||
"github.com/gogf/gf/v2/frame/g"
|
||||
"hotgo/api/api/member"
|
||||
)
|
||||
|
||||
var (
|
||||
Member = cMember{}
|
||||
)
|
||||
|
||||
type cMember struct{}
|
||||
|
||||
func (c *cMember) GetIdByCode(ctx context.Context, _ *member.GetIdByCodeReq) (res *member.GetIdByCodeRes, err error) {
|
||||
g.RequestFromCtx(ctx).Response.Writeln("Hello World api member!")
|
||||
return
|
||||
}
|
||||
|
15
server/internal/controller/api/member/member_new.go
Normal file
15
server/internal/controller/api/member/member_new.go
Normal file
@ -0,0 +1,15 @@
|
||||
// =================================================================================
|
||||
// This is auto-generated by GoFrame CLI tool only once. Fill this file as you wish.
|
||||
// =================================================================================
|
||||
|
||||
package member
|
||||
|
||||
import (
|
||||
"hotgo/api/api/member"
|
||||
)
|
||||
|
||||
type ControllerV1 struct{}
|
||||
|
||||
func NewV1() member.IMemberV1 {
|
||||
return &ControllerV1{}
|
||||
}
|
@ -0,0 +1,14 @@
|
||||
package member
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
v1 "hotgo/api/api/member/v1"
|
||||
|
||||
"github.com/gogf/gf/v2/frame/g"
|
||||
)
|
||||
|
||||
func (c *ControllerV1) GetIdByCode(ctx context.Context, req *v1.GetIdByCodeReq) (res *v1.GetIdByCodeRes, err error) {
|
||||
g.RequestFromCtx(ctx).Response.Writeln("Hello World api member!")
|
||||
return
|
||||
}
|
@ -1,57 +0,0 @@
|
||||
// Package pay
|
||||
// @Link https://github.com/bufanyun/hotgo
|
||||
// @Copyright Copyright (c) 2023 HotGo CLI
|
||||
// @Author Ms <133814250@qq.com>
|
||||
// @License https://github.com/bufanyun/hotgo/blob/master/LICENSE
|
||||
package pay
|
||||
|
||||
import (
|
||||
"context"
|
||||
"github.com/gogf/gf/v2/frame/g"
|
||||
"hotgo/api/api/pay"
|
||||
"hotgo/internal/consts"
|
||||
"hotgo/internal/library/response"
|
||||
"hotgo/internal/model/input/payin"
|
||||
"hotgo/internal/service"
|
||||
)
|
||||
|
||||
var (
|
||||
Notify = cNotify{}
|
||||
)
|
||||
|
||||
type cNotify struct{}
|
||||
|
||||
// AliPay 支付宝回调
|
||||
func (c *cNotify) AliPay(ctx context.Context, _ *pay.NotifyAliPayReq) (res *pay.NotifyAliPayRes, err error) {
|
||||
if _, err = service.Pay().Notify(ctx, &payin.PayNotifyInp{PayType: consts.PayTypeAliPay}); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
response.RText(g.RequestFromCtx(ctx), "success")
|
||||
return
|
||||
}
|
||||
|
||||
// WxPay 微信支付回调
|
||||
func (c *cNotify) WxPay(ctx context.Context, _ *pay.NotifyWxPayReq) (res *pay.NotifyWxPayRes, err error) {
|
||||
if _, err = service.Pay().Notify(ctx, &payin.PayNotifyInp{PayType: consts.PayTypeWxPay}); err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
response.CustomJson(g.RequestFromCtx(ctx), `{"code": "SUCCESS","message": "收单成功"}`)
|
||||
return
|
||||
}
|
||||
|
||||
// QQPay QQ支付回调
|
||||
func (c *cNotify) QQPay(ctx context.Context, _ *pay.NotifyQQPayReq) (res *pay.NotifyQQPayRes, err error) {
|
||||
if _, err = service.Pay().Notify(ctx, &payin.PayNotifyInp{PayType: consts.PayTypeQQPay}); err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
r := g.RequestFromCtx(ctx)
|
||||
r.Response.ClearBuffer()
|
||||
r.Response.Write(`<?xml version="1.0" encoding="UTF-8"?>`)
|
||||
r.Response.WriteXml(g.Map{
|
||||
"return_code": "SUCCESS",
|
||||
})
|
||||
return
|
||||
}
|
5
server/internal/controller/api/pay/pay.go
Normal file
5
server/internal/controller/api/pay/pay.go
Normal file
@ -0,0 +1,5 @@
|
||||
// =================================================================================
|
||||
// This is auto-generated by GoFrame CLI tool only once. Fill this file as you wish.
|
||||
// =================================================================================
|
||||
|
||||
package pay
|
15
server/internal/controller/api/pay/pay_new.go
Normal file
15
server/internal/controller/api/pay/pay_new.go
Normal file
@ -0,0 +1,15 @@
|
||||
// =================================================================================
|
||||
// This is auto-generated by GoFrame CLI tool only once. Fill this file as you wish.
|
||||
// =================================================================================
|
||||
|
||||
package pay
|
||||
|
||||
import (
|
||||
"hotgo/api/api/pay"
|
||||
)
|
||||
|
||||
type ControllerV1 struct{}
|
||||
|
||||
func NewV1() pay.IPayV1 {
|
||||
return &ControllerV1{}
|
||||
}
|
22
server/internal/controller/api/pay/pay_v1_notify_ali_pay.go
Normal file
22
server/internal/controller/api/pay/pay_v1_notify_ali_pay.go
Normal file
@ -0,0 +1,22 @@
|
||||
package pay
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
v1 "hotgo/api/api/pay/v1"
|
||||
"hotgo/internal/consts"
|
||||
"hotgo/internal/library/response"
|
||||
"hotgo/internal/model/input/payin"
|
||||
"hotgo/internal/service"
|
||||
|
||||
"github.com/gogf/gf/v2/frame/g"
|
||||
)
|
||||
|
||||
func (c *ControllerV1) NotifyAliPay(ctx context.Context, req *v1.NotifyAliPayReq) (res *v1.NotifyAliPayRes, err error) {
|
||||
if _, err = service.Pay().Notify(ctx, &payin.PayNotifyInp{PayType: consts.PayTypeAliPay}); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
response.RText(g.RequestFromCtx(ctx), "success")
|
||||
return
|
||||
}
|
26
server/internal/controller/api/pay/pay_v1_notify_qq_pay.go
Normal file
26
server/internal/controller/api/pay/pay_v1_notify_qq_pay.go
Normal file
@ -0,0 +1,26 @@
|
||||
package pay
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
v1 "hotgo/api/api/pay/v1"
|
||||
"hotgo/internal/consts"
|
||||
"hotgo/internal/model/input/payin"
|
||||
"hotgo/internal/service"
|
||||
|
||||
"github.com/gogf/gf/v2/frame/g"
|
||||
)
|
||||
|
||||
func (c *ControllerV1) NotifyQQPay(ctx context.Context, req *v1.NotifyQQPayReq) (res *v1.NotifyQQPayRes, err error) {
|
||||
if _, err = service.Pay().Notify(ctx, &payin.PayNotifyInp{PayType: consts.PayTypeQQPay}); err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
r := g.RequestFromCtx(ctx)
|
||||
r.Response.ClearBuffer()
|
||||
r.Response.Write(`<?xml version="1.0" encoding="UTF-8"?>`)
|
||||
r.Response.WriteXml(g.Map{
|
||||
"return_code": "SUCCESS",
|
||||
})
|
||||
return
|
||||
}
|
22
server/internal/controller/api/pay/pay_v1_notify_wx_pay.go
Normal file
22
server/internal/controller/api/pay/pay_v1_notify_wx_pay.go
Normal file
@ -0,0 +1,22 @@
|
||||
package pay
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
v1 "hotgo/api/api/pay/v1"
|
||||
"hotgo/internal/consts"
|
||||
"hotgo/internal/library/response"
|
||||
"hotgo/internal/model/input/payin"
|
||||
"hotgo/internal/service"
|
||||
|
||||
"github.com/gogf/gf/v2/frame/g"
|
||||
)
|
||||
|
||||
func (c *ControllerV1) NotifyWxPay(ctx context.Context, req *v1.NotifyWxPayReq) (res *v1.NotifyWxPayRes, err error) {
|
||||
if _, err = service.Pay().Notify(ctx, &payin.PayNotifyInp{PayType: consts.PayTypeWxPay}); err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
response.CustomJson(g.RequestFromCtx(ctx), `{"code": "SUCCESS","message": "收单成功"}`)
|
||||
return
|
||||
}
|
@ -10,13 +10,7 @@ package pay
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"github.com/gogf/gf/v2/encoding/gjson"
|
||||
"github.com/gogf/gf/v2/errors/gerror"
|
||||
"github.com/gogf/gf/v2/frame/g"
|
||||
"github.com/gogf/gf/v2/net/ghttp"
|
||||
"github.com/gogf/gf/v2/os/gctx"
|
||||
"github.com/gogf/gf/v2/util/gmeta"
|
||||
"hotgo/api/api/pay"
|
||||
v1 "hotgo/api/api/pay/v1"
|
||||
"hotgo/internal/consts"
|
||||
"hotgo/internal/library/contexts"
|
||||
"hotgo/internal/library/location"
|
||||
@ -25,6 +19,13 @@ import (
|
||||
"hotgo/internal/model/input/payin"
|
||||
"hotgo/internal/service"
|
||||
"hotgo/utility/validate"
|
||||
|
||||
"github.com/gogf/gf/v2/encoding/gjson"
|
||||
"github.com/gogf/gf/v2/errors/gerror"
|
||||
"github.com/gogf/gf/v2/frame/g"
|
||||
"github.com/gogf/gf/v2/net/ghttp"
|
||||
"github.com/gogf/gf/v2/os/gctx"
|
||||
"github.com/gogf/gf/v2/util/gmeta"
|
||||
)
|
||||
|
||||
// Create 创建支付订单和日志
|
||||
@ -127,11 +128,11 @@ func (s *sPay) GenNotifyURL(ctx context.Context, in payin.PayCreateInp) (notifyU
|
||||
var object interface{}
|
||||
switch in.PayType {
|
||||
case consts.PayTypeAliPay:
|
||||
object = pay.NotifyAliPayReq{}
|
||||
object = v1.NotifyAliPayReq{}
|
||||
case consts.PayTypeWxPay:
|
||||
object = pay.NotifyWxPayReq{}
|
||||
object = v1.NotifyWxPayReq{}
|
||||
case consts.PayTypeQQPay:
|
||||
object = pay.NotifyQQPayReq{}
|
||||
object = v1.NotifyQQPayReq{}
|
||||
default:
|
||||
err = gerror.Newf("未被支持的支付方式:%v", in.PayType)
|
||||
return
|
||||
|
@ -7,23 +7,24 @@ package router
|
||||
|
||||
import (
|
||||
"context"
|
||||
"github.com/gogf/gf/v2/net/ghttp"
|
||||
"hotgo/internal/consts"
|
||||
"hotgo/internal/controller/api/member"
|
||||
"hotgo/internal/controller/api/pay"
|
||||
"hotgo/internal/service"
|
||||
"hotgo/utility/simple"
|
||||
|
||||
"github.com/gogf/gf/v2/net/ghttp"
|
||||
)
|
||||
|
||||
// Api 前台路由
|
||||
func Api(ctx context.Context, group *ghttp.RouterGroup) {
|
||||
group.Group(simple.RouterPrefix(ctx, consts.AppApi), func(group *ghttp.RouterGroup) {
|
||||
group.Bind(
|
||||
pay.Notify, // 支付异步通知
|
||||
pay.NewV1(), // 支付异步通知
|
||||
)
|
||||
group.Middleware(service.Middleware().ApiAuth)
|
||||
group.Bind(
|
||||
member.Member, // 管理员
|
||||
member.NewV1(), // 管理员
|
||||
)
|
||||
})
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user