f
This commit is contained in:
@@ -6,7 +6,10 @@ import (
|
||||
|
||||
"in-server/app/main/api/internal/svc"
|
||||
"in-server/app/main/api/internal/types"
|
||||
"in-server/app/main/model"
|
||||
"in-server/common/xerr"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
||||
@@ -25,9 +28,28 @@ func NewDownloadReportPdfLogic(ctx context.Context, svcCtx *svc.ServiceContext)
|
||||
}
|
||||
|
||||
func (l *DownloadReportPdfLogic) DownloadReportPdf(req *types.DownloadReportPdfReq) (resp *types.DownloadReportPdfResp, err error) {
|
||||
pdfBytes, err := l.svcCtx.ReportPDFService.GetOrGenerateReportPDF(l.ctx, req.OrderId, req.OrderNo)
|
||||
orderId := req.OrderId
|
||||
|
||||
// 若没有传 orderId 但有 orderNo,则先根据订单号查出订单ID,确保 PDF 渲染页能走按 orderId 的公开接口
|
||||
if orderId == "" && req.OrderNo != "" {
|
||||
order, findErr := l.svcCtx.OrderModel.FindOneByOrderNo(l.ctx, req.OrderNo)
|
||||
if findErr != nil {
|
||||
if errors.Is(findErr, model.ErrNotFound) {
|
||||
logx.Errorf("生成报告 PDF 失败, 未找到订单, orderNo=%s, err=%v", req.OrderNo, findErr)
|
||||
return nil, errors.Wrapf(xerr.NewErrCode(xerr.LOGIC_QUERY_NOT_FOUND), "报告查询, 订单不存在: %v", findErr)
|
||||
}
|
||||
return nil, errors.Wrapf(xerr.NewErrCode(xerr.DB_ERROR), "报告查询, 查找订单错误: %v", findErr)
|
||||
}
|
||||
// 仅允许已支付订单生成报告 PDF
|
||||
if order.Status != "paid" {
|
||||
return nil, errors.Wrapf(xerr.NewErrMsg("订单未支付,无法生成报告 PDF"), "")
|
||||
}
|
||||
orderId = order.Id
|
||||
}
|
||||
|
||||
pdfBytes, err := l.svcCtx.ReportPDFService.GetOrGenerateReportPDF(l.ctx, orderId, req.OrderNo)
|
||||
if err != nil {
|
||||
logx.Errorf("生成报告 PDF 失败, orderId=%s, orderNo=%s, err=%v", req.OrderId, req.OrderNo, err)
|
||||
logx.Errorf("生成报告 PDF 失败, orderId=%s, orderNo=%s, err=%v", orderId, req.OrderNo, err)
|
||||
return nil, fmt.Errorf("生成报告 PDF 失败: %w", err)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user