重构充值订单模块:用 tb_recharge_order + tb_payment 替换 tb_asset_recharge_record
All checks were successful
构建并部署到测试环境(无 SSH) / build-and-deploy (push) Successful in 7m32s
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:
@@ -3,7 +3,6 @@ package model
|
||||
import (
|
||||
"time"
|
||||
|
||||
"gorm.io/datatypes"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
@@ -64,39 +63,3 @@ type AssetWalletTransaction struct {
|
||||
func (AssetWalletTransaction) TableName() string {
|
||||
return "tb_asset_wallet_transaction"
|
||||
}
|
||||
|
||||
// AssetRechargeRecord 资产充值记录模型
|
||||
// 记录所有资产钱包充值操作
|
||||
type AssetRechargeRecord struct {
|
||||
ID uint `gorm:"column:id;primaryKey" json:"id"`
|
||||
UserID uint `gorm:"column:user_id;not null;index;comment:操作人用户ID" json:"user_id"`
|
||||
AssetWalletID uint `gorm:"column:asset_wallet_id;not null;comment:资产钱包ID" json:"asset_wallet_id"`
|
||||
ResourceType string `gorm:"column:resource_type;type:varchar(20);not null;index;comment:资源类型(冗余字段)" json:"resource_type"`
|
||||
ResourceID uint `gorm:"column:resource_id;not null;index;comment:资源ID(冗余字段)" json:"resource_id"`
|
||||
RechargeNo string `gorm:"column:recharge_no;type:varchar(50);not null;uniqueIndex;comment:充值订单号(格式:CRCH+时间戳+随机数)" json:"recharge_no"`
|
||||
Amount int64 `gorm:"column:amount;type:bigint;not null;comment:充值金额(单位:分,最小100分=1元)" json:"amount"`
|
||||
PaymentMethod string `gorm:"column:payment_method;type:varchar(20);not null;comment:支付方式(alipay-支付宝 | wechat-微信)" json:"payment_method"`
|
||||
PaymentChannel *string `gorm:"column:payment_channel;type:varchar(50);comment:支付渠道" json:"payment_channel,omitempty"`
|
||||
PaymentTransactionID *string `gorm:"column:payment_transaction_id;type:varchar(100);comment:第三方支付交易号" json:"payment_transaction_id,omitempty"`
|
||||
PaymentConfigID *uint `gorm:"column:payment_config_id;index;comment:支付配置ID(关联tb_wechat_config.id)" json:"payment_config_id,omitempty"`
|
||||
Status int `gorm:"column:status;type:int;not null;default:1;comment:充值状态(1-待支付 2-已支付 3-已完成 4-已关闭 5-已退款)" json:"status"`
|
||||
PaidAt *time.Time `gorm:"column:paid_at;comment:支付时间" json:"paid_at,omitempty"`
|
||||
CompletedAt *time.Time `gorm:"column:completed_at;comment:完成时间" json:"completed_at,omitempty"`
|
||||
ShopIDTag uint `gorm:"column:shop_id_tag;not null;index;comment:店铺ID标签(多租户过滤)" json:"shop_id_tag"`
|
||||
EnterpriseIDTag *uint `gorm:"column:enterprise_id_tag;index;comment:企业ID标签(多租户过滤)" json:"enterprise_id_tag,omitempty"`
|
||||
CreatedAt time.Time `gorm:"column:created_at;not null;default:CURRENT_TIMESTAMP" json:"created_at"`
|
||||
UpdatedAt time.Time `gorm:"column:updated_at;not null;default:CURRENT_TIMESTAMP" json:"updated_at"`
|
||||
OperatorType string `gorm:"column:operator_type;type:varchar(20);not null;default:'admin_user';comment:操作人类型" json:"operator_type"`
|
||||
Generation int `gorm:"column:generation;type:int;not null;default:1;comment:资产世代编号" json:"generation"`
|
||||
LinkedPackageIDs datatypes.JSON `gorm:"column:linked_package_ids;type:jsonb;default:'[]';comment:强充关联套餐ID列表" json:"linked_package_ids,omitempty"`
|
||||
LinkedOrderType string `gorm:"column:linked_order_type;type:varchar(20);comment:关联订单类型" json:"linked_order_type,omitempty"`
|
||||
LinkedCarrierType string `gorm:"column:linked_carrier_type;type:varchar(20);comment:关联载体类型" json:"linked_carrier_type,omitempty"`
|
||||
LinkedCarrierID *uint `gorm:"column:linked_carrier_id;type:bigint;comment:关联载体ID" json:"linked_carrier_id,omitempty"`
|
||||
AutoPurchaseStatus string `gorm:"column:auto_purchase_status;type:varchar(20);default:'';comment:强充自动代购状态(pending-待处理 success-成功 failed-失败)" json:"auto_purchase_status,omitempty"`
|
||||
DeletedAt gorm.DeletedAt `gorm:"column:deleted_at;index" json:"deleted_at,omitempty"`
|
||||
}
|
||||
|
||||
// TableName 指定表名
|
||||
func (AssetRechargeRecord) TableName() string {
|
||||
return "tb_asset_recharge_record"
|
||||
}
|
||||
|
||||
@@ -19,6 +19,7 @@ type ClientCreateOrderResponse struct {
|
||||
Recharge *ClientRechargeInfo `json:"recharge,omitempty" description:"充值订单信息"`
|
||||
PayConfig *ClientPayConfig `json:"pay_config,omitempty" description:"微信支付配置(仅强充场景返回)"`
|
||||
LinkedPackageInfo *LinkedPackageInfo `json:"linked_package_info,omitempty" description:"关联套餐信息"`
|
||||
Idempotent bool `json:"idempotent,omitempty" description:"幂等标志(true 表示返回的是已存在的待支付充值订单)"`
|
||||
}
|
||||
|
||||
// ClientOrderInfo D1 套餐订单信息
|
||||
|
||||
46
internal/model/dto/client_recharge_order_dto.go
Normal file
46
internal/model/dto/client_recharge_order_dto.go
Normal file
@@ -0,0 +1,46 @@
|
||||
package dto
|
||||
|
||||
// ClientRechargeOrderListRequest C6 充值订单列表请求
|
||||
type ClientRechargeOrderListRequest struct {
|
||||
Page int `json:"page" query:"page" description:"页码"`
|
||||
PageSize int `json:"page_size" query:"page_size" description:"每页数量"`
|
||||
Status int `json:"status" query:"status" description:"状态过滤 (0:待支付, 1:已支付, 2:已关闭, 3:已退款)"`
|
||||
}
|
||||
|
||||
// ClientRechargeOrderListItem C6 充值订单列表项
|
||||
type ClientRechargeOrderListItem struct {
|
||||
RechargeOrderID uint `json:"recharge_order_id" description:"充值订单ID"`
|
||||
RechargeOrderNo string `json:"recharge_order_no" description:"充值订单号"`
|
||||
Amount int64 `json:"amount" description:"充值金额(分)"`
|
||||
Status int `json:"status" description:"状态 (0:待支付, 1:已支付, 2:已关闭, 3:已退款)"`
|
||||
StatusName string `json:"status_name" description:"状态名称(中文)"`
|
||||
AutoPurchaseStatus string `json:"auto_purchase_status" description:"自动购包状态 (pending/success/failed)"`
|
||||
CreatedAt string `json:"created_at" description:"创建时间"`
|
||||
}
|
||||
|
||||
// ClientRechargeOrderDetail C7 充值订单详情
|
||||
type ClientRechargeOrderDetail struct {
|
||||
RechargeOrderID uint `json:"recharge_order_id" description:"充值订单ID"`
|
||||
RechargeOrderNo string `json:"recharge_order_no" description:"充值订单号"`
|
||||
Amount int64 `json:"amount" description:"充值金额(分)"`
|
||||
Status int `json:"status" description:"状态 (0:待支付, 1:已支付, 2:已关闭, 3:已退款)"`
|
||||
StatusName string `json:"status_name" description:"状态名称(中文)"`
|
||||
AutoPurchaseStatus string `json:"auto_purchase_status" description:"自动购包状态"`
|
||||
LinkedPackageIDs interface{} `json:"linked_package_ids" description:"关联套餐ID列表"`
|
||||
CreatedAt string `json:"created_at" description:"创建时间"`
|
||||
PaidAt string `json:"paid_at,omitempty" description:"支付时间"`
|
||||
Payments []ClientRechargeOrderPaymentDetail `json:"payments,omitempty" description:"支付记录列表"`
|
||||
}
|
||||
|
||||
// ClientRechargeOrderPaymentDetail 充值订单支付记录详情
|
||||
type ClientRechargeOrderPaymentDetail struct {
|
||||
PaymentID uint `json:"payment_id" description:"支付记录ID"`
|
||||
PaymentNo string `json:"payment_no" description:"支付单号"`
|
||||
PaymentMethod string `json:"payment_method" description:"支付方式 (wechat/alipay/wallet)"`
|
||||
Amount int64 `json:"amount" description:"支付金额(分)"`
|
||||
Status int `json:"status" description:"状态 (0:待支付, 1:已支付, 2:已失败, 3:已退款)"`
|
||||
StatusName string `json:"status_name" description:"状态名称(中文)"`
|
||||
ThirdPartyTradeNo string `json:"third_party_trade_no,omitempty" description:"第三方交易号"`
|
||||
PaidAt string `json:"paid_at,omitempty" description:"支付时间"`
|
||||
CreatedAt string `json:"created_at" description:"创建时间"`
|
||||
}
|
||||
46
internal/model/payment.go
Normal file
46
internal/model/payment.go
Normal file
@@ -0,0 +1,46 @@
|
||||
package model
|
||||
|
||||
import (
|
||||
"gorm.io/gorm"
|
||||
"time"
|
||||
)
|
||||
|
||||
type Payment struct {
|
||||
ID uint `gorm:"column:id;primaryKey" json:"id"`
|
||||
PaymentNo string `gorm:"column:payment_no;type:varchar(40);uniqueIndex;not null" json:"payment_no"`
|
||||
OrderID uint `gorm:"column:order_id;not null" json:"order_id"`
|
||||
OrderType string `gorm:"column:order_type;type:varchar(30);not null" json:"order_type"`
|
||||
PaymentMethod string `gorm:"column:payment_method;type:varchar(20);not null" json:"payment_method"`
|
||||
Amount int64 `gorm:"column:amount;type:bigint;not null" json:"amount"`
|
||||
Status int `gorm:"column:status;type:smallint;not null;default:0" json:"status"`
|
||||
ThirdPartyTradeNo string `gorm:"column:third_party_trade_no;type:varchar(100)" json:"third_party_trade_no,omitempty"`
|
||||
PaymentConfigID *uint `gorm:"column:payment_config_id" json:"payment_config_id,omitempty"`
|
||||
PaymentVoucherKey string `gorm:"column:payment_voucher_key;type:varchar(500)" json:"payment_voucher_key,omitempty"`
|
||||
PaidAt *time.Time `gorm:"column:paid_at" json:"paid_at,omitempty"`
|
||||
CreatedAt time.Time `gorm:"column:created_at;not null;default:CURRENT_TIMESTAMP" json:"created_at"`
|
||||
UpdatedAt time.Time `gorm:"column:updated_at;not null;default:CURRENT_TIMESTAMP" json:"updated_at"`
|
||||
DeletedAt gorm.DeletedAt `gorm:"column:deleted_at;index" json:"deleted_at,omitempty"`
|
||||
}
|
||||
|
||||
func (Payment) TableName() string {
|
||||
return "tb_payment"
|
||||
}
|
||||
|
||||
const (
|
||||
PaymentRecordStatusPending = 0 // 待支付
|
||||
PaymentRecordStatusPaid = 1 // 已支付
|
||||
PaymentRecordStatusFailed = 2 // 已失败
|
||||
PaymentRecordStatusRefunded = 3 // 已退款
|
||||
)
|
||||
|
||||
const (
|
||||
PaymentOrderTypePackage = "package_order"
|
||||
PaymentOrderTypeRecharge = "recharge_order"
|
||||
)
|
||||
|
||||
const (
|
||||
PaymentByWallet = "wallet"
|
||||
PaymentByWechat = "wechat"
|
||||
PaymentByAlipay = "alipay"
|
||||
PaymentByOffline = "offline"
|
||||
)
|
||||
55
internal/model/recharge_order.go
Normal file
55
internal/model/recharge_order.go
Normal file
@@ -0,0 +1,55 @@
|
||||
package model
|
||||
|
||||
import (
|
||||
"gorm.io/datatypes"
|
||||
"gorm.io/gorm"
|
||||
"time"
|
||||
)
|
||||
|
||||
// RechargeOrder 充值订单模型
|
||||
// 记录用户发起充值请求后生成的订单,支持强充和普通充值两种类型
|
||||
type RechargeOrder struct {
|
||||
ID uint `gorm:"column:id;primaryKey" json:"id"`
|
||||
RechargeOrderNo string `gorm:"column:recharge_order_no;type:varchar(40);uniqueIndex;not null" json:"recharge_order_no"`
|
||||
UserID uint `gorm:"column:user_id;not null;index" json:"user_id"`
|
||||
AssetWalletID uint `gorm:"column:asset_wallet_id;not null" json:"asset_wallet_id"`
|
||||
ResourceType string `gorm:"column:resource_type;type:varchar(20);not null" json:"resource_type"`
|
||||
ResourceID uint `gorm:"column:resource_id;not null" json:"resource_id"`
|
||||
IotCardID *uint `gorm:"column:iot_card_id" json:"iot_card_id,omitempty"`
|
||||
DeviceID *uint `gorm:"column:device_id" json:"device_id,omitempty"`
|
||||
Amount int64 `gorm:"column:amount;type:bigint;not null" json:"amount"`
|
||||
Status int `gorm:"column:status;type:smallint;not null;default:0" json:"status"`
|
||||
PaidAt *time.Time `gorm:"column:paid_at" json:"paid_at,omitempty"`
|
||||
ShopIDTag uint `gorm:"column:shop_id_tag;not null;default:0" json:"shop_id_tag"`
|
||||
EnterpriseIDTag *uint `gorm:"column:enterprise_id_tag" json:"enterprise_id_tag,omitempty"`
|
||||
OperatorType string `gorm:"column:operator_type;type:varchar(30);not null" json:"operator_type"`
|
||||
Generation int `gorm:"column:generation;not null;default:1" json:"generation"`
|
||||
LinkedPackageIDs datatypes.JSON `gorm:"column:linked_package_ids;type:jsonb" json:"linked_package_ids,omitempty"`
|
||||
LinkedOrderType string `gorm:"column:linked_order_type;type:varchar(20)" json:"linked_order_type,omitempty"`
|
||||
LinkedCarrierType string `gorm:"column:linked_carrier_type;type:varchar(20)" json:"linked_carrier_type,omitempty"`
|
||||
LinkedCarrierID *uint `gorm:"column:linked_carrier_id;type:bigint" json:"linked_carrier_id,omitempty"`
|
||||
AutoPurchaseStatus string `gorm:"column:auto_purchase_status;type:varchar(20)" json:"auto_purchase_status,omitempty"`
|
||||
AccumulatedRechargeSeries int64 `gorm:"column:accumulated_recharge_series;not null;default:0" json:"accumulated_recharge_series"`
|
||||
PaymentConfigID *uint `gorm:"column:payment_config_id;index" json:"payment_config_id,omitempty"`
|
||||
CreatedAt time.Time `gorm:"column:created_at;not null;default:CURRENT_TIMESTAMP" json:"created_at"`
|
||||
UpdatedAt time.Time `gorm:"column:updated_at;not null;default:CURRENT_TIMESTAMP" json:"updated_at"`
|
||||
DeletedAt gorm.DeletedAt `gorm:"column:deleted_at;index" json:"deleted_at,omitempty"`
|
||||
}
|
||||
|
||||
// TableName 指定表名
|
||||
func (RechargeOrder) TableName() string {
|
||||
return "tb_recharge_order"
|
||||
}
|
||||
|
||||
const (
|
||||
RechargeOrderStatusPending = 0 // 待支付
|
||||
RechargeOrderStatusPaid = 1 // 已支付
|
||||
RechargeOrderStatusClosed = 2 // 已关闭
|
||||
RechargeOrderStatusRefunded = 3 // 已退款
|
||||
)
|
||||
|
||||
const (
|
||||
AutoPurchaseStatusPending = "pending" // 待处理
|
||||
AutoPurchaseStatusSuccess = "success" // 成功
|
||||
AutoPurchaseStatusFailed = "failed" // 失败
|
||||
)
|
||||
Reference in New Issue
Block a user