Merge branch 'develop' of https://gitee.com/fusenpack/fusenapi into develop
This commit is contained in:
35
server/order/internal/handler/orderdetailhandler.go
Normal file
35
server/order/internal/handler/orderdetailhandler.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 OrderDetailHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
var req types.OrderDetailReq
|
||||
userinfo, err := basic.RequestParse(w, r, svcCtx, &req)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
// 创建一个业务逻辑层实例
|
||||
l := logic.NewOrderDetailLogic(r.Context(), svcCtx)
|
||||
|
||||
rl := reflect.ValueOf(l)
|
||||
basic.BeforeLogic(w, r, rl)
|
||||
|
||||
resp := l.OrderDetail(&req, userinfo)
|
||||
|
||||
if !basic.AfterLogic(w, r, rl, resp) {
|
||||
basic.NormalAfterLogic(w, r, resp)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -23,10 +23,15 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
|
||||
Handler: CreatePrePaymentDepositHandler(serverCtx),
|
||||
},
|
||||
{
|
||||
Method: http.MethodPost,
|
||||
Method: http.MethodGet,
|
||||
Path: "/api/order/list",
|
||||
Handler: OrderListHandler(serverCtx),
|
||||
},
|
||||
{
|
||||
Method: http.MethodGet,
|
||||
Path: "/api/order/detail",
|
||||
Handler: OrderDetailHandler(serverCtx),
|
||||
},
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
@@ -36,7 +36,7 @@ func NewCreateOrderLogic(ctx context.Context, svcCtx *svc.ServiceContext) *Creat
|
||||
func (l *CreateOrderLogic) CreateOrder(req *types.CreateOrderReq, userinfo *auth.UserInfo) (resp *basic.Response) {
|
||||
// 返回值必须调用Set重新返回, resp可以空指针调用 resp.SetStatus(basic.CodeOK, data)
|
||||
// userinfo 传入值时, 一定不为null
|
||||
if userinfo.IsUser() {
|
||||
if !userinfo.IsUser() {
|
||||
// 如果是,返回未授权的错误码
|
||||
return resp.SetStatus(basic.CodeUnAuth)
|
||||
}
|
||||
@@ -54,7 +54,9 @@ func (l *CreateOrderLogic) CreateOrder(req *types.CreateOrderReq, userinfo *auth
|
||||
return resp.SetStatus(&res.ErrorCode)
|
||||
}
|
||||
|
||||
return resp.SetStatus(basic.CodeOK)
|
||||
return resp.SetStatus(basic.CodeOK, map[string]interface{}{
|
||||
"order_sn": res.OrderSn,
|
||||
})
|
||||
}
|
||||
|
||||
// 处理逻辑后 w,r 如:重定向, resp 必须重新处理
|
||||
|
||||
57
server/order/internal/logic/orderdetaillogic.go
Normal file
57
server/order/internal/logic/orderdetaillogic.go
Normal file
@@ -0,0 +1,57 @@
|
||||
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 OrderDetailLogic struct {
|
||||
logx.Logger
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
}
|
||||
|
||||
func NewOrderDetailLogic(ctx context.Context, svcCtx *svc.ServiceContext) *OrderDetailLogic {
|
||||
return &OrderDetailLogic{
|
||||
Logger: logx.WithContext(ctx),
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
}
|
||||
}
|
||||
|
||||
// 处理进入前逻辑w,r
|
||||
// func (l *OrderDetailLogic) BeforeLogic(w http.ResponseWriter, r *http.Request) {
|
||||
// }
|
||||
|
||||
func (l *OrderDetailLogic) OrderDetail(req *types.OrderDetailReq, 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.Detail(l.ctx, &repositories.DetailReq{
|
||||
OrderSn: req.OrderSn,
|
||||
UserId: userinfo.UserId,
|
||||
})
|
||||
if err != nil {
|
||||
return resp.SetStatus(basic.CodeApiErr)
|
||||
}
|
||||
|
||||
return resp.SetStatus(basic.CodeOK, map[string]interface{}{
|
||||
"order_detail": res,
|
||||
})
|
||||
}
|
||||
|
||||
// 处理逻辑后 w,r 如:重定向, resp 必须重新处理
|
||||
// func (l *OrderDetailLogic) AfterLogic(w http.ResponseWriter, r *http.Request, resp *basic.Response) {
|
||||
// // httpx.OkJsonCtx(r.Context(), w, resp)
|
||||
// }
|
||||
@@ -5,6 +5,10 @@ import (
|
||||
"fusenapi/utils/basic"
|
||||
)
|
||||
|
||||
type OrderDetailReq struct {
|
||||
OrderSn string `form:"order_sn"`
|
||||
}
|
||||
|
||||
type CreateOrderReq struct {
|
||||
CartIds []int64 `json:"cart_ids"`
|
||||
DeliveryMethod int64 `json:"delivery_method,options=[1,2]"`
|
||||
|
||||
@@ -208,6 +208,7 @@ func (l *GetCartsLogic) GetCarts(req *types.GetCartsReq, userinfo *auth.UserInfo
|
||||
IsInvalid: false,
|
||||
InvalidDescription: "",
|
||||
IsHighlyCustomized: *cart.IsHighlyCustomized > 0,
|
||||
IsSelected: *cart.IsSelected > 0,
|
||||
}
|
||||
//是否有失效的
|
||||
if description, ok := mapCartChange[cart.Id]; ok {
|
||||
|
||||
@@ -52,6 +52,7 @@ type CartItem struct {
|
||||
IsHighlyCustomized bool `json:"is_highly_customized"` //是否高度定制
|
||||
IsInvalid bool `json:"is_invalid"` //是否无效
|
||||
InvalidDescription string `json:"invalid_description"` //无效原因
|
||||
IsSelected bool `json:"is_selected"` //是否选中
|
||||
}
|
||||
|
||||
type ProductInfo struct {
|
||||
|
||||
7
server/shopping-cart/order_test.go
Normal file
7
server/shopping-cart/order_test.go
Normal file
@@ -0,0 +1,7 @@
|
||||
package main
|
||||
|
||||
import "testing"
|
||||
|
||||
func TestMain(t *testing.T) {
|
||||
main()
|
||||
}
|
||||
Reference in New Issue
Block a user