fix:新增订单关闭
This commit is contained in:
parent
d2f24772ca
commit
634f1b9584
35
server/order/internal/handler/closeorderhandler.go
Normal file
35
server/order/internal/handler/closeorderhandler.go
Normal 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 CloseOrderHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||||
|
return func(w http.ResponseWriter, r *http.Request) {
|
||||||
|
|
||||||
|
var req types.CloseOrderReq
|
||||||
|
userinfo, err := basic.RequestParse(w, r, svcCtx, &req)
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// 创建一个业务逻辑层实例
|
||||||
|
l := logic.NewCloseOrderLogic(r.Context(), svcCtx)
|
||||||
|
|
||||||
|
rl := reflect.ValueOf(l)
|
||||||
|
basic.BeforeLogic(w, r, rl)
|
||||||
|
|
||||||
|
resp := l.CloseOrder(&req, userinfo)
|
||||||
|
|
||||||
|
if !basic.AfterLogic(w, r, rl, resp) {
|
||||||
|
basic.NormalAfterLogic(w, r, resp)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -32,6 +32,11 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
|
|||||||
Path: "/api/order/delete",
|
Path: "/api/order/delete",
|
||||||
Handler: DeleteOrderHandler(serverCtx),
|
Handler: DeleteOrderHandler(serverCtx),
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
Method: http.MethodPost,
|
||||||
|
Path: "/api/order/close",
|
||||||
|
Handler: CloseOrderHandler(serverCtx),
|
||||||
|
},
|
||||||
{
|
{
|
||||||
Method: http.MethodGet,
|
Method: http.MethodGet,
|
||||||
Path: "/api/order/list",
|
Path: "/api/order/list",
|
||||||
|
56
server/order/internal/logic/closeorderlogic.go
Normal file
56
server/order/internal/logic/closeorderlogic.go
Normal file
@ -0,0 +1,56 @@
|
|||||||
|
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 CloseOrderLogic struct {
|
||||||
|
logx.Logger
|
||||||
|
ctx context.Context
|
||||||
|
svcCtx *svc.ServiceContext
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewCloseOrderLogic(ctx context.Context, svcCtx *svc.ServiceContext) *CloseOrderLogic {
|
||||||
|
return &CloseOrderLogic{
|
||||||
|
Logger: logx.WithContext(ctx),
|
||||||
|
ctx: ctx,
|
||||||
|
svcCtx: svcCtx,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 处理进入前逻辑w,r
|
||||||
|
// func (l *CloseOrderLogic) BeforeLogic(w http.ResponseWriter, r *http.Request) {
|
||||||
|
// }
|
||||||
|
|
||||||
|
func (l *CloseOrderLogic) CloseOrder(req *types.CloseOrderReq, 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.Close(l.ctx, &repositories.CloseReq{
|
||||||
|
UserId: userinfo.UserId,
|
||||||
|
OrderSn: req.OrderSn,
|
||||||
|
Type: 1,
|
||||||
|
})
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
return resp.SetStatus(&res.ErrorCode)
|
||||||
|
}
|
||||||
|
return resp.SetStatus(basic.CodeOK)
|
||||||
|
}
|
||||||
|
|
||||||
|
// 处理逻辑后 w,r 如:重定向, resp 必须重新处理
|
||||||
|
// func (l *CloseOrderLogic) AfterLogic(w http.ResponseWriter, r *http.Request, resp *basic.Response) {
|
||||||
|
// // httpx.OkJsonCtx(r.Context(), w, resp)
|
||||||
|
// }
|
@ -5,6 +5,10 @@ import (
|
|||||||
"fusenapi/utils/basic"
|
"fusenapi/utils/basic"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
type CloseOrderReq struct {
|
||||||
|
OrderSn string `json:"order_sn"`
|
||||||
|
}
|
||||||
|
|
||||||
type DeleteOrderReq struct {
|
type DeleteOrderReq struct {
|
||||||
OrderSn string `json:"order_sn"`
|
OrderSn string `json:"order_sn"`
|
||||||
}
|
}
|
||||||
|
@ -23,6 +23,9 @@ service order {
|
|||||||
@handler DeleteOrderHandler
|
@handler DeleteOrderHandler
|
||||||
post /api/order/delete(DeleteOrderReq) returns (response);
|
post /api/order/delete(DeleteOrderReq) returns (response);
|
||||||
|
|
||||||
|
@handler CloseOrderHandler
|
||||||
|
post /api/order/close(CloseOrderReq) returns (response);
|
||||||
|
|
||||||
@handler OrderListHandler
|
@handler OrderListHandler
|
||||||
get /api/order/list(OrderListReq) returns (response);
|
get /api/order/list(OrderListReq) returns (response);
|
||||||
|
|
||||||
@ -31,6 +34,12 @@ service order {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type (
|
||||||
|
CloseOrderReq {
|
||||||
|
OrderSn string `json:"order_sn"`
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
type DeleteOrderReq {
|
type DeleteOrderReq {
|
||||||
OrderSn string `json:"order_sn"`
|
OrderSn string `json:"order_sn"`
|
||||||
}
|
}
|
||||||
|
@ -108,6 +108,7 @@ type (
|
|||||||
CloseReq struct {
|
CloseReq struct {
|
||||||
Type int64 // type:1=添加购物车
|
Type int64 // type:1=添加购物车
|
||||||
OrderSn string
|
OrderSn string
|
||||||
|
UserId int64 `json:"user_id"`
|
||||||
}
|
}
|
||||||
CloseRes struct {
|
CloseRes struct {
|
||||||
ErrorCode basic.StatusResponse
|
ErrorCode basic.StatusResponse
|
||||||
@ -342,6 +343,9 @@ func (d *defaultOrder) Close(ctx context.Context, in *CloseReq) (res *CloseRes,
|
|||||||
err = d.MysqlConn.WithContext(ctx).Transaction(func(tx *gorm.DB) error {
|
err = d.MysqlConn.WithContext(ctx).Transaction(func(tx *gorm.DB) error {
|
||||||
var orderInfo gmodel.FsOrder
|
var orderInfo gmodel.FsOrder
|
||||||
model := tx.Where("status = ?", int64(constants.ORDER_STATUS_UNPAIDDEPOSIT)).Where("pay_status = ?", int(constants.ORDER_PAY_STATUS_UNPAIDDEPOSIT))
|
model := tx.Where("status = ?", int64(constants.ORDER_STATUS_UNPAIDDEPOSIT)).Where("pay_status = ?", int(constants.ORDER_PAY_STATUS_UNPAIDDEPOSIT))
|
||||||
|
if in.UserId != 0 {
|
||||||
|
model = model.Where("user_id = ?", in.UserId)
|
||||||
|
}
|
||||||
if in.OrderSn != "" {
|
if in.OrderSn != "" {
|
||||||
model = model.Where("order_sn = ?", in.OrderSn)
|
model = model.Where("order_sn = ?", in.OrderSn)
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user