feat: 钱包系统分离 - 代理钱包与卡钱包完全隔离
All checks were successful
构建并部署到测试环境(无 SSH) / build-and-deploy (push) Successful in 7m17s
All checks were successful
构建并部署到测试环境(无 SSH) / build-and-deploy (push) Successful in 7m17s
## 变更概述 将统一钱包系统拆分为代理钱包和卡钱包两个独立系统,实现数据表和代码层面的完全隔离。 ## 数据库变更 - 新增 6 张表:tb_agent_wallet、tb_agent_wallet_transaction、tb_agent_recharge_record、tb_card_wallet、tb_card_wallet_transaction、tb_card_recharge_record - 删除 3 张旧表:tb_wallet、tb_wallet_transaction、tb_recharge_record - 代理钱包:按 (shop_id, wallet_type) 唯一标识,支持主钱包和分佣钱包 - 卡钱包:按 (resource_type, resource_id) 唯一标识,支持物联网卡和设备 ## 代码变更 - Model 层:新增 AgentWallet、AgentWalletTransaction、AgentRechargeRecord、CardWallet、CardWalletTransaction、CardRechargeRecord 模型 - Store 层:新增 6 个独立 Store,支持事务、乐观锁、Redis 缓存 - Service 层:重构 commission_calculation、commission_withdrawal、order、recharge 等 8 个服务 - Bootstrap 层:更新 Store 和 Service 依赖注入 - 常量层:按钱包类型重新组织常量和 Redis Key 生成函数 ## 技术特性 - 乐观锁:使用 version 字段防止并发冲突 - 多租户:支持 shop_id_tag 和 enterprise_id_tag 过滤 - 事务管理:所有余额变动使用事务保证 ACID - 缓存策略:Cache-Aside 模式,余额变动后删除缓存 ## 业务影响 - 代理钱包和卡钱包业务完全隔离,互不影响 - 为独立监控、优化、扩展打下基础 - 提升代理钱包的稳定性和独立性 Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
//go:build ignore
|
||||
// +build ignore
|
||||
|
||||
package main
|
||||
@@ -20,20 +21,20 @@ import (
|
||||
|
||||
// IotCard 简化的卡模型
|
||||
type IotCard struct {
|
||||
ID uint `gorm:"primaryKey"`
|
||||
ICCID string `gorm:"column:iccid;uniqueIndex:idx_iot_card_iccid,where:deleted_at IS NULL"`
|
||||
CardCategory string `gorm:"column:card_category;default:normal"`
|
||||
CarrierID uint `gorm:"column:carrier_id"`
|
||||
Status int `gorm:"column:status;default:1"`
|
||||
ActivationStatus int `gorm:"column:activation_status;default:0"`
|
||||
RealNameStatus int `gorm:"column:real_name_status;default:0"`
|
||||
NetworkStatus int `gorm:"column:network_status;default:0"`
|
||||
EnablePolling bool `gorm:"column:enable_polling;default:true"`
|
||||
Creator uint `gorm:"column:creator"`
|
||||
Updater uint `gorm:"column:updater"`
|
||||
CreatedAt time.Time
|
||||
UpdatedAt time.Time
|
||||
DeletedAt *time.Time `gorm:"index"`
|
||||
ID uint `gorm:"primaryKey"`
|
||||
ICCID string `gorm:"column:iccid;uniqueIndex:idx_iot_card_iccid,where:deleted_at IS NULL"`
|
||||
CardCategory string `gorm:"column:card_category;default:normal"`
|
||||
CarrierID uint `gorm:"column:carrier_id"`
|
||||
Status int `gorm:"column:status;default:1"`
|
||||
ActivationStatus int `gorm:"column:activation_status;default:0"`
|
||||
RealNameStatus int `gorm:"column:real_name_status;default:0"`
|
||||
NetworkStatus int `gorm:"column:network_status;default:0"`
|
||||
EnablePolling bool `gorm:"column:enable_polling;default:true"`
|
||||
Creator uint `gorm:"column:creator"`
|
||||
Updater uint `gorm:"column:updater"`
|
||||
CreatedAt time.Time
|
||||
UpdatedAt time.Time
|
||||
DeletedAt *time.Time `gorm:"index"`
|
||||
}
|
||||
|
||||
func (IotCard) TableName() string {
|
||||
@@ -41,11 +42,11 @@ func (IotCard) TableName() string {
|
||||
}
|
||||
|
||||
var (
|
||||
totalCards = flag.Int("total", 10000000, "要生成的卡数量")
|
||||
batchSize = flag.Int("batch", 10000, "每批插入数量")
|
||||
workers = flag.Int("workers", 10, "并行 worker 数量")
|
||||
startICCID = flag.String("start", "898600000", "起始 ICCID 前缀(9位,总长度不超过20位)")
|
||||
clearOld = flag.Bool("clear", false, "是否清空现有测试卡")
|
||||
totalCards = flag.Int("total", 10000000, "要生成的卡数量")
|
||||
batchSize = flag.Int("batch", 10000, "每批插入数量")
|
||||
workers = flag.Int("workers", 10, "并行 worker 数量")
|
||||
startICCID = flag.String("start", "898600000", "起始 ICCID 前缀(9位,总长度不超过20位)")
|
||||
clearOld = flag.Bool("clear", false, "是否清空现有测试卡")
|
||||
|
||||
insertedCount int64
|
||||
startTime time.Time
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
//go:build ignore
|
||||
// +build ignore
|
||||
|
||||
package main
|
||||
@@ -250,12 +251,12 @@ func handleStats(w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
|
||||
stats := map[string]interface{}{
|
||||
"uptime_seconds": elapsed,
|
||||
"total_requests": total,
|
||||
"success_count": success,
|
||||
"failed_count": failed,
|
||||
"qps": qps,
|
||||
"success_rate": fmt.Sprintf("%.2f%%", successRate),
|
||||
"uptime_seconds": elapsed,
|
||||
"total_requests": total,
|
||||
"success_count": success,
|
||||
"failed_count": failed,
|
||||
"qps": qps,
|
||||
"success_rate": fmt.Sprintf("%.2f%%", successRate),
|
||||
}
|
||||
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
|
||||
Reference in New Issue
Block a user