feat: 实名即生效套餐沉默期、延期办理与资产出库时间
Some checks failed
构建并部署到测试环境(无 SSH) / build-and-deploy (push) Failing after 8m39s

- 迁移 000259~000265:套餐记录沉默期字段与扫描索引、套餐默认沉默期、延期政策/流水/订单/批次/明细 5 张表、默认政策与系统配置(总开关默认关闭)、企微审批白名单、卡与设备出库时间及出库记录
- 沉默期设置(订单发放、自动购包、钱包续费)、后台购买时调整(超默认值按政策免审或企微审批)、统一判定与激活闸门、排队与孤儿扫描跳过过期套餐、过期套餐禁止退款、每 10 分钟扫描
- 总开关专用接口与打开前 4 项检查;延期政策;延期资格与计费;H5 自助与后台二维码在线支付(商户池路由)、支付回调与查单恢复、线下登记、特殊/批量延期、异常重试与原路退款;沉默期审批场景与终态处理
- 换货沉默期流水与出库时间;卡/设备列表、详情、导出与出库记录接口;延期订单与即将过期套餐列表及导出;财务流水纳入延期支付
- 沉默期与出库时间回填工具 cmd/silence-backfill;前端接口变更说明

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
邹进
2026-10-27 16:32:58 +09:00
parent d2b0d2f534
commit 909f4d0ec2
112 changed files with 10473 additions and 82 deletions

View File

@@ -40,7 +40,7 @@ func (s *IotCardDataSource) Count(ctx context.Context, params ExportParams) (int
// Headers 返回 IoT 卡导出表头。
func (s *IotCardDataSource) Headers(ctx context.Context, params ExportParams) ([]string, error) {
// 「关联手机号」「套餐到期时间」「使用流量(GB)」「剩余流量(GB)」依次固定追加在尾部:导出表头在 dispatch 阶段落库,历史任务重导出沿用同一列序。
return []string{"ICCID", "MSISDN", "绑定设备虚拟号", "运营商", "店铺名称", "绑定设备名称", "是否实名", "实名时间", "网络状态", "套餐名称", "使用流量(MB)", "剩余流量(MB)", iotCardExportAssociatedPhoneHeader, iotCardExportFinalExpiryHeader, iotCardExportUsageGBHeader, iotCardExportRemainingGBHeader, iotCardExportPollingHeader}, nil
return []string{"ICCID", "MSISDN", "绑定设备虚拟号", "运营商", "店铺名称", "绑定设备名称", "是否实名", "实名时间", "网络状态", "套餐名称", "使用流量(MB)", "剩余流量(MB)", iotCardExportAssociatedPhoneHeader, iotCardExportFinalExpiryHeader, iotCardExportUsageGBHeader, iotCardExportRemainingGBHeader, iotCardExportPollingHeader, iotCardExportOutboundHeader}, nil
}
// Fetch 按 offset/limit 查询 IoT 卡导出数据。
@@ -62,6 +62,7 @@ func (s *IotCardDataSource) Fetch(ctx context.Context, params ExportParams, offs
c.real_name_status,
c.enable_polling,
c.first_realname_at,
c.outbound_at,
c.network_status,
COALESCE(pkg.package_name, '') AS package_name,
COALESCE(pkg.data_usage_mb, 0) AS data_usage_mb,
@@ -82,7 +83,7 @@ func (s *IotCardDataSource) Fetch(ctx context.Context, params ExportParams, offs
if err != nil {
return nil, err
}
includeExpiry, includeGB, includePolling := iotCardExportTailColumns(params.ResolvedHeaders)
includeExpiry, includeGB, includePolling, includeOutbound := iotCardExportTailColumns(params.ResolvedHeaders)
var finalExpiries map[uint]string
if includeExpiry {
finalExpiries, err = s.loadFinalExpiries(ctx, cardIDs)
@@ -118,6 +119,9 @@ func (s *IotCardDataSource) Fetch(ctx context.Context, params ExportParams, offs
if includePolling {
row = append(row, yesNo(item.EnablePolling))
}
if includeOutbound {
row = append(row, formatOptionalTime(item.OutboundAt))
}
rows = append(rows, row)
}
return rows, nil
@@ -141,19 +145,21 @@ func (s *IotCardDataSource) loadFinalExpiries(ctx context.Context, cardIDs []uin
// iotCardExportTailColumns 按冻结表头末列识别尾部版本:末列「是否轮询」输出到期、GB 与是否轮询列,
// 末列「剩余流量(GB)」输出到期列与 GB 列,末列「套餐到期时间」只输出到期列,更早的表头都不输出;无冻结表头按当前版本输出。
func iotCardExportTailColumns(headers []string) (includeExpiry, includeGB, includePolling bool) {
func iotCardExportTailColumns(headers []string) (includeExpiry, includeGB, includePolling, includeOutbound bool) {
if len(headers) == 0 {
return true, true, true
return true, true, true, true
}
switch headers[len(headers)-1] {
case iotCardExportOutboundHeader:
return true, true, true, true
case iotCardExportPollingHeader:
return true, true, true
return true, true, true, false
case iotCardExportRemainingGBHeader:
return true, true, false
return true, true, false, false
case iotCardExportFinalExpiryHeader:
return true, false, false
return true, false, false, false
default:
return false, false, false
return false, false, false, false
}
}
@@ -198,6 +204,12 @@ func (s *IotCardDataSource) baseQuery(ctx context.Context) *gorm.DB {
// 导出任务运行在 Worker 中,权限只能使用任务创建时保存的店铺范围快照。
func (s *IotCardDataSource) applyFilters(ctx context.Context, query *gorm.DB, params ExportParams) *gorm.DB {
query = applyExportShopScope(query, params, "c.shop_id")
if start, ok := filterTime(params.Filters, "outbound_start"); ok {
query = query.Where("c.outbound_at >= ?", start)
}
if end, ok := filterTime(params.Filters, "outbound_end"); ok {
query = query.Where("c.outbound_at <= ?", end)
}
if isStandalone, ok := filterOptionalBool(params.Filters, "is_standalone"); ok {
query = query.Where("c.is_standalone = ?", isStandalone)
@@ -302,6 +314,8 @@ const (
iotCardExportRemainingGBHeader = "剩余流量(GB)"
// iotCardExportPollingHeader 是「是否轮询」列的表头,位于 GB 流量列之后、导出最后一列。
iotCardExportPollingHeader = "是否轮询"
// iotCardExportOutboundHeader 出库时间(当前世代首次购买套餐的支付时间)
iotCardExportOutboundHeader = "出库时间"
)
type iotCardExportRow struct {
@@ -314,6 +328,7 @@ type iotCardExportRow struct {
DeviceName string `gorm:"column:device_name"`
RealNameStatus int `gorm:"column:real_name_status"`
FirstRealnameAt *time.Time `gorm:"column:first_realname_at"`
OutboundAt *time.Time `gorm:"column:outbound_at"`
NetworkStatus int `gorm:"column:network_status"`
PackageName string `gorm:"column:package_name"`
DataUsageMB int64 `gorm:"column:data_usage_mb"`