fix:删除订单

This commit is contained in:
momo
2023-10-07 18:36:59 +08:00
parent e031f804f3
commit ae2c41364f
8 changed files with 215 additions and 14 deletions

View File

@@ -0,0 +1,35 @@
package handler
import (
"net/http"
"reflect"
"fusenapi/utils/basic"
"fusenapi/server/order/internal/logic"
"fusenapi/server/order/internal/svc"
"fusenapi/server/order/internal/types"
)
func DeleteOrderHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req types.DeleteOrderReq
userinfo, err := basic.RequestParse(w, r, svcCtx, &req)
if err != nil {
return
}
// 创建一个业务逻辑层实例
l := logic.NewDeleteOrderLogic(r.Context(), svcCtx)
rl := reflect.ValueOf(l)
basic.BeforeLogic(w, r, rl)
resp := l.DeleteOrder(&req, userinfo)
if !basic.AfterLogic(w, r, rl, resp) {
basic.NormalAfterLogic(w, r, resp)
}
}
}

View File

@@ -27,6 +27,11 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
Path: "/api/order/create-prepayment-balance",
Handler: CreatePrePaymentByBalanceHandler(serverCtx),
},
{
Method: http.MethodPost,
Path: "/api/order/delete",
Handler: DeleteOrderHandler(serverCtx),
},
{
Method: http.MethodGet,
Path: "/api/order/list",

View File

@@ -0,0 +1,55 @@
package logic
import (
"fusenapi/service/repositories"
"fusenapi/utils/auth"
"fusenapi/utils/basic"
"context"
"fusenapi/server/order/internal/svc"
"fusenapi/server/order/internal/types"
"github.com/zeromicro/go-zero/core/logx"
)
type DeleteOrderLogic struct {
logx.Logger
ctx context.Context
svcCtx *svc.ServiceContext
}
func NewDeleteOrderLogic(ctx context.Context, svcCtx *svc.ServiceContext) *DeleteOrderLogic {
return &DeleteOrderLogic{
Logger: logx.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
}
}
// 处理进入前逻辑w,r
// func (l *DeleteOrderLogic) BeforeLogic(w http.ResponseWriter, r *http.Request) {
// }
func (l *DeleteOrderLogic) DeleteOrder(req *types.DeleteOrderReq, userinfo *auth.UserInfo) (resp *basic.Response) {
// 返回值必须调用Set重新返回, resp可以空指针调用 resp.SetStatus(basic.CodeOK, data)
// userinfo 传入值时, 一定不为null
if !userinfo.IsUser() {
// 如果是,返回未授权的错误码
return resp.SetStatus(basic.CodeUnAuth)
}
res, err := l.svcCtx.Repositories.NewOrder.Delete(l.ctx, &repositories.DeleteReq{
UserId: userinfo.UserId,
OrderSn: req.OrderSn,
})
if err != nil {
return resp.SetStatus(&res.ErrorCode)
}
return resp.SetStatus(basic.CodeOK)
}
// 处理逻辑后 w,r 如:重定向, resp 必须重新处理
// func (l *DeleteOrderLogic) AfterLogic(w http.ResponseWriter, r *http.Request, resp *basic.Response) {
// // httpx.OkJsonCtx(r.Context(), w, resp)
// }

View File

@@ -5,6 +5,10 @@ import (
"fusenapi/utils/basic"
)
type DeleteOrderReq struct {
OrderSn string `json:"order_sn"`
}
type OrderDetailReq struct {
OrderSn string `form:"order_sn"`
}