This commit is contained in:
2024-10-15 17:19:23 +08:00
parent 8f903b457f
commit c76451788c
42 changed files with 1600 additions and 237 deletions

View File

@@ -258,17 +258,44 @@ type (
AliTopUpResponse {
payUrl string `json:"payUrl"`
}
GetTopUpListReq {
Page int64 `form:"page"`
PageSize int64 `form:"pageSize"`
}
GetTopUpListResp {
Total int64 `json:"total"`
List []TopUpItem `json:"list"`
}
TopUpItem {
Id int64 `json:"id"` // 主键ID
UserId int64 `json:"user_id"` // 用户ID
TransactionId string `json:"transaction_id"` // 交易ID
OutTradeNo string `json:"out_trade_no"` // 外部订单号
Amount float64 `json:"amount"` // 充值金额
PaymentMethod int64 `json:"payment_method"` // 支付方式
CreatedAt string `json:"created_at"` // 创建时间
UpdatedAt string `json:"updated_at"` // 更新时间
}
)
@server (
group: topup
prefix: /api/console/topupfmghnjx
prefix: /api/console/topup
middleware: AuthInterceptor,EntAuthInterceptor
)
service gateway-api {
@handler aliTopUp
post /aliTopUp (AliTopUpRequest) returns (AliTopUpResponse)
@handler topList
get /topUpList (GetTopUpListReq) returns (GetTopUpListResp)
}
@server (
group: topup
prefix: /api/console/topup
)
service gateway-api {
@handler aliTopUpCallback
post /aliTopUpCallback
}

View File

@@ -90,13 +90,24 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
Handler: topup.AliTopUpHandler(serverCtx),
},
{
Method: http.MethodPost,
Path: "/aliTopUpCallback",
Handler: topup.AliTopUpCallbackHandler(serverCtx),
Method: http.MethodGet,
Path: "/topUpList",
Handler: topup.TopListHandler(serverCtx),
},
}...,
),
rest.WithPrefix("/api/console/topupfmghnjx"),
rest.WithPrefix("/api/console/topup"),
)
server.AddRoutes(
[]rest.Route{
{
Method: http.MethodPost,
Path: "/aliTopUpCallback",
Handler: topup.AliTopUpCallbackHandler(serverCtx),
},
},
rest.WithPrefix("/api/console/topup"),
)
server.AddRoutes(

View File

@@ -0,0 +1,30 @@
package topup
import (
"net/http"
"github.com/zeromicro/go-zero/rest/httpx"
"tianyuan-api/apps/gateway/internal/logic/topup"
"tianyuan-api/apps/gateway/internal/svc"
"tianyuan-api/apps/gateway/internal/types"
xhttp "github.com/zeromicro/x/http"
)
func TopListHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req types.GetTopUpListReq
if err := httpx.Parse(r, &req); err != nil {
xhttp.JsonBaseResponseCtx(r.Context(), w, err)
return
}
l := topup.NewTopListLogic(r.Context(), svcCtx)
resp, err := l.TopList(&req)
if err != nil {
xhttp.JsonBaseResponseCtx(r.Context(), w, err)
} else {
xhttp.JsonBaseResponseCtx(r.Context(), w, resp)
}
}
}

View File

