重构充值订单模块:用 tb_recharge_order + tb_payment 替换 tb_asset_recharge_record
All checks were successful
构建并部署到测试环境(无 SSH) / build-and-deploy (push) Successful in 7m32s

- 新增 RechargeOrder 和 Payment 模型及对应 Store
- 新增 ClientRechargeOrderHandler 提供充值订单列表/详情接口
- 修改 client_wallet.go 使用新表读写充值数据
- 修改 callback/payment.go 将 CRCH 订单路由到 rechargeOrderService
- 修改 client_order/service.go 的强充流程使用新表
- 修改 auto_purchase.go 从 tb_recharge_order 读取 linked_package_ids
- 修改 order/service.go 的 WalletPay 使用 tb_payment 记录
- 修改 wechat_config_store.go 从 tb_recharge_order 统计待支付充值数
- 移除 AssetRechargeStore 和 AssetRechargeRecord 的注册引用
- 修复文档生成器缺失 ClientRechargeOrder handler
- 状态枚举改为 0-based: Pending=0, Paid=1, Closed=2, Refunded=3
This commit is contained in:
2026-04-15 11:00:32 +08:00
parent d26010b29d
commit b972a776d9
33 changed files with 1589 additions and 1017 deletions

View File

@@ -39,6 +39,7 @@ type Service struct {
orderItemStore *postgres.OrderItemStore
agentWalletStore *postgres.AgentWalletStore
assetWalletStore *postgres.AssetWalletStore
paymentStore *postgres.PaymentStore
purchaseValidationService *purchase_validation.Service
shopPackageAllocationStore *postgres.ShopPackageAllocationStore
shopSeriesAllocationStore *postgres.ShopSeriesAllocationStore
@@ -65,6 +66,7 @@ func New(
orderItemStore *postgres.OrderItemStore,
agentWalletStore *postgres.AgentWalletStore,
assetWalletStore *postgres.AssetWalletStore,
paymentStore *postgres.PaymentStore,
purchaseValidationService *purchase_validation.Service,
shopPackageAllocationStore *postgres.ShopPackageAllocationStore,
shopSeriesAllocationStore *postgres.ShopSeriesAllocationStore,
@@ -89,6 +91,7 @@ func New(
orderItemStore: orderItemStore,
agentWalletStore: agentWalletStore,
assetWalletStore: assetWalletStore,
paymentStore: paymentStore,
purchaseValidationService: purchaseValidationService,
shopPackageAllocationStore: shopPackageAllocationStore,
shopSeriesAllocationStore: shopSeriesAllocationStore,
@@ -1188,6 +1191,18 @@ func (s *Service) unfreezeWalletForCancel(ctx context.Context, tx *gorm.DB, orde
return nil
}
func (s *Service) createWalletPaymentRecord(tx *gorm.DB, order *model.Order, paymentMethod string) error {
payment := &model.Payment{
PaymentNo: order.OrderNo,
OrderID: order.ID,
OrderType: model.PaymentOrderTypePackage,
PaymentMethod: paymentMethod,
Amount: order.TotalAmount,
Status: model.PaymentRecordStatusPaid,
}
return tx.Create(payment).Error
}
func (s *Service) WalletPay(ctx context.Context, orderID uint, buyerType string, buyerID uint) error {
order, err := s.orderStore.GetByID(ctx, orderID)
if err != nil {
@@ -1205,6 +1220,11 @@ func (s *Service) WalletPay(ctx context.Context, orderID uint, buyerType string,
return errors.New(errors.CodeInvalidStatus, "代购订单无需支付")
}
existingPayment, _ := s.paymentStore.GetByOrderIDAndStatus(ctx, orderID, model.PaymentRecordStatusPaid)
if existingPayment != nil {
return nil
}
var resourceType string
var resourceID uint
@@ -1286,6 +1306,10 @@ func (s *Service) WalletPay(ctx context.Context, orderID uint, buyerType string,
return errors.New(errors.CodeInsufficientBalance, "余额不足或并发冲突")
}
if err := s.createWalletPaymentRecord(tx, order, model.PaymentByWallet); err != nil {
return err
}
return s.activatePackage(ctx, tx, order)
})
} else {
@@ -1370,6 +1394,10 @@ func (s *Service) WalletPay(ctx context.Context, orderID uint, buyerType string,
return errors.Wrap(errors.CodeDatabaseError, err, "创建扣款流水失败")
}
if err := s.createWalletPaymentRecord(tx, order, model.PaymentByWallet); err != nil {
return err
}
return s.activatePackage(ctx, tx, order)
})
}