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 旧表改名
This commit is contained in:
2026-03-19 13:26:54 +08:00
parent df76e33105
commit e78f5794b9
41 changed files with 5242 additions and 10 deletions

View File

@@ -64,7 +64,8 @@ const (
TaskTypePackageDataReset = "package:data:reset" // 套餐流量重置
// 订单超时任务类型
TaskTypeOrderExpire = "order:expire" // 订单超时自动取消
TaskTypeOrderExpire = "order:expire" // 订单超时自动取消
TaskTypeAutoPurchaseAfterRecharge = "task:auto_purchase_after_recharge" // 充值后自动购包
// 定时任务类型(由 Asynq Scheduler 调度)
TaskTypeAlertCheck = "alert:check" // 告警检查
@@ -205,8 +206,30 @@ const (
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" // 设备
)