@@ -24,7 +24,11 @@ func NewAliTopUpCallbackLogic(ctx context.Context, svcCtx *svc.ServiceContext) *
}
func (l *AliTopUpCallbackLogic) AliTopUpCallback(r *http.Request) error {
_, err := l.svcCtx.TopUpRpc.AliTopUpNotify(l.ctx, &sentinel.AliTopUpNotifyRequest{
err := r.ParseForm()
if err != nil {
return err
}
_, err = l.svcCtx.TopUpRpc.AliTopUpNotify(l.ctx, &sentinel.AliTopUpNotifyRequest{
RawForm: r.Form.Encode(),
})
if err != nil {

View File

@@ -0,0 +1,59 @@
package topup
import (
"context"
"errors"
"tianyuan-api/apps/user/user"
"tianyuan-api/apps/gateway/internal/svc"
"tianyuan-api/apps/gateway/internal/types"
"github.com/zeromicro/go-zero/core/logx"
)
type TopListLogic struct {
logx.Logger
ctx context.Context
svcCtx *svc.ServiceContext
}
func NewTopListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *TopListLogic {
return &TopListLogic{
Logger: logx.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
}
}
func (l *TopListLogic) TopList(req *types.GetTopUpListReq) (resp *types.GetTopUpListResp, err error) {
userId, ok := l.ctx.Value("userId").(int64)
if !ok {
return nil, errors.New("无法获取 userId")
}
list, err := l.svcCtx.Wallets.GetRechargeList(l.ctx, &user.RechargeRequest{
UserId: userId,
Page: req.Page,
PageSize: req.PageSize,
})
if err != nil {
return nil, err
}
var topUpItemList []types.TopUpItem
for _, p := range list.List {
topUpItemList = append(topUpItemList, types.TopUpItem{
Id: p.Id,
UserId: p.UserId,
TransactionId: p.TransactionId,
OutTradeNo: p.OutTradeNo,
Amount: float64(p.Amount),
PaymentMethod: p.PaymentMethod,
CreatedAt: p.CreatedAt,
UpdatedAt: p.UpdatedAt,
})
}
return &types.GetTopUpListResp{
Total: list.Total,
List: topUpItemList,
}, nil
}

View File

@@ -18,6 +18,7 @@ type ServiceContext struct {
AuthRpc user.AuthClient
EntRpc user.EnterpriseClient
UserRpc user.UserClient
Wallets user.WalletServiceClient
ProductRpc sentinel.ProductClient
UserProductRpc sentinel.UserProductClient
WhitelistRpc sentinel.WhitelistClient
@@ -37,11 +38,13 @@ func NewServiceContext(c config.Config) *ServiceContext {
authRpc := user.NewAuthClient(zrpc.MustNewClient(c.UserRpc).Conn())
entRpc := user.NewEnterpriseClient(zrpc.MustNewClient(c.UserRpc).Conn())
userRpc := user.NewUserClient(zrpc.MustNewClient(c.UserRpc).Conn())
wallets := user.NewWalletServiceClient(zrpc.MustNewClient(c.UserRpc).Conn())
productRpc := sentinel.NewProductClient(zrpc.MustNewClient(c.SentinelRpc).Conn())
userProductRpc := sentinel.NewUserProductClient(zrpc.MustNewClient(c.SentinelRpc).Conn())
whitelistRpc := sentinel.NewWhitelistClient(zrpc.MustNewClient(c.SentinelRpc).Conn())
secretRpc := sentinel.NewSecretClient(zrpc.MustNewClient(c.SentinelRpc).Conn())
topUpRpc := sentinel.NewTopUpClient(zrpc.MustNewClient(c.SentinelRpc).Conn())
return &ServiceContext{
Config: c,
AuthInterceptor: middleware.NewAuthInterceptorMiddleware(c).Handle,
@@ -55,5 +58,6 @@ func NewServiceContext(c config.Config) *ServiceContext {
WhitelistRpc: whitelistRpc,
SecretRpc: secretRpc,
TopUpRpc: topUpRpc,
Wallets: wallets,
}
}

View File

@@ -45,6 +45,16 @@ type GetProductListResp struct {
List []ProductItem `json:"list"`
}
type GetTopUpListReq struct {
Page int64 `form:"page"`
PageSize int64 `form:"pageSize"`
}
type GetTopUpListResp struct {
Total int64 `json:"total"`
List []TopUpItem `json:"list"`
}
type GetUserProductListReq struct {
Page int64 `form:"page"`
PageSize int64 `form:"pageSize"`
@@ -95,6 +105,17 @@ type RegisterReq struct {
Code string `json:"code"`
}
type TopUpItem struct {
Id int64 `json:"id"` // 主键ID
UserId int64 `json:"user_id"` // 用户ID
TransactionId string `json:"transaction_id"` // 交易ID
OutTradeNo string `json:"out_trade_no"` // 外部订单号
Amount float64 `json:"amount"` // 充值金额
PaymentMethod int64 `json:"payment_method"` // 支付方式
CreatedAt string `json:"created_at"` // 创建时间
UpdatedAt string `json:"updated_at"` // 更新时间
}
type UploadBusinessLicenseResp struct {
Url string `json:"url"`
EnterpriseName string `json:"enterpriseName"`