修复金额的问题
All checks were successful
构建并部署到测试环境(无 SSH) / build-and-deploy (push) Successful in 7m30s

This commit is contained in:
2026-04-23 10:09:23 +08:00
parent 10a35625a5
commit 6b1fbf4a92
17 changed files with 637 additions and 16 deletions

View File

@@ -339,6 +339,11 @@ func (s *Service) CreateAdminOrder(ctx context.Context, req *dto.CreateAdminOrde
return nil, errors.New(errors.CodeInvalidParam, "后台仅支持钱包支付或线下支付")
}
if paymentStatus == model.PaymentStatusPaid && actualPaidAmount == nil {
actualPaidAmountSnapshot := totalAmount
actualPaidAmount = &actualPaidAmountSnapshot
}
// 查询当前生效的支付配置
var paymentConfigID *uint
if req.PaymentMethod == model.PaymentMethodWechat || req.PaymentMethod == model.PaymentMethodAlipay {
@@ -608,6 +613,11 @@ func (s *Service) CreateH5Order(ctx context.Context, req *dto.CreateOrderRequest
}
}
if paymentStatus == model.PaymentStatusPaid && actualPaidAmount == nil {
actualPaidAmountSnapshot := totalAmount
actualPaidAmount = &actualPaidAmountSnapshot
}
// 查询当前生效的支付配置
var h5PaymentConfigID *uint
if req.PaymentMethod == model.PaymentMethodWechat || req.PaymentMethod == model.PaymentMethodAlipay {
@@ -998,6 +1008,9 @@ func (s *Service) List(ctx context.Context, req *dto.OrderListRequest, buyerType
if req.PaymentStatus != nil {
filters["payment_status"] = *req.PaymentStatus
}
if req.PaymentMethod != "" {
filters["payment_method"] = req.PaymentMethod
}
if req.OrderType != "" {
filters["order_type"] = req.OrderType
}
@@ -1247,6 +1260,7 @@ func (s *Service) WalletPay(ctx context.Context, orderID uint, buyerType string,
// 根据资源类型选择对应的钱包系统
now := time.Now()
actualPaidAmount := order.TotalAmount
if resourceType == "shop" {
// 代理钱包系统(店铺)
@@ -1266,10 +1280,11 @@ func (s *Service) WalletPay(ctx context.Context, orderID uint, buyerType string,
result := tx.Model(&model.Order{}).
Where("id = ? AND payment_status = ?", orderID, model.PaymentStatusPending).
Updates(map[string]any{
"payment_status": model.PaymentStatusPaid,
"payment_method": model.PaymentMethodWallet,
"paid_at": now,
"expires_at": nil, // 支付成功,清除过期时间
"payment_status": model.PaymentStatusPaid,
"payment_method": model.PaymentMethodWallet,
"paid_at": now,
"expires_at": nil, // 支付成功,清除过期时间
"actual_paid_amount": actualPaidAmount,
})
if result.Error != nil {
return errors.Wrap(errors.CodeDatabaseError, result.Error, "更新订单支付状态失败")
@@ -1293,6 +1308,9 @@ func (s *Service) WalletPay(ctx context.Context, orderID uint, buyerType string,
}
}
actualPaidAmountSnapshot := actualPaidAmount
order.ActualPaidAmount = &actualPaidAmountSnapshot
walletResult := tx.Model(&model.AgentWallet{}).
Where("id = ? AND balance >= ? AND version = ?", wallet.ID, order.TotalAmount, wallet.Version).
Updates(map[string]any{
@@ -1330,10 +1348,11 @@ func (s *Service) WalletPay(ctx context.Context, orderID uint, buyerType string,
result := tx.Model(&model.Order{}).
Where("id = ? AND payment_status = ?", orderID, model.PaymentStatusPending).
Updates(map[string]any{
"payment_status": model.PaymentStatusPaid,
"payment_method": model.PaymentMethodWallet,
"paid_at": now,
"expires_at": nil, // 支付成功,清除过期时间
"payment_status": model.PaymentStatusPaid,
"payment_method": model.PaymentMethodWallet,
"paid_at": now,
"expires_at": nil, // 支付成功,清除过期时间
"actual_paid_amount": actualPaidAmount,
})
if result.Error != nil {
return errors.Wrap(errors.CodeDatabaseError, result.Error, "更新订单支付状态失败")
@@ -1357,6 +1376,9 @@ func (s *Service) WalletPay(ctx context.Context, orderID uint, buyerType string,
}
}
actualPaidAmountSnapshot := actualPaidAmount
order.ActualPaidAmount = &actualPaidAmountSnapshot
// 扣款前记录余额快照,用于写入流水
balanceBefore := wallet.Balance
@@ -2030,6 +2052,12 @@ func (s *Service) buildOrderResponse(order *model.Order, items []*model.OrderIte
assetType = "device"
}
actualPaidAmount := order.ActualPaidAmount
if actualPaidAmount == nil && order.PaymentStatus == model.PaymentStatusPaid {
actualPaidAmountSnapshot := order.TotalAmount
actualPaidAmount = &actualPaidAmountSnapshot
}
return &dto.OrderResponse{
ID: order.ID,
OrderNo: order.OrderNo,
@@ -2054,7 +2082,7 @@ func (s *Service) buildOrderResponse(order *model.Order, items []*model.OrderIte
OperatorID: order.OperatorID,
OperatorType: order.OperatorType,
OperatorName: operatorName,
ActualPaidAmount: order.ActualPaidAmount,
ActualPaidAmount: actualPaidAmount,
PurchaseRole: order.PurchaseRole,
IsPurchasedByParent: isPurchasedByParent,