Files
junhong_cmp_fiber/pkg/constants/wallet.go
huang b0da71bd25 refactor: 清理 YAML 支付配置遗留代码,重命名 Card* 常量为 Asset*,新增支付配置相关错误码
- 删除 PaymentConfig 结构体和 WechatConfig.Payment 字段(YAML 方案已废弃)
- 删除 wechat.payment 配置节和 NewPaymentApp() 函数
- 删除 validateWechatConfig 中所有 wechatCfg.Payment.* 校验代码
- pkg/constants/wallet.go: Card* 前缀统一重命名为 Asset*,旧名保留废弃别名
- pkg/constants/redis.go: 新增 RedisWechatConfigActiveKey()
- pkg/errors/codes.go: 新增错误码 1170-1175
- go.mod: 新增 golang.org/x/text 依赖(富友支付 GBK 编解码)

Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-opencode)

Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
2026-03-16 23:28:29 +08:00

233 lines
8.3 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
package constants
import "fmt"
// ========================================
// 钱包系统常量定义
// ========================================
// ========== 代理钱包常量 ==========
// 代理钱包类型
const (
AgentWalletTypeMain = "main" // 主钱包
AgentWalletTypeCommission = "commission" // 分佣钱包
)
// 代理钱包状态
const (
AgentWalletStatusNormal = 1 // 正常
AgentWalletStatusFrozen = 2 // 冻结
AgentWalletStatusClosed = 3 // 关闭
)
// 代理钱包交易类型
const (
AgentTransactionTypeRecharge = "recharge" // 充值
AgentTransactionTypeDeduct = "deduct" // 扣款
AgentTransactionTypeRefund = "refund" // 退款
AgentTransactionTypeCommission = "commission" // 分佣
AgentTransactionTypeWithdrawal = "withdrawal" // 提现
)
// 代理钱包交易子类型(当 transaction_type = "deduct" 用于订单支付时)
const (
WalletTransactionSubtypeSelfPurchase = "self_purchase" // 自购
WalletTransactionSubtypePurchaseForSubordinate = "purchase_for_subordinate" // 给下级代理购买
)
// 代理充值订单号前缀
const (
AgentRechargeOrderPrefix = "ARCH" // 代理充值订单号前缀
)
// 代理充值金额限制(单位:分)
const (
AgentRechargeMinAmount = 10000 // 最小充值金额100元
AgentRechargeMaxAmount = 100000000 // 最大充值金额1000000元
)
// ========== 资产钱包常量 ==========
// 资产钱包资源类型
const (
AssetWalletResourceTypeIotCard = "iot_card" // 物联网卡钱包
AssetWalletResourceTypeDevice = "device" // 设备钱包(多卡共享)
)
// 资产钱包状态
const (
AssetWalletStatusNormal = 1 // 正常
AssetWalletStatusFrozen = 2 // 冻结
AssetWalletStatusClosed = 3 // 关闭
)
// 资产钱包交易类型
const (
AssetTransactionTypeRecharge = "recharge" // 充值
AssetTransactionTypeDeduct = "deduct" // 扣款
AssetTransactionTypeRefund = "refund" // 退款
)
// 资产充值订单号前缀
const (
AssetRechargeOrderPrefix = "CRCH" // 资产充值订单号前缀
)
// 资产充值金额限制(单位:分)
const (
AssetRechargeMinAmount = 100 // 最小充值金额1元
AssetRechargeMaxAmount = 10000000 // 最大充值金额100000元
)
// ========== 通用常量 ==========
// 交易状态(代理钱包和卡钱包通用)
const (
TransactionStatusSuccess = 1 // 成功
TransactionStatusFailed = 2 // 失败
TransactionStatusProcessing = 3 // 处理中
)
// 充值状态(代理钱包和卡钱包通用)
const (
RechargeStatusPending = 1 // 待支付
RechargeStatusPaid = 2 // 已支付
RechargeStatusCompleted = 3 // 已完成
RechargeStatusClosed = 4 // 已关闭
RechargeStatusRefunded = 5 // 已退款
)
// 充值支付方式
const (
RechargeMethodAlipay = "alipay" // 支付宝
RechargeMethodWechat = "wechat" // 微信
RechargeMethodBank = "bank" // 银行转账(仅代理钱包支持)
RechargeMethodOffline = "offline" // 线下(仅代理钱包支持)
)
// 关联业务类型
const (
ReferenceTypeOrder = "order" // 订单
ReferenceTypeCommission = "commission" // 分佣
ReferenceTypeWithdrawal = "withdrawal" // 提现
ReferenceTypeTopup = "topup" // 充值
)
// ========== Redis Key 生成函数 ==========
// RedisAgentWalletBalanceKey 代理钱包余额缓存 Key
// 格式agent_wallet:balance:{shop_id}:{wallet_type}
// TTL300 秒5 分钟)
func RedisAgentWalletBalanceKey(shopID uint, walletType string) string {
return fmt.Sprintf("agent_wallet:balance:%d:%s", shopID, walletType)
}
// RedisAgentWalletLockKey 代理钱包分布式锁 Key
// 格式agent_wallet:lock:{shop_id}:{wallet_type}
// TTL10 秒
func RedisAgentWalletLockKey(shopID uint, walletType string) string {
return fmt.Sprintf("agent_wallet:lock:%d:%s", shopID, walletType)
}
// RedisAssetWalletBalanceKey 资产钱包余额缓存 Key
// 格式asset_wallet:balance:{resource_type}:{resource_id}
// TTL180 秒3 分钟)
func RedisAssetWalletBalanceKey(resourceType string, resourceID uint) string {
return fmt.Sprintf("asset_wallet:balance:%s:%d", resourceType, resourceID)
}
// RedisAssetWalletLockKey 资产钱包分布式锁 Key
// 格式asset_wallet:lock:{resource_type}:{resource_id}
// TTL10 秒
func RedisAssetWalletLockKey(resourceType string, resourceID uint) string {
return fmt.Sprintf("asset_wallet:lock:%s:%d", resourceType, resourceID)
}
// ========== 兼容性别名(待清理)==========
// 以下常量保留用于向后兼容,待旧代码清理后删除
// WalletTypeMain 主钱包(已废弃,使用 AgentWalletTypeMain
const WalletTypeMain = AgentWalletTypeMain
// WalletTypeCommission 分佣钱包(已废弃,使用 AgentWalletTypeCommission
const WalletTypeCommission = AgentWalletTypeCommission
// WalletResourceTypeIotCard 物联网卡钱包(已废弃,使用 AssetWalletResourceTypeIotCard
const WalletResourceTypeIotCard = AssetWalletResourceTypeIotCard
// WalletResourceTypeDevice 设备钱包(已废弃,使用 AssetWalletResourceTypeDevice
const WalletResourceTypeDevice = AssetWalletResourceTypeDevice
// WalletResourceTypeShop 店铺钱包(已废弃,代理钱包不再使用 resource_type
const WalletResourceTypeShop = "shop"
// WalletStatusNormal 钱包状态-正常(已废弃,使用 AgentWalletStatusNormal 或 AssetWalletStatusNormal
const WalletStatusNormal = AgentWalletStatusNormal
// WalletStatusFrozen 钱包状态-冻结(已废弃,使用 AgentWalletStatusFrozen 或 AssetWalletStatusFrozen
const WalletStatusFrozen = AgentWalletStatusFrozen
// WalletStatusClosed 钱包状态-关闭(已废弃,使用 AgentWalletStatusClosed 或 AssetWalletStatusClosed
const WalletStatusClosed = AgentWalletStatusClosed
// TransactionTypeRecharge 交易类型-充值(已废弃,使用 AgentTransactionTypeRecharge 或 AssetTransactionTypeRecharge
const TransactionTypeRecharge = AgentTransactionTypeRecharge
// TransactionTypeDeduct 交易类型-扣款(已废弃,使用 AgentTransactionTypeDeduct 或 AssetTransactionTypeDeduct
const TransactionTypeDeduct = AgentTransactionTypeDeduct
// TransactionTypeRefund 交易类型-退款(已废弃,使用 AgentTransactionTypeRefund 或 AssetTransactionTypeRefund
const TransactionTypeRefund = AgentTransactionTypeRefund
// TransactionTypeCommission 交易类型-分佣(已废弃,使用 AgentTransactionTypeCommission
const TransactionTypeCommission = AgentTransactionTypeCommission
// TransactionTypeWithdrawal 交易类型-提现(已废弃,使用 AgentTransactionTypeWithdrawal
const TransactionTypeWithdrawal = AgentTransactionTypeWithdrawal
// RechargeOrderPrefix 充值订单号前缀(已废弃,使用 AgentRechargeOrderPrefix 或 AssetRechargeOrderPrefix
const RechargeOrderPrefix = "RCH"
// RechargeMinAmount 最小充值金额(已废弃,使用 AgentRechargeMinAmount 或 AssetRechargeMinAmount
const RechargeMinAmount = AssetRechargeMinAmount
// RechargeMaxAmount 最大充值金额(已废弃,使用 AgentRechargeMaxAmount 或 AssetRechargeMaxAmount
const RechargeMaxAmount = AssetRechargeMaxAmount
// ========== Card* 废弃别名(向后兼容)==========
// Deprecated: 使用 AssetWalletResourceTypeIotCard
const CardWalletResourceTypeIotCard = AssetWalletResourceTypeIotCard
// Deprecated: 使用 AssetWalletResourceTypeDevice
const CardWalletResourceTypeDevice = AssetWalletResourceTypeDevice
// Deprecated: 使用 AssetWalletStatusNormal
const CardWalletStatusNormal = AssetWalletStatusNormal
// Deprecated: 使用 AssetWalletStatusFrozen
const CardWalletStatusFrozen = AssetWalletStatusFrozen
// Deprecated: 使用 AssetWalletStatusClosed
const CardWalletStatusClosed = AssetWalletStatusClosed
// Deprecated: 使用 AssetTransactionTypeRecharge
const CardTransactionTypeRecharge = AssetTransactionTypeRecharge
// Deprecated: 使用 AssetTransactionTypeDeduct
const CardTransactionTypeDeduct = AssetTransactionTypeDeduct
// Deprecated: 使用 AssetTransactionTypeRefund
const CardTransactionTypeRefund = AssetTransactionTypeRefund
// Deprecated: 使用 AssetRechargeOrderPrefix
const CardRechargeOrderPrefix = AssetRechargeOrderPrefix
// Deprecated: 使用 AssetRechargeMinAmount
const CardRechargeMinAmount = AssetRechargeMinAmount
// Deprecated: 使用 AssetRechargeMaxAmount
const CardRechargeMaxAmount = AssetRechargeMaxAmount