Merge branch 'develop' of gitee.com:fusenpack/fusenapi into develop
This commit is contained in:
commit
8a1209c6f0
|
@ -10,9 +10,9 @@ import (
|
|||
"fusenapi/utils/auth"
|
||||
"fusenapi/utils/basic"
|
||||
|
||||
"fusenapi/server/orders/internal/logic"
|
||||
"fusenapi/server/orders/internal/svc"
|
||||
"fusenapi/server/orders/internal/types"
|
||||
"fusenapi/server/home-user-auth/internal/logic"
|
||||
"fusenapi/server/home-user-auth/internal/svc"
|
||||
"fusenapi/server/home-user-auth/internal/types"
|
||||
)
|
||||
|
||||
func GetUserOrderListHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
|
@ -72,6 +72,16 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
|
|||
Path: "/api/user/oauth2/login/google",
|
||||
Handler: UserGoogleLoginHandler(serverCtx),
|
||||
},
|
||||
{
|
||||
Method: http.MethodGet,
|
||||
Path: "/api/user/order-list",
|
||||
Handler: GetUserOrderListHandler(serverCtx),
|
||||
},
|
||||
{
|
||||
Method: http.MethodGet,
|
||||
Path: "/api/user/order-cancel",
|
||||
Handler: UserOrderCancelHandler(serverCtx),
|
||||
},
|
||||
},
|
||||
)
|
||||
}
|
||||
|
|
|
@ -0,0 +1,78 @@
|
|||
package handler
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"net/http"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
"github.com/zeromicro/go-zero/rest/httpx"
|
||||
|
||||
"fusenapi/utils/auth"
|
||||
"fusenapi/utils/basic"
|
||||
|
||||
"fusenapi/server/home-user-auth/internal/logic"
|
||||
"fusenapi/server/home-user-auth/internal/svc"
|
||||
"fusenapi/server/home-user-auth/internal/types"
|
||||
)
|
||||
|
||||
func UserOrderCancelHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
var (
|
||||
// 定义错误变量
|
||||
err error
|
||||
// 定义用户信息变量
|
||||
userinfo *auth.UserInfo
|
||||
)
|
||||
// 解析JWT token,并对空用户进行判断
|
||||
claims, err := svcCtx.ParseJwtToken(r)
|
||||
// 如果解析JWT token出错,则返回未授权的JSON响应并记录错误消息
|
||||
if err != nil {
|
||||
httpx.OkJsonCtx(r.Context(), w, &basic.Response{
|
||||
Code: 401, // 返回401状态码,表示未授权
|
||||
Message: "unauthorized", // 返回未授权信息
|
||||
})
|
||||
logx.Info("unauthorized:", err.Error()) // 记录错误日志
|
||||
return
|
||||
}
|
||||
|
||||
if claims != nil {
|
||||
// 从token中获取对应的用户信息
|
||||
userinfo, err = auth.GetUserInfoFormMapClaims(claims)
|
||||
// 如果获取用户信息出错,则返回未授权的JSON响应并记录错误消息
|
||||
if err != nil {
|
||||
httpx.OkJsonCtx(r.Context(), w, &basic.Response{
|
||||
Code: 401,
|
||||
Message: "unauthorized",
|
||||
})
|
||||
logx.Info("unauthorized:", err.Error())
|
||||
return
|
||||
}
|
||||
} else {
|
||||
// 如果claims为nil,则认为用户身份为白板用户
|
||||
userinfo = &auth.UserInfo{UserId: 0, GuestId: 0}
|
||||
}
|
||||
|
||||
var req types.UserOrderCancelReq
|
||||
// 如果端点有请求结构体,则使用httpx.Parse方法从HTTP请求体中解析请求数据
|
||||
if err := httpx.Parse(r, &req); err != nil {
|
||||
httpx.OkJsonCtx(r.Context(), w, &basic.Response{
|
||||
Code: 510,
|
||||
Message: "parameter error",
|
||||
})
|
||||
logx.Info(err)
|
||||
return
|
||||
}
|
||||
// 创建一个业务逻辑层实例
|
||||
l := logic.NewUserOrderCancelLogic(r.Context(), svcCtx)
|
||||
resp := l.UserOrderCancel(&req, userinfo)
|
||||
// 如果响应不为nil,则使用httpx.OkJsonCtx方法返回JSON响应;
|
||||
if resp != nil {
|
||||
httpx.OkJsonCtx(r.Context(), w, resp)
|
||||
} else {
|
||||
err := errors.New("server logic is error, resp must not be nil")
|
||||
httpx.ErrorCtx(r.Context(), w, err)
|
||||
logx.Error(err)
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,7 +1,6 @@
|
|||
package logic
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fusenapi/constants"
|
||||
"fusenapi/model/gmodel"
|
||||
|
@ -10,8 +9,10 @@ import (
|
|||
"fusenapi/utils/format"
|
||||
"math"
|
||||
|
||||
"fusenapi/server/orders/internal/svc"
|
||||
"fusenapi/server/orders/internal/types"
|
||||
"context"
|
||||
|
||||
"fusenapi/server/home-user-auth/internal/svc"
|
||||
"fusenapi/server/home-user-auth/internal/types"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
"gorm.io/gorm"
|
||||
|
@ -34,6 +35,7 @@ func NewGetUserOrderListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *
|
|||
func (l *GetUserOrderListLogic) GetUserOrderList(req *types.GetUserOrderListReq, userinfo *auth.UserInfo) (resp *basic.Response) {
|
||||
// 返回值必须调用Set重新返回, resp可以空指针调用 resp.SetStatus(basic.CodeOK, data)
|
||||
// userinfo 传入值时, 一定不为null
|
||||
|
||||
orderDetailModel := gmodel.NewFsOrderDetailModel(l.svcCtx.MysqlConn)
|
||||
orderModel := gmodel.NewFsOrderModel(l.svcCtx.MysqlConn)
|
||||
rowBuilder := orderModel.RowSelectBuilder(nil)
|
60
server/home-user-auth/internal/logic/userordercancellogic.go
Normal file
60
server/home-user-auth/internal/logic/userordercancellogic.go
Normal file
|
@ -0,0 +1,60 @@
|
|||
package logic
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fusenapi/constants"
|
||||
"fusenapi/model/gmodel"
|
||||
"fusenapi/utils/auth"
|
||||
"fusenapi/utils/basic"
|
||||
|
||||
"context"
|
||||
|
||||
"fusenapi/server/home-user-auth/internal/svc"
|
||||
"fusenapi/server/home-user-auth/internal/types"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
type UserOrderCancelLogic struct {
|
||||
logx.Logger
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
}
|
||||
|
||||
func NewUserOrderCancelLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UserOrderCancelLogic {
|
||||
return &UserOrderCancelLogic{
|
||||
Logger: logx.WithContext(ctx),
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
}
|
||||
}
|
||||
|
||||
func (l *UserOrderCancelLogic) UserOrderCancel(req *types.UserOrderCancelReq, userinfo *auth.UserInfo) (resp *basic.Response) {
|
||||
// 返回值必须调用Set重新返回, resp可以空指针调用 resp.SetStatus(basic.CodeOK, data)
|
||||
// userinfo 传入值时, 一定不为null
|
||||
|
||||
if userinfo == nil || userinfo.UserId == 0 {
|
||||
return resp.SetStatusWithMessage(basic.CodeDbRecordNotFoundErr, "order not found")
|
||||
}
|
||||
|
||||
//查询订单信息
|
||||
orderModel := gmodel.NewFsOrderModel(l.svcCtx.MysqlConn)
|
||||
orderInfo, err := orderModel.FindOne(l.ctx, userinfo.UserId, req.ID)
|
||||
if err != nil {
|
||||
if errors.Is(err, gorm.ErrRecordNotFound) {
|
||||
return resp.SetStatusWithMessage(basic.CodeDbRecordNotFoundErr, "the order is not exists")
|
||||
}
|
||||
logx.Error(err)
|
||||
return resp.SetStatus(basic.CodeServiceErr, "failed to get order info")
|
||||
}
|
||||
|
||||
// 判断订单状态
|
||||
if *orderInfo.Status == int64(constants.STATUS_NEW_NOT_PAY) {
|
||||
|
||||
} else {
|
||||
return resp.SetStatusWithMessage(basic.CodeOrderNotCancelledErr, "the order status not cancle")
|
||||
}
|
||||
|
||||
return resp.SetStatus(basic.CodeOK)
|
||||
}
|
|
@ -5,6 +5,70 @@ import (
|
|||
"fusenapi/utils/basic"
|
||||
)
|
||||
|
||||
type UserOrderCancelReq struct {
|
||||
ID int64 `form:"id"` //订单id
|
||||
RefundReasonId int64 `form:"refund_reason_id"` //退款配置id
|
||||
RefundReason string `form:"refund_reason,optional"` //退款原因
|
||||
}
|
||||
|
||||
type UserOrderCancelRsp struct {
|
||||
}
|
||||
|
||||
type GetUserOrderListReq struct {
|
||||
Page int64 `form:"page"` // 分页
|
||||
PageSize int64 `form:"page_size"` // 每页数量
|
||||
Status int64 `form:"status"` // 状态筛选
|
||||
Time int64 `form:"time"` // 时间筛选
|
||||
Total int64 `form:"total"` // 总数
|
||||
Size int64 `form:"size"` // 图片尺寸
|
||||
}
|
||||
|
||||
type GetUserOrderListRsp struct {
|
||||
Items []Items `json:"items"`
|
||||
Meta Meta `json:"_meta"`
|
||||
}
|
||||
|
||||
type Items struct {
|
||||
ID int64 `json:"id"`
|
||||
Sn string `json:"sn"`
|
||||
UserID int64 `json:"user_id"`
|
||||
TotalAmount int64 `json:"total_amount"`
|
||||
Ctime string `json:"ctime"`
|
||||
Status int64 `json:"status"`
|
||||
DeliveryMethod int64 `json:"delivery_method"`
|
||||
TsTime string `json:"ts_time"`
|
||||
IsPayCompleted int64 `json:"is_pay_completed"`
|
||||
DeliverSn string `json:"deliver_sn"`
|
||||
PcsBox int64 `json:"pcs_box"`
|
||||
Pcs int64 `json:"pcs"`
|
||||
SurplusAt int64 `json:"surplus_at"`
|
||||
LogisticsStatus int64 `json:"logistics_status"`
|
||||
StatusTimes []*StatusTime `json:"status_times"`
|
||||
Deposit int64 `json:"deposit"`
|
||||
Remaining int64 `json:"remaining"`
|
||||
ProductList []*Product `json:"productList"`
|
||||
IsStop int64 `json:"is_stop"`
|
||||
}
|
||||
|
||||
type StatusTime struct {
|
||||
Key int `json:"key"`
|
||||
Time string `json:"time"`
|
||||
}
|
||||
|
||||
type Product struct {
|
||||
Cover string `json:"cover"`
|
||||
Fitting string `json:"fitting"`
|
||||
OptionPrice int64 `json:"option_price"`
|
||||
OrderDetailTemplateId int64 `json:"order_detail_template_id"`
|
||||
OrderId int64 `json:"order_id"`
|
||||
Pcs int64 `json:"pcs"`
|
||||
PcsBox int64 `json:"pcs_box"`
|
||||
Price int64 `json:"price"`
|
||||
ProductId int64 `json:"product_id"`
|
||||
Size string `json:"size"`
|
||||
Title string `json:"title"`
|
||||
}
|
||||
|
||||
type RequestGoogleLogin struct {
|
||||
Code string `form:"code"`
|
||||
Scope string `form:"scope"`
|
||||
|
|
|
@ -22,11 +22,6 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
|
|||
Path: "/api/order/detail",
|
||||
Handler: GetOrderDetailHandler(serverCtx),
|
||||
},
|
||||
{
|
||||
Method: http.MethodGet,
|
||||
Path: "/api/user/order-list",
|
||||
Handler: GetUserOrderListHandler(serverCtx),
|
||||
},
|
||||
},
|
||||
)
|
||||
}
|
||||
|
|
|
@ -76,47 +76,6 @@ type Deposit struct {
|
|||
TransNo string `json:"trans_no"`
|
||||
}
|
||||
|
||||
type GetUserOrderListReq struct {
|
||||
Page int64 `form:"page"` // 分页
|
||||
PageSize int64 `form:"page_size"` // 每页数量
|
||||
Status int64 `form:"status"` // 状态筛选
|
||||
Time int64 `form:"time"` // 时间筛选
|
||||
Total int64 `form:"total"` // 总数
|
||||
Size int64 `form:"size"` // 图片尺寸
|
||||
}
|
||||
|
||||
type GetUserOrderListRsp struct {
|
||||
Items []Items `json:"items"`
|
||||
Meta Meta `json:"_meta"`
|
||||
}
|
||||
|
||||
type StatusTime struct {
|
||||
Key int `json:"key"`
|
||||
Time string `json:"time"`
|
||||
}
|
||||
|
||||
type Items struct {
|
||||
ID int64 `json:"id"`
|
||||
Sn string `json:"sn"`
|
||||
UserID int64 `json:"user_id"`
|
||||
TotalAmount int64 `json:"total_amount"`
|
||||
Ctime string `json:"ctime"`
|
||||
Status int64 `json:"status"`
|
||||
DeliveryMethod int64 `json:"delivery_method"`
|
||||
TsTime string `json:"ts_time"`
|
||||
IsPayCompleted int64 `json:"is_pay_completed"`
|
||||
DeliverSn string `json:"deliver_sn"`
|
||||
PcsBox int64 `json:"pcs_box"`
|
||||
Pcs int64 `json:"pcs"`
|
||||
SurplusAt int64 `json:"surplus_at"`
|
||||
LogisticsStatus int64 `json:"logistics_status"`
|
||||
StatusTimes []*StatusTime `json:"status_times"`
|
||||
Deposit int64 `json:"deposit"`
|
||||
Remaining int64 `json:"remaining"`
|
||||
ProductList []*Product `json:"productList"`
|
||||
IsStop int64 `json:"is_stop"`
|
||||
}
|
||||
|
||||
type Request struct {
|
||||
}
|
||||
|
||||
|
|
|
@ -10,49 +10,126 @@ info (
|
|||
import "basic.api"
|
||||
|
||||
service home-user-auth {
|
||||
|
||||
|
||||
// @handler UserRegisterHandler
|
||||
// post /api/user/register(RequestUserRegister) returns (response);
|
||||
|
||||
|
||||
@handler UserLoginHandler
|
||||
post /api/user/login(RequestUserLogin) returns (response);
|
||||
|
||||
|
||||
@handler AcceptCookieHandler
|
||||
post /api/user/accept-cookie(request) returns (response);
|
||||
|
||||
|
||||
@handler UserFontsHandler
|
||||
get /api/user/fonts(request) returns (response);
|
||||
|
||||
|
||||
@handler UserGetTypeHandler
|
||||
get /api/user/get-type(request) returns (response);
|
||||
|
||||
|
||||
@handler UserSaveBasicInfoHandler
|
||||
post /api/user/basic-info(RequestBasicInfoForm) returns (response);
|
||||
|
||||
|
||||
@handler UserStatusConfigHandler
|
||||
get /api/user/status-config(request) returns (response);
|
||||
|
||||
|
||||
@handler UserBasicInfoHandler
|
||||
get /api/user/basic-info(request) returns (response);
|
||||
|
||||
|
||||
@handler UserAddressListHandler
|
||||
get /api/user/address-list(request) returns (response);
|
||||
|
||||
|
||||
@handler UserAddAddressHandler
|
||||
post /api/user/add-address(RequestAddAddress) returns (response);
|
||||
|
||||
|
||||
@handler UserContactServiceHandler
|
||||
post /api/user/contact-service (RequestContactService) returns (response);
|
||||
|
||||
|
||||
// @handler UserOderListHandler
|
||||
// get /api/user/order-list(RequestOrderId) returns (response);
|
||||
|
||||
|
||||
@handler UserOderDeleteHandler
|
||||
post /api/user/order-delete(RequestOrderId) returns (response);
|
||||
|
||||
|
||||
@handler UserGoogleLoginHandler
|
||||
get /api/user/oauth2/login/google(RequestGoogleLogin) returns (response);
|
||||
|
||||
|
||||
//获取订单列表
|
||||
@handler GetUserOrderListHandler
|
||||
get /api/user/order-list (GetUserOrderListReq) returns (response);
|
||||
|
||||
//取消订单
|
||||
@handler UserOrderCancelHandler
|
||||
get /api/user/order-cancel (UserOrderCancelReq) returns (response);
|
||||
|
||||
}
|
||||
|
||||
//取消订单
|
||||
type (
|
||||
UserOrderCancelReq {
|
||||
ID int64 `form:"id"` //订单id
|
||||
RefundReasonId int64 `form:"refund_reason_id"` //退款配置id
|
||||
RefundReason string `form:"refund_reason,optional"` //退款原因
|
||||
}
|
||||
UserOrderCancelRsp {
|
||||
}
|
||||
)
|
||||
|
||||
// 获取订单列表
|
||||
type (
|
||||
GetUserOrderListReq {
|
||||
Page int64 `form:"page"` // 分页
|
||||
PageSize int64 `form:"page_size"` // 每页数量
|
||||
Status int64 `form:"status"` // 状态筛选
|
||||
Time int64 `form:"time"` // 时间筛选
|
||||
Total int64 `form:"total"` // 总数
|
||||
Size int64 `form:"size"` // 图片尺寸
|
||||
}
|
||||
|
||||
GetUserOrderListRsp {
|
||||
Items []Items `json:"items"`
|
||||
Meta Meta `json:"_meta"`
|
||||
}
|
||||
)
|
||||
|
||||
type Items {
|
||||
ID int64 `json:"id"`
|
||||
Sn string `json:"sn"`
|
||||
UserID int64 `json:"user_id"`
|
||||
TotalAmount int64 `json:"total_amount"`
|
||||
Ctime string `json:"ctime"`
|
||||
Status int64 `json:"status"`
|
||||
DeliveryMethod int64 `json:"delivery_method"`
|
||||
TsTime string `json:"ts_time"`
|
||||
IsPayCompleted int64 `json:"is_pay_completed"`
|
||||
DeliverSn string `json:"deliver_sn"`
|
||||
PcsBox int64 `json:"pcs_box"`
|
||||
Pcs int64 `json:"pcs"`
|
||||
SurplusAt int64 `json:"surplus_at"`
|
||||
LogisticsStatus int64 `json:"logistics_status"`
|
||||
StatusTimes []*StatusTime `json:"status_times"`
|
||||
Deposit int64 `json:"deposit"`
|
||||
Remaining int64 `json:"remaining"`
|
||||
ProductList []*Product `json:"productList"`
|
||||
IsStop int64 `json:"is_stop"`
|
||||
}
|
||||
|
||||
type StatusTime {
|
||||
Key int `json:"key"`
|
||||
Time string `json:"time"`
|
||||
}
|
||||
|
||||
type Product {
|
||||
Cover string `json:"cover"`
|
||||
Fitting string `json:"fitting"`
|
||||
OptionPrice int64 `json:"option_price"`
|
||||
OrderDetailTemplateId int64 `json:"order_detail_template_id"`
|
||||
OrderId int64 `json:"order_id"`
|
||||
Pcs int64 `json:"pcs"`
|
||||
PcsBox int64 `json:"pcs_box"`
|
||||
Price int64 `json:"price"`
|
||||
ProductId int64 `json:"product_id"`
|
||||
Size string `json:"size"`
|
||||
Title string `json:"title"`
|
||||
}
|
||||
|
||||
type RequestGoogleLogin {
|
||||
|
|
|
@ -16,10 +16,6 @@ service orders {
|
|||
//获取订单详情
|
||||
@handler GetOrderDetailHandler
|
||||
get /api/order/detail (GetOrderDetailReq) returns (response);
|
||||
|
||||
//获取订单列表
|
||||
@handler GetUserOrderListHandler
|
||||
get /api/user/order-list (GetUserOrderListReq) returns (response);
|
||||
}
|
||||
|
||||
//获取订单发票
|
||||
|
@ -86,48 +82,4 @@ type PayInfo {
|
|||
type Deposit {
|
||||
Method string `json:"method"`
|
||||
TransNo string `json:"trans_no"`
|
||||
}
|
||||
|
||||
// 获取订单列表
|
||||
type (
|
||||
GetUserOrderListReq {
|
||||
Page int64 `form:"page"` // 分页
|
||||
PageSize int64 `form:"page_size"` // 每页数量
|
||||
Status int64 `form:"status"` // 状态筛选
|
||||
Time int64 `form:"time"` // 时间筛选
|
||||
Total int64 `form:"total"` // 总数
|
||||
Size int64 `form:"size"` // 图片尺寸
|
||||
}
|
||||
|
||||
GetUserOrderListRsp {
|
||||
Items []Items `json:"items"`
|
||||
Meta Meta `json:"_meta"`
|
||||
}
|
||||
)
|
||||
|
||||
type StatusTime {
|
||||
Key int `json:"key"`
|
||||
Time string `json:"time"`
|
||||
}
|
||||
|
||||
type Items {
|
||||
ID int64 `json:"id"`
|
||||
Sn string `json:"sn"`
|
||||
UserID int64 `json:"user_id"`
|
||||
TotalAmount int64 `json:"total_amount"`
|
||||
Ctime string `json:"ctime"`
|
||||
Status int64 `json:"status"`
|
||||
DeliveryMethod int64 `json:"delivery_method"`
|
||||
TsTime string `json:"ts_time"`
|
||||
IsPayCompleted int64 `json:"is_pay_completed"`
|
||||
DeliverSn string `json:"deliver_sn"`
|
||||
PcsBox int64 `json:"pcs_box"`
|
||||
Pcs int64 `json:"pcs"`
|
||||
SurplusAt int64 `json:"surplus_at"`
|
||||
LogisticsStatus int64 `json:"logistics_status"`
|
||||
StatusTimes []*StatusTime `json:"status_times"`
|
||||
Deposit int64 `json:"deposit"`
|
||||
Remaining int64 `json:"remaining"`
|
||||
ProductList []*Product `json:"productList"`
|
||||
IsStop int64 `json:"is_stop"`
|
||||
}
|
Loading…
Reference in New Issue
Block a user