-f
This commit is contained in:
@@ -571,6 +571,7 @@ func (s *ComponentReportOrderService) createFreeOrder(
|
||||
ProductName: product.Name,
|
||||
OrderID: &createdPurchaseOrder.ID, // 关联购买订单ID
|
||||
OrderNumber: &createdPurchaseOrder.OrderNo, // 外部订单号
|
||||
DownloadPrice: finalPrice, // 设置下载价格
|
||||
ExpiresAt: calculateExpiryTime(), // 30天后过期
|
||||
}
|
||||
|
||||
@@ -785,6 +786,7 @@ func (s *ComponentReportOrderService) DownloadFile(ctx context.Context, orderID
|
||||
ProductName: product.Name,
|
||||
OrderID: &purchaseOrder.ID,
|
||||
OrderNumber: &purchaseOrder.OrderNo,
|
||||
DownloadPrice: purchaseOrder.Amount, // 设置下载价格(从订单获取)
|
||||
ExpiresAt: calculateExpiryTime(),
|
||||
}
|
||||
|
||||
@@ -924,6 +926,7 @@ func (s *ComponentReportOrderService) createDownloadRecordForPaidOrder(ctx conte
|
||||
ProductName: product.Name,
|
||||
OrderID: &purchaseOrder.ID,
|
||||
OrderNumber: &purchaseOrder.OrderNo,
|
||||
DownloadPrice: purchaseOrder.Amount, // 设置下载价格(从订单获取)
|
||||
ExpiresAt: calculateExpiryTime(), // 30天后过期
|
||||
}
|
||||
|
||||
|
||||
@@ -4,6 +4,7 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/google/uuid"
|
||||
"github.com/shopspring/decimal"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
@@ -22,6 +23,9 @@ type ComponentReportDownload struct {
|
||||
SubProductIDs string `gorm:"type:text" comment:"子产品ID列表(JSON数组,组合包使用)"`
|
||||
SubProductCodes string `gorm:"type:text" comment:"子产品编号列表(JSON数组)"`
|
||||
|
||||
// 价格相关字段
|
||||
DownloadPrice decimal.Decimal `gorm:"type:decimal(10,2);not null" comment:"实际支付价格"`
|
||||
|
||||
// 下载相关信息
|
||||
FilePath *string `gorm:"type:varchar(500)" comment:"生成的ZIP文件路径(用于二次下载)"`
|
||||
FileHash *string `gorm:"type:varchar(64)" comment:"文件哈希值(用于缓存验证)"`
|
||||
|
||||
@@ -397,9 +397,14 @@ func (h *ComponentReportHandler) GenerateAndDownloadZip(c *gin.Context) {
|
||||
}
|
||||
}()
|
||||
|
||||
// 创建带超时的上下文,避免ZIP生成时间过长导致网关超时
|
||||
// 设置超时时间为 25 秒,略小于服务器的 write_timeout (30秒)
|
||||
ctx, cancel := context.WithTimeout(c.Request.Context(), 25*time.Second)
|
||||
defer cancel()
|
||||
|
||||
// 生成ZIP文件
|
||||
zipPath, err := h.zipGenerator.GenerateZipFile(
|
||||
c.Request.Context(),
|
||||
ctx,
|
||||
req.ProductID,
|
||||
req.SubProductCodes,
|
||||
h.exampleJSONGenerator,
|
||||
@@ -407,6 +412,18 @@ func (h *ComponentReportHandler) GenerateAndDownloadZip(c *gin.Context) {
|
||||
)
|
||||
if err != nil {
|
||||
h.logger.Error("生成ZIP文件失败", zap.Error(err), zap.String("product_id", req.ProductID))
|
||||
|
||||
// 检查是否是超时错误
|
||||
if ctx.Err() == context.DeadlineExceeded {
|
||||
h.logger.Error("ZIP文件生成超时", zap.String("product_id", req.ProductID))
|
||||
c.JSON(http.StatusRequestTimeout, gin.H{
|
||||
"code": 504,
|
||||
"message": "文件生成超时,请稍后重试",
|
||||
"error": "请求处理时间过长",
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
c.JSON(http.StatusInternalServerError, gin.H{
|
||||
"code": 500,
|
||||
"message": "生成ZIP文件失败",
|
||||
@@ -989,6 +1006,7 @@ func (h *ComponentReportHandler) CreatePaymentOrder(c *gin.Context) {
|
||||
// 关联购买订单ID
|
||||
OrderID: &createdPurchaseOrder.ID,
|
||||
OrderNumber: &outTradeNo,
|
||||
DownloadPrice: finalPrice, // 设置下载价格
|
||||
}
|
||||
|
||||
// 记录创建前的详细信息用于调试
|
||||
@@ -1390,6 +1408,7 @@ func (h *ComponentReportHandler) createDownloadRecordIfEligible(ctx context.Cont
|
||||
ProductName: product.Name,
|
||||
OrderID: &validOrder.ID, // 添加OrderID字段
|
||||
OrderNumber: &validOrder.OrderNo, // 使用OrderNumber字段
|
||||
DownloadPrice: validOrder.Amount, // 设置下载价格(从订单获取)
|
||||
ExpiresAt: calculateExpiryTime(), // 从创建日起30天
|
||||
}
|
||||
|
||||
@@ -1568,6 +1587,7 @@ func (h *ComponentReportHandler) createDownloadRecordForPaidOrder(ctx context.Co
|
||||
ProductName: order.ProductName,
|
||||
OrderID: &order.ID,
|
||||
OrderNumber: &order.OrderNo,
|
||||
DownloadPrice: order.Amount, // 设置下载价格(从订单获取)
|
||||
ExpiresAt: calculateExpiryTime(),
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user