f
This commit is contained in:
@@ -313,12 +313,6 @@ func (s *ComponentReportOrderService) CreatePaymentOrder(ctx context.Context, re
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 检查价格是否为0
|
|
||||||
if finalPrice.IsZero() {
|
|
||||||
return s.createFreeOrder(ctx, req, &product, nil, nil, finalPrice)
|
|
||||||
}
|
|
||||||
|
|
||||||
// 准备子产品信息列表(仅用于展示)
|
// 准备子产品信息列表(仅用于展示)
|
||||||
var subProductCodes []string
|
var subProductCodes []string
|
||||||
var subProductIDs []string
|
var subProductIDs []string
|
||||||
@@ -528,67 +522,6 @@ func (s *ComponentReportOrderService) CreatePaymentOrder(ctx context.Context, re
|
|||||||
return response, nil
|
return response, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// createFreeOrder 创建免费订单
|
|
||||||
func (s *ComponentReportOrderService) createFreeOrder(
|
|
||||||
ctx context.Context,
|
|
||||||
req *CreatePaymentOrderRequest,
|
|
||||||
product *productEntities.Product,
|
|
||||||
subProductCodes []string,
|
|
||||||
subProductIDs []string,
|
|
||||||
finalPrice decimal.Decimal,
|
|
||||||
) (*CreatePaymentOrderResponse, error) {
|
|
||||||
// 序列化子产品列表
|
|
||||||
// 简化后的实体不再需要序列化子产品列表
|
|
||||||
|
|
||||||
// 创建免费订单
|
|
||||||
purchaseOrder := entities.NewPurchaseOrder(
|
|
||||||
req.UserID,
|
|
||||||
req.ProductID,
|
|
||||||
product.Code,
|
|
||||||
product.Name,
|
|
||||||
fmt.Sprintf("组件报告下载-%s", product.Name),
|
|
||||||
finalPrice,
|
|
||||||
"app",
|
|
||||||
"free",
|
|
||||||
"free",
|
|
||||||
)
|
|
||||||
|
|
||||||
// 设置为已支付状态
|
|
||||||
purchaseOrder.Status = entities.PurchaseOrderStatusPaid
|
|
||||||
now := time.Now()
|
|
||||||
purchaseOrder.PayTime = &now
|
|
||||||
|
|
||||||
createdPurchaseOrder, err := s.purchaseOrderRepo.Create(ctx, purchaseOrder)
|
|
||||||
if err != nil {
|
|
||||||
return nil, fmt.Errorf("创建免费订单失败: %w", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
// 创建下载记录
|
|
||||||
download := &productEntities.ComponentReportDownload{
|
|
||||||
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)
|
|
||||||
if err != nil {
|
|
||||||
s.logger.Error("创建下载记录失败", zap.Error(err))
|
|
||||||
// 不中断流程,即使创建下载记录失败也继续返回订单信息
|
|
||||||
}
|
|
||||||
|
|
||||||
return &CreatePaymentOrderResponse{
|
|
||||||
OrderID: createdPurchaseOrder.ID, // 修改为购买订单ID
|
|
||||||
OrderNo: createdPurchaseOrder.OrderNo,
|
|
||||||
PaymentType: "free",
|
|
||||||
Amount: "0.00",
|
|
||||||
}, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// generateReportFile 生成报告文件
|
// generateReportFile 生成报告文件
|
||||||
func (s *ComponentReportOrderService) generateReportFile(ctx context.Context, download *productEntities.ComponentReportDownload) (string, error) {
|
func (s *ComponentReportOrderService) generateReportFile(ctx context.Context, download *productEntities.ComponentReportDownload) (string, error) {
|
||||||
// 解析子产品编号列表
|
// 解析子产品编号列表
|
||||||
@@ -870,12 +803,7 @@ func (s *ComponentReportOrderService) GetUserOrders(ctx context.Context, userID
|
|||||||
}
|
}
|
||||||
paymentType = purchaseOrder.PayChannel
|
paymentType = purchaseOrder.PayChannel
|
||||||
}
|
}
|
||||||
} else if download.OrderNumber != nil {
|
|
||||||
// 兼容旧的支付订单逻辑
|
|
||||||
purchaseStatus = "paid" // 简化处理,有支付订单号就认为已支付
|
|
||||||
paymentType = "unknown"
|
|
||||||
}
|
}
|
||||||
|
|
||||||
result = append(result, &UserOrderResponse{
|
result = append(result, &UserOrderResponse{
|
||||||
ID: download.ID,
|
ID: download.ID,
|
||||||
OrderNo: "",
|
OrderNo: "",
|
||||||
@@ -883,7 +811,7 @@ func (s *ComponentReportOrderService) GetUserOrders(ctx context.Context, userID
|
|||||||
ProductCode: download.ProductCode,
|
ProductCode: download.ProductCode,
|
||||||
PaymentType: paymentType,
|
PaymentType: paymentType,
|
||||||
PurchaseStatus: purchaseStatus,
|
PurchaseStatus: purchaseStatus,
|
||||||
Price: "0.00", // 下载记录不存储价格信息
|
Price: download.DownloadPrice.String(),
|
||||||
CreatedAt: download.CreatedAt,
|
CreatedAt: download.CreatedAt,
|
||||||
PaymentTime: paymentTime,
|
PaymentTime: paymentTime,
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ type ComponentReportDownload struct {
|
|||||||
SubProductCodes string `gorm:"type:text" comment:"子产品编号列表(JSON数组)"`
|
SubProductCodes string `gorm:"type:text" comment:"子产品编号列表(JSON数组)"`
|
||||||
|
|
||||||
// 价格相关字段
|
// 价格相关字段
|
||||||
DownloadPrice decimal.Decimal `gorm:"type:decimal(10,2);not null" comment:"实际支付价格"`
|
DownloadPrice decimal.Decimal `gorm:"type:decimal(10,2);default:0.00" comment:"实际支付价格"`
|
||||||
|
|
||||||
// 下载相关信息
|
// 下载相关信息
|
||||||
FilePath *string `gorm:"type:varchar(500)" comment:"生成的ZIP文件路径(用于二次下载)"`
|
FilePath *string `gorm:"type:varchar(500)" comment:"生成的ZIP文件路径(用于二次下载)"`
|
||||||
|
|||||||
Reference in New Issue
Block a user