Files
junhong_cmp_fiber/pkg/constants/constants.go
huang e78f5794b9 feat: 实现客户端换货系统(client-exchange-system)
新增完整换货生命周期管理:后台发起 → 客户端填收货信息 → 后台发货 → 确认完成(含可选全量迁移) → 旧资产转新再销售

后台接口(7个):
- POST /api/admin/exchanges(发起换货)
- GET /api/admin/exchanges(换货列表)
- GET /api/admin/exchanges/:id(换货详情)
- POST /api/admin/exchanges/:id/ship(发货)
- POST /api/admin/exchanges/:id/complete(确认完成+可选迁移)
- POST /api/admin/exchanges/:id/cancel(取消)
- POST /api/admin/exchanges/:id/renew(旧资产转新)

客户端接口(2个):
- GET /api/c/v1/exchange/pending(查询换货通知)
- POST /api/c/v1/exchange/:id/shipping-info(填写收货信息)

核心能力:
- ExchangeOrder 模型与状态机(1待填写→2待发货→3已发货→4已完成,1/2可取消→5)
- 全量迁移事务(11张表:钱包、套餐、标签、客户绑定等)
- 旧资产转新(generation+1、状态重置、新钱包、历史隔离)
- 旧 CardReplacementRecord 表改名为 legacy,is_replaced 过滤改为查新表
- 数据库迁移:000085 新建 tb_exchange_order,000086 旧表改名
2026-03-19 13:26:54 +08:00

