feat(v2): 对账主体——周期查单收敛 + 已付订单抽查 + 退款修复扫描/卡滞告警 + main 装配 reconcile Runner
Task 5(债务 #6):两条腿收敛对账——① SyncPendingTask 调度 P2 gateway.SyncPendingAttempts 逐 pending attempt 查单收敛(防掉单);② PaidSpotCheckTask 对近期已付 attempt 反查渠道 核对金额/币种,漂移(渠道侧已退款/拒付而本地仍 paid)只告警不改状态。 追加两条 P4 T3 opus review 义务(该 review 产出时本 worktree 已分叉,P4 退款主体在主 checkout;这里对本 worktree 已有的 store.RefundStore/OrderStore 接口——P4 T2,在 base 里——建自愈扫描,设计为可在合并 P4 后继续工作): - RefundApplyTask:退款修复扫描,重算 succeeded 退款之和,自愈「退款成功但订单卡 paid」 的崩溃窗口(MarkRefundStatus 翻 succeeded 后、ApplyRefundToOrder 调用前崩溃)。候选订单 =有 succeeded 退款的订单 ∪ 当前处于 refunding/partially_refunded 态的订单;走既有 ApplyRefundToOrder 条件 UPDATE,目标态与当前态一致时跳过,天然幂等。 - RefundStuckAlertTask:卡滞 processing/manual_pending 退款超阈值(默认 30min)打 WARN, 只观测不改状态;渠道退款查询 API 面留待后续。 main 装配前 4 job(order-expire/usage-refresh/sync-pending/paid-spotcheck)+ 上述两个退款 job 挂上 reconcile.Runner;acctPicker 的 limit_aware 用量源改用 reconcile.NewUsageSource 替 NopUsage。crypto 冷启动 Warm/孤儿扫描(AddCryptoJobs)留给 Task 6 追加。 config.go 新增 ReconcileConfig(含 Task 6 预留的 orphan_* 字段)+ 默认值;crypto.go 补 SetReservationLoader 构造后注入 setter(Task 6 依赖)。 Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_013nMthbVEmQquxBRKb9Fj8u
This commit is contained in:
@@ -14,6 +14,7 @@ type Config struct {
|
||||
AlipaySandbox AlipaySandboxConfig `mapstructure:"alipay_sandbox"`
|
||||
Wechat WechatConfig `mapstructure:"wechat"`
|
||||
QuerySync QuerySyncConfig `mapstructure:"query_sync"`
|
||||
Reconcile ReconcileConfig `mapstructure:"reconcile"`
|
||||
// Biz 通用:任意业务系统(jiu / dudu / …)在 config 的 biz.<name> 下声明即可接入,无需改代码。
|
||||
Biz map[string]BizSystemConfig `mapstructure:"biz"`
|
||||
// Accounts 多账户配置注册表(v2):凭证不写死配置,只存 env 前缀,真值运行时从环境变量取。
|
||||
@@ -98,6 +99,23 @@ type QuerySyncConfig struct {
|
||||
MaxAgeMin int `mapstructure:"max_age_min"` // 只查创建时间在该分钟数内的待支付单
|
||||
}
|
||||
|
||||
// ReconcileConfig v2 后台守护/对账周期任务开关与间隔。
|
||||
type ReconcileConfig struct {
|
||||
Enabled bool `mapstructure:"enabled"`
|
||||
OrderTTLMin int `mapstructure:"order_ttl_min"` // pending 订单存活 TTL(分钟),超则关闭
|
||||
ExpireEverySec int `mapstructure:"expire_every_sec"` // 过期清理间隔
|
||||
SyncEverySec int `mapstructure:"sync_every_sec"` // 查单对账间隔
|
||||
UsageEverySec int `mapstructure:"usage_every_sec"` // 用量快照刷新间隔
|
||||
SpotCheckEverySec int `mapstructure:"spot_check_every_sec"` // 已付抽查间隔
|
||||
SpotCheckWindowMin int `mapstructure:"spot_check_window_min"` // 抽查回溯窗(分钟)
|
||||
OrphanEverySec int `mapstructure:"orphan_every_sec"` // crypto 孤儿扫描间隔(Task 6)
|
||||
OrphanWindowMin int `mapstructure:"orphan_window_min"` // 孤儿扫描回溯窗(Task 6)
|
||||
// —— 以下两项为 P4 T3 opus review 追加义务(退款修复扫描 + 卡滞退款告警),
|
||||
// 本期归到本任务(对账主体)一起装配,brief 原表未列。
|
||||
RefundApplyEverySec int `mapstructure:"refund_apply_every_sec"` // 退款修复扫描 + 卡滞告警 共用间隔
|
||||
RefundStuckWarnMin int `mapstructure:"refund_stuck_warn_min"` // 退款卡滞 processing/manual_pending 告警阈值(分钟)
|
||||
}
|
||||
|
||||
var C Config
|
||||
|
||||
func Load() {
|
||||
@@ -130,6 +148,17 @@ func Load() {
|
||||
viper.SetDefault("query_sync.enabled", true)
|
||||
viper.SetDefault("query_sync.interval_sec", 30)
|
||||
viper.SetDefault("query_sync.max_age_min", 30)
|
||||
viper.SetDefault("reconcile.enabled", true)
|
||||
viper.SetDefault("reconcile.order_ttl_min", 60)
|
||||
viper.SetDefault("reconcile.expire_every_sec", 300)
|
||||
viper.SetDefault("reconcile.sync_every_sec", 30)
|
||||
viper.SetDefault("reconcile.usage_every_sec", 60)
|
||||
viper.SetDefault("reconcile.spot_check_every_sec", 300)
|
||||
viper.SetDefault("reconcile.spot_check_window_min", 180)
|
||||
viper.SetDefault("reconcile.orphan_every_sec", 300)
|
||||
viper.SetDefault("reconcile.orphan_window_min", 180)
|
||||
viper.SetDefault("reconcile.refund_apply_every_sec", 300)
|
||||
viper.SetDefault("reconcile.refund_stuck_warn_min", 30)
|
||||
|
||||
if err := viper.ReadInConfig(); err != nil {
|
||||
log.Println("[config] 未找到 config.yaml,使用默认值 + 环境变量")
|
||||
|
||||
Reference in New Issue
Block a user