Compare commits

...

3 Commits

Author SHA1 Message Date
6b902f68f1 Merge branch 'main' of http://1.117.67.95:3000/team/tyapi-server 2026-01-14 16:00:32 +08:00
745fbc05d5 f 2026-01-14 16:00:27 +08:00
6618e35869 -f 2026-01-14 15:59:15 +08:00
3 changed files with 75 additions and 65 deletions

View File

@@ -565,13 +565,14 @@ func (s *ComponentReportOrderService) createFreeOrder(
// 创建下载记录
download := &productEntities.ComponentReportDownload{
UserID: req.UserID,
ProductID: req.ProductID,
ProductCode: product.Code,
ProductName: product.Name,
OrderID: &createdPurchaseOrder.ID, // 关联购买订单ID
OrderNumber: &createdPurchaseOrder.OrderNo, // 外部订单号
ExpiresAt: calculateExpiryTime(), // 30天后过期
UserID: req.UserID,
ProductID: req.ProductID,
ProductCode: product.Code,
ProductName: product.Name,
OrderID: &createdPurchaseOrder.ID, // 关联购买订单ID
OrderNumber: &createdPurchaseOrder.OrderNo, // 外部订单号
DownloadPrice: finalPrice, // 设置下载价格
ExpiresAt: calculateExpiryTime(), // 30天后过期
}
err = s.componentReportRepo.Create(ctx, download)
@@ -779,13 +780,14 @@ func (s *ComponentReportOrderService) DownloadFile(ctx context.Context, orderID
// 创建新的下载记录
newDownload := &productEntities.ComponentReportDownload{
UserID: purchaseOrder.UserID,
ProductID: purchaseOrder.ProductID,
ProductCode: product.Code,
ProductName: product.Name,
OrderID: &purchaseOrder.ID,
OrderNumber: &purchaseOrder.OrderNo,
ExpiresAt: calculateExpiryTime(),
UserID: purchaseOrder.UserID,
ProductID: purchaseOrder.ProductID,
ProductCode: product.Code,
ProductName: product.Name,
OrderID: &purchaseOrder.ID,
OrderNumber: &purchaseOrder.OrderNo,
DownloadPrice: purchaseOrder.Amount, // 设置下载价格(从订单获取)
ExpiresAt: calculateExpiryTime(),
}
// 保存下载记录
@@ -918,13 +920,14 @@ func (s *ComponentReportOrderService) createDownloadRecordForPaidOrder(ctx conte
// 创建新的下载记录
download := &productEntities.ComponentReportDownload{
UserID: purchaseOrder.UserID,
ProductID: purchaseOrder.ProductID,
ProductCode: product.Code,
ProductName: product.Name,
OrderID: &purchaseOrder.ID,
OrderNumber: &purchaseOrder.OrderNo,
ExpiresAt: calculateExpiryTime(), // 30天后过期
UserID: purchaseOrder.UserID,
ProductID: purchaseOrder.ProductID,
ProductCode: product.Code,
ProductName: product.Name,
OrderID: &purchaseOrder.ID,
OrderNumber: &purchaseOrder.OrderNo,
DownloadPrice: purchaseOrder.Amount, // 设置下载价格(从订单获取)
ExpiresAt: calculateExpiryTime(), // 30天后过期
}
// 保存下载记录

View File

@@ -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:"文件哈希值(用于缓存验证)"`

View File

@@ -987,8 +987,9 @@ func (h *ComponentReportHandler) CreatePaymentOrder(c *gin.Context) {
SubProductIDs: string(subProductIDsJSON),
SubProductCodes: string(subProductCodesJSON),
// 关联购买订单ID
OrderID: &createdPurchaseOrder.ID,
OrderNumber: &outTradeNo,
OrderID: &createdPurchaseOrder.ID,
OrderNumber: &outTradeNo,
DownloadPrice: finalPrice, // 设置下载价格
}
// 记录创建前的详细信息用于调试
@@ -1384,13 +1385,14 @@ func (h *ComponentReportHandler) createDownloadRecordIfEligible(ctx context.Cont
// 3. 创建下载记录
download := &entities.ComponentReportDownload{
UserID: userID,
ProductID: productID,
ProductCode: product.Code,
ProductName: product.Name,
OrderID: &validOrder.ID, // 添加OrderID字段
OrderNumber: &validOrder.OrderNo, // 使用OrderNumber字段
ExpiresAt: calculateExpiryTime(), // 从创建日起30天
UserID: userID,
ProductID: productID,
ProductCode: product.Code,
ProductName: product.Name,
OrderID: &validOrder.ID, // 添加OrderID字段
OrderNumber: &validOrder.OrderNo, // 使用OrderNumber字段
DownloadPrice: validOrder.Amount, // 设置下载价格(从订单获取)
ExpiresAt: calculateExpiryTime(), // 从创建日起30天
}
// 4. 如果是组合包,获取子产品信息
@@ -1562,13 +1564,14 @@ func (h *ComponentReportHandler) createDownloadRecordForPaidOrder(ctx context.Co
// 创建下载记录
download := &entities.ComponentReportDownload{
UserID: order.UserID,
ProductID: order.ProductID,
ProductCode: order.ProductCode,
ProductName: order.ProductName,
OrderID: &order.ID,
OrderNumber: &order.OrderNo,
ExpiresAt: calculateExpiryTime(),
UserID: order.UserID,
ProductID: order.ProductID,
ProductCode: order.ProductCode,
ProductName: order.ProductName,
OrderID: &order.ID,
OrderNumber: &order.OrderNo,
DownloadPrice: order.Amount, // 设置下载价格(从订单获取)
ExpiresAt: calculateExpiryTime(),
}
// 如果是组合包,获取子产品信息