修复产品修改、删除

This commit is contained in:
2024-10-15 00:23:07 +08:00
parent e6467b7004
commit 8f903b457f
31 changed files with 1292 additions and 111 deletions

View File

@@ -191,6 +191,7 @@ service gateway-api {
@handler getUserProductList
get /userProductList (GetUserProductListReq) returns (GetUserProductListResp)
}
@server (
group: userProduct
prefix: /api/console/user-product
@@ -202,8 +203,8 @@ service gateway-api {
@handler deleteUserProduct
delete /userProductDel/:id (DeleteUserProductReq)
}
type (
AddWhitelistReq {
Ip string `json:"ip"`
@@ -250,3 +251,25 @@ service gateway-api {
delete /delWhitelist (DeleteWhitelistReq)
}
type (
AliTopUpRequest {
amount int64 `json:"amount"`
}
AliTopUpResponse {
payUrl string `json:"payUrl"`
}
)
@server (
group: topup
prefix: /api/console/topupfmghnjx
middleware: AuthInterceptor,EntAuthInterceptor
)
service gateway-api {
@handler aliTopUp
post /aliTopUp (AliTopUpRequest) returns (AliTopUpResponse)
@handler aliTopUpCallback
post /aliTopUpCallback
}

View File

@@ -9,6 +9,7 @@ import (
auth "tianyuan-api/apps/gateway/internal/handler/auth"
base "tianyuan-api/apps/gateway/internal/handler/base"
product "tianyuan-api/apps/gateway/internal/handler/product"
topup "tianyuan-api/apps/gateway/internal/handler/topup"
user "tianyuan-api/apps/gateway/internal/handler/user"
userProduct "tianyuan-api/apps/gateway/internal/handler/userProduct"
whitelistr "tianyuan-api/apps/gateway/internal/handler/whitelistr"
@@ -79,6 +80,25 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
rest.WithPrefix("/api/console/product"),
)
server.AddRoutes(
rest.WithMiddlewares(
[]rest.Middleware{serverCtx.AuthInterceptor, serverCtx.EntAuthInterceptor},
[]rest.Route{
{
Method: http.MethodPost,
Path: "/aliTopUp",
Handler: topup.AliTopUpHandler(serverCtx),
},
{
Method: http.MethodPost,
Path: "/aliTopUpCallback",
Handler: topup.AliTopUpCallbackHandler(serverCtx),
},
}...,
),
rest.WithPrefix("/api/console/topupfmghnjx"),
)
server.AddRoutes(
rest.WithMiddlewares(
[]rest.Middleware{serverCtx.AuthInterceptor},
@@ -111,6 +131,20 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
server.AddRoutes(
rest.WithMiddlewares(
[]rest.Middleware{serverCtx.AuthInterceptor},
[]rest.Route{
{
Method: http.MethodGet,
Path: "/userProductList",
Handler: userProduct.GetUserProductListHandler(serverCtx),
},
}...,
),
rest.WithPrefix("/api/console/user-product"),
)
server.AddRoutes(
rest.WithMiddlewares(
[]rest.Middleware{serverCtx.AuthInterceptor, serverCtx.EntAuthInterceptor},
[]rest.Route{
{
Method: http.MethodPost,
@@ -122,11 +156,6 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
Path: "/userProductDel/:id",
Handler: userProduct.DeleteUserProductHandler(serverCtx),
},
{
Method: http.MethodGet,
Path: "/userProductList",
Handler: userProduct.GetUserProductListHandler(serverCtx),
},
}...,
),
rest.WithPrefix("/api/console/user-product"),

View File

@@ -0,0 +1,19 @@
package topup
import (
"github.com/smartwalle/alipay/v3"
"net/http"
"tianyuan-api/apps/gateway/internal/logic/topup"
"tianyuan-api/apps/gateway/internal/svc"
)
func AliTopUpCallbackHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
l := topup.NewAliTopUpCallbackLogic(r.Context(), svcCtx)
err := l.AliTopUpCallback(r)
if err != nil {
alipay.ACKNotification(w)
}
}
}

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 AliTopUpHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req types.AliTopUpRequest
if err := httpx.Parse(r, &req); err != nil {
xhttp.JsonBaseResponseCtx(r.Context(), w, err)
return
}
l := topup.NewAliTopUpLogic(r.Context(), svcCtx)
resp, err := l.AliTopUp(&req)
if err != nil {
xhttp.JsonBaseResponseCtx(r.Context(), w, err)
} else {
xhttp.JsonBaseResponseCtx(r.Context(), w, resp)
}
}
}

View File

@@ -0,0 +1,34 @@
package topup
import (
"context"
"net/http"
"tianyuan-api/apps/sentinel/sentinel"
"github.com/zeromicro/go-zero/core/logx"
"tianyuan-api/apps/gateway/internal/svc"
)
type AliTopUpCallbackLogic struct {
logx.Logger
ctx context.Context
svcCtx *svc.ServiceContext
}
func NewAliTopUpCallbackLogic(ctx context.Context, svcCtx *svc.ServiceContext) *AliTopUpCallbackLogic {
return &AliTopUpCallbackLogic{
Logger: logx.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
}
}
func (l *AliTopUpCallbackLogic) AliTopUpCallback(r *http.Request) error {
_, err := l.svcCtx.TopUpRpc.AliTopUpNotify(l.ctx, &sentinel.AliTopUpNotifyRequest{
RawForm: r.Form.Encode(),
})
if err != nil {
return err
}
return nil
}

View File

@@ -0,0 +1,40 @@
package topup
import (
"context"
"errors"
"tianyuan-api/apps/sentinel/sentinel"
"tianyuan-api/apps/gateway/internal/svc"
"tianyuan-api/apps/gateway/internal/types"
"github.com/zeromicro/go-zero/core/logx"
)
type AliTopUpLogic struct {
logx.Logger
ctx context.Context
svcCtx *svc.ServiceContext
}
func NewAliTopUpLogic(ctx context.Context, svcCtx *svc.ServiceContext) *AliTopUpLogic {
return &AliTopUpLogic{
Logger: logx.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
}
}
func (l *AliTopUpLogic) AliTopUp(req *types.AliTopUpRequest) (resp *types.AliTopUpResponse, err error) {
userId, ok := l.ctx.Value("userId").(int64)
if !ok {
return nil, errors.New("无法获取 userId")
}
up, err := l.svcCtx.TopUpRpc.AliTopUp(l.ctx, &sentinel.AliTopUpRequest{UserId: userId, Amount: req.Amount})
if err != nil {
return nil, err
}
return &types.AliTopUpResponse{
PayUrl: up.PayUrl,
}, nil
}

View File

@@ -22,6 +22,7 @@ type ServiceContext struct {
UserProductRpc sentinel.UserProductClient
WhitelistRpc sentinel.WhitelistClient
SecretRpc sentinel.SecretClient
TopUpRpc sentinel.TopUpClient
}
func NewServiceContext(c config.Config) *ServiceContext {
@@ -40,7 +41,7 @@ func NewServiceContext(c config.Config) *ServiceContext {
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,
@@ -53,5 +54,6 @@ func NewServiceContext(c config.Config) *ServiceContext {
UserProductRpc: userProductRpc,
WhitelistRpc: whitelistRpc,
SecretRpc: secretRpc,
TopUpRpc: topUpRpc,
}
}

View File

@@ -11,6 +11,14 @@ type AddWhitelistReq struct {
Ip string `json:"ip"`
}
type AliTopUpRequest struct {
Amount int64 `json:"amount"`
}
type AliTopUpResponse struct {
PayUrl string `json:"payUrl"`
}
type DeleteUserProductReq struct {
Id int64 `json:"id"`
}