This commit is contained in:
liangzai 2025-06-02 15:45:48 +08:00
parent 776a8c244d
commit a0d94f19c2
3 changed files with 25 additions and 18 deletions

View File

@ -114,8 +114,8 @@ service main {
type (
QueryGenerateShareLinkReq {
OrderId int64 `json:"order_id,optional"`
OrderNo string `json:"order_no,optional"`
OrderId *int64 `json:"order_id,optional"`
OrderNo *string `json:"order_no,optional"`
}
QueryGenerateShareLinkResp {
ShareLink string `json:"share_link"`

View File

@ -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和订单号不能同时为空"), "")
}
var order *model.Order
// 优先使用OrderId查询
if req.OrderId != 0 {
order, err = l.svcCtx.OrderModel.FindOne(l.ctx, req.OrderId)
if req.OrderId != nil && *req.OrderId != 0 {
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 errors.Is(err, model.ErrNotFound) {
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)
}
} else {
// 使用OrderNo查询
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)
}
return nil, errors.Wrapf(xerr.NewErrMsg("订单ID和订单号不能同时为空"), "")
}
if order.Status != model.OrderStatusPaid {
@ -75,10 +77,15 @@ func (l *QueryGenerateShareLinkLogic) QueryGenerateShareLink(req *types.QueryGen
if query.QueryState != model.QueryStateSuccess {
return nil, errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "生成分享链接, 查询未成功")
}
if order.UserId != userId {
user, err := l.svcCtx.UserModel.FindOne(l.ctx, order.UserId)
if err != nil {
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)
payload := types.QueryShareLinkPayload{

View File

@ -372,8 +372,8 @@ type QueryExampleResp struct {
}
type QueryGenerateShareLinkReq struct {
OrderId int64 `json:"order_id,optional"`
OrderNo string `json:"order_no,optional"`
OrderId *int64 `json:"order_id,optional"`
OrderNo *string `json:"order_no,optional"`
}
type QueryGenerateShareLinkResp struct {