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:
@@ -128,6 +128,38 @@ func (s *RefundStore) MarkRefundStatus(refundID string, from, to model.RefundSta
|
||||
return res.RowsAffected > 0, nil
|
||||
}
|
||||
|
||||
// ListDistinctOutTradeNosByStatus 列有某状态退款的 distinct out_trade_no,供退款修复
|
||||
// 扫描(RefundApplyTask)定位「有 succeeded 退款」的候选订单——self-heal「退款成功但
|
||||
// 订单卡 paid」的崩溃窗口(P4 T3 review 义务,见 task-5-brief 外的两条追加义务)。
|
||||
func (s *RefundStore) ListDistinctOutTradeNosByStatus(status model.RefundStatus, limit int) ([]string, error) {
|
||||
if limit <= 0 || limit > 500 {
|
||||
limit = 200
|
||||
}
|
||||
var out []string
|
||||
if err := s.db.Model(&model.Refund{}).Where("status = ?", status).
|
||||
Group("out_trade_no").Order("out_trade_no ASC").Limit(limit).
|
||||
Pluck("out_trade_no", &out).Error; err != nil {
|
||||
return nil, fmt.Errorf("store.ListDistinctOutTradeNosByStatus: %w", err)
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
|
||||
// ListStuckRefunds 列 status 落在给定集合、且 updated_at 早于 before 的退款行,供
|
||||
// 「卡滞 processing/manual_pending 退款告警」只读观测扫描用(不改状态)。updated_at
|
||||
// 用作「进入当前状态」的近似时刻——本表除 MarkRefundStatus/CreateRefundGuarded 外
|
||||
// 不写,近似成立。
|
||||
func (s *RefundStore) ListStuckRefunds(statuses []model.RefundStatus, before time.Time, limit int) ([]model.Refund, error) {
|
||||
if limit <= 0 || limit > 500 {
|
||||
limit = 200
|
||||
}
|
||||
var out []model.Refund
|
||||
if err := s.db.Where("status IN ? AND updated_at < ?", statuses, before).
|
||||
Order("updated_at ASC").Limit(limit).Find(&out).Error; err != nil {
|
||||
return nil, fmt.Errorf("store.ListStuckRefunds: %w", err)
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
|
||||
// ListManualPending lists refunds awaiting manual (crypto) settlement.
|
||||
func (s *RefundStore) ListManualPending(limit int) ([]model.Refund, error) {
|
||||
if limit <= 0 || limit > 200 {
|
||||
|
||||
Reference in New Issue
Block a user