236 lines
7.7 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 "time"
// Fiber Locals 的上下文键
const (
ContextKeyRequestID = "requestid" // 请求记录ID
ContextKeyStartTime = "start_time" // 请求开始时间
ContextKeyUserID = "user_id" // 用户ID
ContextKeyUserType = "user_type" // 用户类型
ContextKeyShopID = "shop_id" // 店铺ID
ContextKeyEnterpriseID = "enterprise_id" // 企业ID
ContextKeyCustomerID = "customer_id" // 个人客户ID
ContextKeyUserInfo = "user_info" // 完整的用户信息
ContextKeyIP = "ip_address" // IP地址
ContextKeyUserAgent = "user_agent" // User-Agent
ContextKeySubordinateShopIDs = "subordinate_shop_ids" // 下级店铺ID列表代理用户预计算
)
// 配置环境变量
const (
EnvConfigPath = "CONFIG_PATH"
EnvConfigEnv = "CONFIG_ENV" // dev, staging, prod
)
// 默认配置值
const (
DefaultConfigPath = "configs/config.yaml"
DefaultServerAddr = ":3000"
DefaultRedisAddr = "localhost:6379"
)
// 数据库配置常量
const (
DefaultMaxOpenConns = 25
DefaultMaxIdleConns = 10
DefaultConnMaxLifetime = 5 * time.Minute
DefaultPageSize = 20
MaxPageSize = 100
SlowQueryThreshold = 500 * time.Millisecond
)
// 任务类型常量
const (
TaskTypeEmailSend = "email:send" // 发送邮件
TaskTypeDataSync = "data:sync" // 数据同步
TaskTypeSIMStatusSync = "sim:status:sync" // SIM 卡状态同步
TaskTypeCommission = "commission:calculate" // 分佣计算
TaskTypeIotCardImport = "iot_card:import" // IoT 卡批量导入
TaskTypeDeviceImport = "device:import" // 设备批量导入
TaskTypeCommissionStatsUpdate = "commission:stats:update" // 佣金统计更新
TaskTypeCommissionStatsSync = "commission:stats:sync" // 佣金统计同步
TaskTypeCommissionStatsArchive = "commission:stats:archive" // 佣金统计归档
// 轮询任务类型
TaskTypePollingRealname = "polling:realname" // 实名状态检查
TaskTypePollingCarddata = "polling:carddata" // 卡流量检查
TaskTypePollingPackage = "polling:package" // 套餐流量检查
TaskTypePollingProtect = "polling:protect" // 保护期一致性检查
// 套餐激活任务类型
TaskTypePackageFirstActivation = "package:first:activation" // 首次实名激活
TaskTypePackageQueueActivation = "package:queue:activation" // 主套餐排队激活
TaskTypePackageDataReset = "package:data:reset" // 套餐流量重置
// 订单超时任务类型
TaskTypeOrderExpire = "order:expire" // 订单超时自动取消
TaskTypeAutoPurchaseAfterRecharge = "task:auto_purchase_after_recharge" // 充值后自动购包
// 定时任务类型(由 Asynq Scheduler 调度)
TaskTypeAlertCheck = "alert:check" // 告警检查
TaskTypeDataCleanup = "data:cleanup" // 数据清理
)
// 用户状态常量
const (
UserStatusActive = "active" // 激活
UserStatusInactive = "inactive" // 未激活
UserStatusSuspended = "suspended" // 暂停
)
// RBAC 用户类型常量
const (
UserTypeSuperAdmin = 1 // 超级管理员(跳过数据权限过滤)
UserTypePlatform = 2 // 平台用户
UserTypeAgent = 3 // 代理账号
UserTypeEnterprise = 4 // 企业账号
UserTypePersonalCustomer = 5 // 个人客户C端用户
)
// RBAC 角色类型常量
const (
RoleTypePlatform = 1 // 平台角色(适用于平台用户)
RoleTypeCustomer = 2 // 客户角色(适用于代理/企业账号)
)
// RBAC 权限类型常量
const (
PermissionTypeMenu = 1 // 菜单权限
PermissionTypeButton = 2 // 按钮权限
)
// RBAC 权限端口常量
const (
PlatformAll = "all" // 全部端口Web + H5
PlatformWeb = "web" // Web 后台
PlatformH5 = "h5" // H5 端
)
// RBAC 状态常量
const (
StatusDisabled = 0 // 禁用
StatusEnabled = 1 // 启用
)
// 上架状态常量
const (
ShelfStatusOn = 1 // 上架
ShelfStatusOff = 2 // 下架
)
// 套餐周期类型常量
const (
PackageCalendarTypeNaturalMonth = "natural_month" // 自然月周期
PackageCalendarTypeByDay = "by_day" // 按天周期
)
// 套餐流量重置周期常量
const (
PackageDataResetDaily = "daily" // 每日重置
PackageDataResetMonthly = "monthly" // 每月重置
PackageDataResetYearly = "yearly" // 每年重置
PackageDataResetNone = "none" // 不重置
)
// 套餐使用状态常量
const (
PackageUsageStatusPending = 0 // 待生效
PackageUsageStatusActive = 1 // 生效中
PackageUsageStatusDepleted = 2 // 已用完
PackageUsageStatusExpired = 3 // 已过期
PackageUsageStatusInvalidated = 4 // 已失效
)
// 运营商类型常量
const (
CarrierTypeCMCC = "CMCC" // 中国移动
CarrierTypeCUCC = "CUCC" // 中国联通
CarrierTypeCTCC = "CTCC" // 中国电信
CarrierTypeCBN = "CBN" // 中国广电
)
// 订单状态常量
const (
OrderStatusPending = "pending" // 待支付
OrderStatusPaid = "paid" // 已支付
OrderStatusProcessing = "processing" // 处理中
OrderStatusCompleted = "completed" // 已完成
OrderStatusCancelled = "cancelled" // 已取消
)
// 订单超时配置常量
const (
OrderExpireTimeout = 30 * time.Minute // 订单超时时间30分钟
OrderExpireBatchSize = 100 // 每次批量处理超时订单的数量上限
)
// 队列配置常量
const (
QueueCritical = "critical" // 关键任务队列
QueueDefault = "default" // 默认队列
QueueLow = "low" // 低优先级队列
DefaultRetryMax = 5
DefaultTimeout = 10 * time.Minute
DefaultConcurrency = 10
)
// 店铺配置常量
const (
MaxShopLevel = 7 // 店铺最大层级
)
// 验证码配置常量
const (
VerificationCodeLength = 6 // 验证码长度6位数字
VerificationCodeExpiration = 5 * time.Minute // 验证码过期时间5分钟
VerificationCodeRateLimit = 60 * time.Second // 验证码发送频率限制60秒
)
// ======== 默认超级管理员账号配置(用于系统初始化) ========
// DefaultAdminUsername 默认超级管理员用户名
const DefaultAdminUsername = "admin"
// DefaultAdminPassword 默认超级管理员密码
const DefaultAdminPassword = "Admin@123456"
// DefaultAdminPhone 默认超级管理员手机号
const DefaultAdminPhone = "13800000000"
// ======== 企业卡授权相关常量 ========
// AuthorizerType 授权人类型
const (
AuthorizerTypePlatform = UserTypePlatform // 平台用户授权(2)
AuthorizerTypeAgent = UserTypeAgent // 代理账号授权(3)
)
// 自动代购状态常量(强充二阶段异步购买)
const (
AutoPurchaseStatusPending = "pending" // 待处理
AutoPurchaseStatusSuccess = "success" // 成功
AutoPurchaseStatusFailed = "failed" // 失败
)
// 设备保护期相关时长常量
const (
DeviceProtectPeriodDuration = 1 * time.Hour // 设备停/复机保护期时长1小时
DeviceRefreshCooldownDuration = 30 * time.Second // 设备网关刷新冷却时长30秒
)
// 换货单状态常量
const (
ExchangeStatusPendingInfo = 1 // 待填写信息(等待客户端填写收货地址)
ExchangeStatusPendingShip = 2 // 待发货(客户端已填写,等待后台发货)
ExchangeStatusShipped = 3 // 已发货待确认(后台已发货,等待确认完成)
ExchangeStatusCompleted = 4 // 已完成
ExchangeStatusCancelled = 5 // 已取消
)
// 换货资产类型常量
const (
ExchangeAssetTypeIotCard = "iot_card" // 物联网卡
ExchangeAssetTypeDevice = "device" // 设备
)