新增钱包、换卡、标签系统的数据模型和规范
本次提交完成 add-wallet-transfer-tag-models 提案的实施和归档: ## 新增功能模块 - 钱包系统:用户/代理钱包管理,支持充值、扣款、退款、乐观锁防并发 - 换卡记录:物联卡更换历史追溯,包含套餐快照(JSONB) - 标签系统:设备/IoT卡/号卡的统一标签管理 - 运营商渠道:四大运营商(CMCC/CUCC/CTCC/CBN)的渠道管理 ## 数据库变更 - 新增 6 张表:tb_wallet, tb_wallet_transaction, tb_recharge_record, tb_card_replacement_record, tb_tag, tb_resource_tag - 修改 2 张表:tb_carrier(新增渠道字段), tb_order(新增混合支付字段) - 迁移版本:v6 → v7(执行时间 282.5ms) ## 代码变更 - 新增 8 个 Go 模型(符合统一规范:gorm.Model + BaseModel) - 新增 40+ 个常量定义(含完整中文注释) - 新增 7 个 Redis Key 生成函数 - 修复模型规范:移除重复字段,统一使用 gorm.Model 嵌入 ## 文档变更 - 新增 3 个业务文档:数据模型设计、字段说明、迁移验证报告 - 更新 AGENTS.md:新增 Model 模型规范和常量注释规范 - 新增 4 个 OpenSpec 规范:wallet, carrier, card-replacement, tag - 更新 1 个 OpenSpec 规范:iot-order(支持混合支付) ## 验证通过 - ✅ LSP 诊断:所有模型和常量文件无错误 - ✅ OpenSpec 验证:openspec validate --strict 通过 - ✅ 迁移执行:表结构创建成功,索引正确 - ✅ 提案归档:2026-01-13-add-wallet-transfer-tag-models 变更文件统计:29 个文件,新增 3682 行
This commit is contained in:
@@ -237,4 +237,13 @@ const (
|
||||
CarrierCodeCMCC = "CMCC" // 中国移动
|
||||
CarrierCodeCUCC = "CUCC" // 中国联通
|
||||
CarrierCodeCTCC = "CTCC" // 中国电信
|
||||
CarrierCodeCBN = "CBN" // 广电
|
||||
)
|
||||
|
||||
const (
|
||||
ReplacementReasonDamaged = "damaged"
|
||||
ReplacementReasonLost = "lost"
|
||||
ReplacementReasonMalfunction = "malfunction"
|
||||
ReplacementReasonUpgrade = "upgrade"
|
||||
ReplacementReasonOther = "other"
|
||||
)
|
||||
|
||||
@@ -46,3 +46,53 @@ func RedisVerificationCodeKey(phone string) string {
|
||||
func RedisVerificationCodeLimitKey(phone string) string {
|
||||
return fmt.Sprintf("verification:limit:%s", phone)
|
||||
}
|
||||
|
||||
// ========================================
|
||||
// 钱包相关 Redis Key
|
||||
// ========================================
|
||||
|
||||
// RedisWalletLockKey 生成钱包操作锁的 Redis 键
|
||||
// 用途:钱包余额变更时的分布式锁,防止并发冲突
|
||||
// 过期时间:10 秒
|
||||
func RedisWalletLockKey(walletID uint) string {
|
||||
return fmt.Sprintf("wallet:lock:%d", walletID)
|
||||
}
|
||||
|
||||
// RedisWalletBalanceKey 生成钱包余额缓存的 Redis 键
|
||||
// 用途:缓存钱包余额,减少数据库查询
|
||||
// 过期时间:5 分钟
|
||||
func RedisWalletBalanceKey(walletID uint) string {
|
||||
return fmt.Sprintf("wallet:balance:%d", walletID)
|
||||
}
|
||||
|
||||
// RedisRechargeOrderKey 生成充值订单缓存的 Redis 键
|
||||
// 用途:充值订单状态查询缓存
|
||||
// 过期时间:1 小时
|
||||
func RedisRechargeOrderKey(rechargeNo string) string {
|
||||
return fmt.Sprintf("recharge:order:%s", rechargeNo)
|
||||
}
|
||||
|
||||
// RedisWalletTransactionKey 生成钱包交易幂等性的 Redis 键
|
||||
// 用途:防止重复交易
|
||||
// 过期时间:24 小时
|
||||
func RedisWalletTransactionKey(requestID string) string {
|
||||
return fmt.Sprintf("wallet:transaction:%s", requestID)
|
||||
}
|
||||
|
||||
// ========================================
|
||||
// 标签相关 Redis Key
|
||||
// ========================================
|
||||
|
||||
// RedisTagCacheKey 生成标签缓存的 Redis 键
|
||||
// 用途:缓存热门标签列表
|
||||
// 过期时间:1 小时
|
||||
func RedisTagCacheKey() string {
|
||||
return "tag:cache:list"
|
||||
}
|
||||
|
||||
// RedisResourceTagsKey 生成资源标签关联缓存的 Redis 键
|
||||
// 用途:缓存资源的标签列表
|
||||
// 过期时间:30 分钟
|
||||
func RedisResourceTagsKey(resourceType string, resourceID uint) string {
|
||||
return fmt.Sprintf("resource:tags:%s:%d", resourceType, resourceID)
|
||||
}
|
||||
|
||||
12
pkg/constants/tag.go
Normal file
12
pkg/constants/tag.go
Normal file
@@ -0,0 +1,12 @@
|
||||
package constants
|
||||
|
||||
// ========================================
|
||||
// 标签系统常量定义
|
||||
// ========================================
|
||||
|
||||
// 资源类型
|
||||
const (
|
||||
ResourceTypeDevice = "device" // 设备
|
||||
ResourceTypeIotCard = "iot_card" // IoT卡
|
||||
ResourceTypeNumberCard = "number_card" // 号卡
|
||||
)
|
||||
59
pkg/constants/wallet.go
Normal file
59
pkg/constants/wallet.go
Normal file
@@ -0,0 +1,59 @@
|
||||
package constants
|
||||
|
||||
// ========================================
|
||||
// 钱包系统常量定义
|
||||
// ========================================
|
||||
|
||||
// 钱包类型
|
||||
const (
|
||||
WalletTypeUser = "user" // 用户钱包
|
||||
WalletTypeAgent = "agent" // 代理钱包
|
||||
)
|
||||
|
||||
// 钱包状态
|
||||
const (
|
||||
WalletStatusNormal = 1 // 正常
|
||||
WalletStatusFrozen = 2 // 冻结
|
||||
WalletStatusClosed = 3 // 关闭
|
||||
)
|
||||
|
||||
// 交易类型
|
||||
const (
|
||||
TransactionTypeRecharge = "recharge" // 充值
|
||||
TransactionTypeDeduct = "deduct" // 扣款
|
||||
TransactionTypeRefund = "refund" // 退款
|
||||
TransactionTypeCommission = "commission" // 分佣
|
||||
TransactionTypeWithdrawal = "withdrawal" // 提现
|
||||
)
|
||||
|
||||
// 交易状态
|
||||
const (
|
||||
TransactionStatusSuccess = 1 // 成功
|
||||
TransactionStatusFailed = 2 // 失败
|
||||
TransactionStatusProcessing = 3 // 处理中
|
||||
)
|
||||
|
||||
// 关联业务类型
|
||||
const (
|
||||
ReferenceTypeOrder = "order" // 订单
|
||||
ReferenceTypeCommission = "commission" // 分佣
|
||||
ReferenceTypeWithdrawal = "withdrawal" // 提现
|
||||
ReferenceTypeTopup = "topup" // 充值
|
||||
)
|
||||
|
||||
// 充值状态
|
||||
const (
|
||||
RechargeStatusPending = 1 // 待支付
|
||||
RechargeStatusPaid = 2 // 已支付
|
||||
RechargeStatusCompleted = 3 // 已完成
|
||||
RechargeStatusClosed = 4 // 已关闭
|
||||
RechargeStatusRefunded = 5 // 已退款
|
||||
)
|
||||
|
||||
// 充值支付方式
|
||||
const (
|
||||
RechargeMethodAlipay = "alipay" // 支付宝
|
||||
RechargeMethodWechat = "wechat" // 微信
|
||||
RechargeMethodBank = "bank" // 银行转账
|
||||
RechargeMethodOffline = "offline" // 线下
|
||||
)
|
||||
Reference in New Issue
Block a user