This commit is contained in:
2026-01-16 18:37:47 +08:00
parent 96dfa3d758
commit 96d530a67d
12 changed files with 959 additions and 156 deletions

View File

@@ -300,7 +300,7 @@ func (h *ComponentReportHandler) GenerateAndDownloadZip(c *gin.Context) {
return
}
// 直接检查用户是否有已支付的购买记录,而不是查询下载记录
// 直接检查用户是否有已支付的购买记录
orders, _, err := h.purchaseOrderRepo.GetByUserID(c.Request.Context(), userID, 100, 0)
if err != nil {
h.logger.Error("查询用户购买记录失败", zap.Error(err), zap.String("user_id", userID), zap.String("product_id", req.ProductID))
@@ -384,10 +384,12 @@ func (h *ComponentReportHandler) GenerateAndDownloadZip(c *gin.Context) {
}
// 更新下载次数和最后下载时间
err = h.componentReportRepo.IncrementDownloadCount(c.Request.Context(), download.ID)
if err != nil {
h.logger.Warn("更新下载次数失败", zap.Error(err))
// 不影响下载流程,只记录警告
if download != nil {
err = h.componentReportRepo.IncrementDownloadCount(c.Request.Context(), download.ID)
if err != nil {
h.logger.Warn("更新下载次数失败", zap.Error(err))
// 不影响下载流程,只记录警告
}
}
// 清理过期的缓存(非阻塞方式)
@@ -979,6 +981,13 @@ func (h *ComponentReportHandler) CreatePaymentOrder(c *gin.Context) {
}
// 创建下载记录
// 设置原始价格组合包使用UIComponentPrice单品使用Price
var originalPrice decimal.Decimal
if product.IsPackage {
originalPrice = product.UIComponentPrice
} else {
originalPrice = product.Price
}
download := &entities.ComponentReportDownload{
UserID: userID,
ProductID: productID,
@@ -989,7 +998,8 @@ func (h *ComponentReportHandler) CreatePaymentOrder(c *gin.Context) {
// 关联购买订单ID
OrderID: &createdPurchaseOrder.ID,
OrderNumber: &outTradeNo,
DownloadPrice: finalPrice, // 设置下载价格
OriginalPrice: originalPrice, // 设置原始价格
DownloadPrice: finalPrice, // 设置下载价格
}
// 记录创建前的详细信息用于调试
@@ -1384,6 +1394,13 @@ func (h *ComponentReportHandler) createDownloadRecordIfEligible(ctx context.Cont
}
// 3. 创建下载记录
// 设置原始价格组合包使用UIComponentPrice单品使用Price
var originalPrice decimal.Decimal
if product.IsPackage {
originalPrice = product.UIComponentPrice
} else {
originalPrice = product.Price
}
download := &entities.ComponentReportDownload{
UserID: userID,
ProductID: productID,
@@ -1391,6 +1408,7 @@ func (h *ComponentReportHandler) createDownloadRecordIfEligible(ctx context.Cont
ProductName: product.Name,
OrderID: &validOrder.ID, // 添加OrderID字段
OrderNumber: &validOrder.OrderNo, // 使用OrderNumber字段
OriginalPrice: originalPrice, // 设置原始价格
DownloadPrice: validOrder.Amount, // 设置下载价格(从订单获取)
ExpiresAt: calculateExpiryTime(), // 从创建日起30天
}
@@ -1563,6 +1581,13 @@ func (h *ComponentReportHandler) createDownloadRecordForPaidOrder(ctx context.Co
}
// 创建下载记录
// 设置原始价格组合包使用UIComponentPrice单品使用Price
var originalPrice decimal.Decimal
if product.IsPackage {
originalPrice = product.UIComponentPrice
} else {
originalPrice = product.Price
}
download := &entities.ComponentReportDownload{
UserID: order.UserID,
ProductID: order.ProductID,
@@ -1570,7 +1595,8 @@ func (h *ComponentReportHandler) createDownloadRecordForPaidOrder(ctx context.Co
ProductName: order.ProductName,
OrderID: &order.ID,
OrderNumber: &order.OrderNo,
DownloadPrice: order.Amount, // 设置下载价格(从订单获取)
OriginalPrice: originalPrice, // 设置原始价格
DownloadPrice: order.Amount, // 设置下载价格(从订单获取)
ExpiresAt: calculateExpiryTime(),
}