temp
This commit is contained in:
parent
776a8c244d
commit
a0d94f19c2
@ -114,8 +114,8 @@ service main {
|
|||||||
|
|
||||||
type (
|
type (
|
||||||
QueryGenerateShareLinkReq {
|
QueryGenerateShareLinkReq {
|
||||||
OrderId int64 `json:"order_id,optional"`
|
OrderId *int64 `json:"order_id,optional"`
|
||||||
OrderNo string `json:"order_no,optional"`
|
OrderNo *string `json:"order_no,optional"`
|
||||||
}
|
}
|
||||||
QueryGenerateShareLinkResp {
|
QueryGenerateShareLinkResp {
|
||||||
ShareLink string `json:"share_link"`
|
ShareLink string `json:"share_link"`
|
||||||
|
@ -38,14 +38,23 @@ func (l *QueryGenerateShareLinkLogic) QueryGenerateShareLink(req *types.QueryGen
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 检查参数
|
// 检查参数
|
||||||
if req.OrderId == 0 && req.OrderNo == "" {
|
if (req.OrderId == nil || *req.OrderId == 0) && (req.OrderNo == nil || *req.OrderNo == "") {
|
||||||
return nil, errors.Wrapf(xerr.NewErrMsg("订单ID和订单号不能同时为空"), "")
|
return nil, errors.Wrapf(xerr.NewErrMsg("订单ID和订单号不能同时为空"), "")
|
||||||
}
|
}
|
||||||
|
|
||||||
var order *model.Order
|
var order *model.Order
|
||||||
// 优先使用OrderId查询
|
// 优先使用OrderId查询
|
||||||
if req.OrderId != 0 {
|
if req.OrderId != nil && *req.OrderId != 0 {
|
||||||
order, err = l.svcCtx.OrderModel.FindOne(l.ctx, req.OrderId)
|
order, err = l.svcCtx.OrderModel.FindOne(l.ctx, *req.OrderId)
|
||||||
|
if err != nil {
|
||||||
|
if errors.Is(err, model.ErrNotFound) {
|
||||||
|
return nil, errors.Wrapf(xerr.NewErrMsg("订单不存在"), "")
|
||||||
|
}
|
||||||
|
return nil, errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "生成分享链接, 获取订单失败: %v", err)
|
||||||
|
}
|
||||||
|
} else if req.OrderNo != nil && *req.OrderNo != "" {
|
||||||
|
// 使用OrderNo查询
|
||||||
|
order, err = l.svcCtx.OrderModel.FindOneByOrderNo(l.ctx, *req.OrderNo)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if errors.Is(err, model.ErrNotFound) {
|
if errors.Is(err, model.ErrNotFound) {
|
||||||
return nil, errors.Wrapf(xerr.NewErrMsg("订单不存在"), "")
|
return nil, errors.Wrapf(xerr.NewErrMsg("订单不存在"), "")
|
||||||
@ -53,14 +62,7 @@ func (l *QueryGenerateShareLinkLogic) QueryGenerateShareLink(req *types.QueryGen
|
|||||||
return nil, errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "生成分享链接, 获取订单失败: %v", err)
|
return nil, errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "生成分享链接, 获取订单失败: %v", err)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// 使用OrderNo查询
|
return nil, errors.Wrapf(xerr.NewErrMsg("订单ID和订单号不能同时为空"), "")
|
||||||
order, err = l.svcCtx.OrderModel.FindOneByOrderNo(l.ctx, req.OrderNo)
|
|
||||||
if err != nil {
|
|
||||||
if errors.Is(err, model.ErrNotFound) {
|
|
||||||
return nil, errors.Wrapf(xerr.NewErrMsg("订单不存在"), "")
|
|
||||||
}
|
|
||||||
return nil, errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "生成分享链接, 获取订单失败: %v", err)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if order.Status != model.OrderStatusPaid {
|
if order.Status != model.OrderStatusPaid {
|
||||||
@ -75,9 +77,14 @@ func (l *QueryGenerateShareLinkLogic) QueryGenerateShareLink(req *types.QueryGen
|
|||||||
if query.QueryState != model.QueryStateSuccess {
|
if query.QueryState != model.QueryStateSuccess {
|
||||||
return nil, errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "生成分享链接, 查询未成功")
|
return nil, errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "生成分享链接, 查询未成功")
|
||||||
}
|
}
|
||||||
|
user, err := l.svcCtx.UserModel.FindOne(l.ctx, order.UserId)
|
||||||
if order.UserId != userId {
|
if err != nil {
|
||||||
return nil, errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "生成分享链接, 无权操作此订单")
|
return nil, errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "生成分享链接, 获取用户失败: %v", err)
|
||||||
|
}
|
||||||
|
if user.Inside != 1 {
|
||||||
|
if order.Id != userId {
|
||||||
|
return nil, errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "生成分享链接, 无权操作此订单")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
expireAt := time.Now().Add(time.Duration(l.svcCtx.Config.Query.ShareLinkExpire) * time.Second)
|
expireAt := time.Now().Add(time.Duration(l.svcCtx.Config.Query.ShareLinkExpire) * time.Second)
|
||||||
|
@ -372,8 +372,8 @@ type QueryExampleResp struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type QueryGenerateShareLinkReq struct {
|
type QueryGenerateShareLinkReq struct {
|
||||||
OrderId int64 `json:"order_id,optional"`
|
OrderId *int64 `json:"order_id,optional"`
|
||||||
OrderNo string `json:"order_no,optional"`
|
OrderNo *string `json:"order_no,optional"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type QueryGenerateShareLinkResp struct {
|
type QueryGenerateShareLinkResp struct {
|
||||||
|
Loading…
Reference in New Issue
Block a user