修复金额的问题
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

@@ -22,6 +22,7 @@ type OrderListRequest struct {
Page int `json:"page" query:"page" validate:"omitempty,min=1" minimum:"1" description:"页码"`
PageSize int `json:"page_size" query:"page_size" validate:"omitempty,min=1,max=100" minimum:"1" maximum:"100" description:"每页数量"`
PaymentStatus *int `json:"payment_status" query:"payment_status" validate:"omitempty,min=1,max=4" minimum:"1" maximum:"4" description:"支付状态 (1:待支付, 2:已支付, 3:已取消, 4:已退款)"`
PaymentMethod string `json:"payment_method" query:"payment_method" validate:"omitempty,oneof=wallet wechat alipay offline" description:"支付方式 (wallet:钱包支付, wechat:微信支付, alipay:支付宝支付, offline:线下支付)"`
OrderType string `json:"order_type" query:"order_type" validate:"omitempty,oneof=single_card device" description:"订单类型 (single_card:单卡购买, device:设备购买)"`
OrderNo string `json:"order_no" query:"order_no" validate:"omitempty,max=30" maxLength:"30" description:"订单号(精确查询)"`
PurchaseRole string `json:"purchase_role" query:"purchase_role" validate:"omitempty,oneof=self_purchase purchased_by_parent purchased_by_platform purchase_for_subordinate" description:"订单角色 (self_purchase:自己购买, purchased_by_parent:上级代理购买, purchased_by_platform:平台代购, purchase_for_subordinate:给下级购买)"`

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,

View File

@@ -109,6 +109,9 @@ func (s *OrderStore) List(ctx context.Context, opts *store.QueryOptions, filters
if v, ok := filters["order_type"]; ok {
query = query.Where("order_type = ?", v)
}
if v, ok := filters["payment_method"]; ok {
query = query.Where("payment_method = ?", v)
}
if v, ok := filters["order_no"]; ok {
query = query.Where("order_no = ?", v)
}