Files
junhong_cmp_fiber/pkg/constants/wallet.go
Break 5f57429fb0
All checks were successful
构建并部署到测试环境(无 SSH) / build-and-deploy (push) Successful in 8m28s
直接换货流程
2026-06-03 16:55:32 +08:00

169 lines
5.2 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" // 提现
AgentTransactionTypeCommissionDeduct = "commission_deduct" // 退款佣金回扣
)
// 代理钱包交易子类型(当 transaction_type = "deduct" 用于订单支付时)
const (
WalletTransactionSubtypeSelfPurchase = "self_purchase" // 自购
WalletTransactionSubtypePurchaseForSubordinate = "purchase_for_subordinate" // 给下级代理购买
)
// 代理充值订单号前缀
const (
AgentRechargeOrderPrefix = "ARCH" // 代理充值订单号前缀
)
// 代理充值金额限制(单位:分)
const (
AgentRechargeMinAmount = 1 // 最小充值金额1分
AgentRechargeMaxAmount = 100000000 // 最大充值金额1000000元
)
// ========== 资产钱包常量 ==========
// 资产钱包资源类型
const (
AssetWalletResourceTypeIotCard = "iot_card" // 物联网卡钱包
AssetWalletResourceTypeDevice = "device" // 设备钱包(多卡共享)
)
// 资产钱包状态
const (
AssetWalletStatusNormal = 1 // 正常
AssetWalletStatusFrozen = 2 // 冻结
AssetWalletStatusClosed = 3 // 关闭
)
// 资产钱包交易类型
const (
AssetTransactionTypeRecharge = "recharge" // 充值
AssetTransactionTypeDeduct = "deduct" // 扣款
AssetTransactionTypeRefund = "refund" // 退款
AssetTransactionTypeExchange = "exchange" // 换货迁移
)
// 资产充值订单号前缀
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" // 充值
ReferenceTypeRefund = "refund" // 退款
ReferenceTypeExchange = "exchange" // 换货
)
// ========== Redis Key 生成函数 ==========
// GetRechargeStatusName 获取充值状态名称
// 对应 RechargeStatus* 常量1=待支付, 2=已支付, 3=已完成, 4=已关闭, 5=已退款
func GetRechargeStatusName(status int) string {
switch status {
case RechargeStatusPending:
return "待支付"
case RechargeStatusPaid:
return "已支付"
case RechargeStatusCompleted:
return "已完成"
case RechargeStatusClosed:
return "已关闭"
case RechargeStatusRefunded:
return "已退款"
default:
return "未知"
}
}
// 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)
}