S2-D5 利润/返点/三方对账——S2 泳道收官: profit.go(UserProfit 时间线价收入+成本占比分摊+直线下级返点 R4 历史不重算=不落档现算+parent_id 子树 Path 过滤+平台净利双口径;ChannelProfit 同分母分摊 Σ守恒;阶梯不进分析=与账单金额差为口径差异)+reconcile.go(三方对账:账号=明细直查↔billing_consume_log↔settle_customer 条数/通道两方/上家=当前归并口径重推↔快照;金额不比=快照语义防调价噪音;bill_missing 不判失败;AllZero=出口判据)+cmd/reconcile/settle-check(-period/-json,exit 0=all_zero)+handler /stats/profit/users·channels 双端点(平台角色门,缺省窗本月至今)+openapi 描述对齐;测试 5 件(利润树/返点/分摊/子树/守恒+对账全零+篡改逐项暴露+missing 语义+handler 数值/403/坏日期);真机全链:2026-10 空月种链→汇总 1/1→下家 0.2→阶梯覆写 0.1→结账 SettleRecord→上家 2/0.1→利润双端点(rev0.2 时间线 vs 账单 0.1 口径差异实证)→settle-check all_zero=true EXIT=0(S2 出口判据)→清理 11 项零残留;走查脚本扩 D4/D5 全域 AI 预走查 27 PASS/0 FAIL+修复两存量 bug(明细 ID 9302 段超 int64 拒收→7302 段/清理段 $ON $B0 单引号不展开致 SQL 语法错→printf|mysql_pipe);门禁 vet/-race 39 包/lint 0;收官判定 s2-closeout.md(出口两项全过+六项裁决 R1~R6 全闭环)+验收单 s2-d5.md+CHANGELOG+memory-bank 回填
This commit is contained in:
@@ -0,0 +1,68 @@
|
||||
// reconcile/settle-check S2-D5:三方对账子命令——明细直查 vs 日汇总 vs
|
||||
// 结算单(diff=0 为 S2 泳道出口判据)。
|
||||
//
|
||||
// 用法(仓库根目录):go run ./cmd/reconcile/settle-check -period 2026-11 [-json]
|
||||
// 退出码:0=三方差异全零;1=存在差异(明细见输出);2=运行错误。
|
||||
// 注意:金额不在比对范围(结算单金额=出账时点价/阶梯快照,事后调价重算必生
|
||||
// 噪音,口径见 settle/reconcile.go 头注);账单未生成=流程状态,计入
|
||||
// bill_missing 但不影响 AllZero 判定。
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"flag"
|
||||
"fmt"
|
||||
"os"
|
||||
"time"
|
||||
|
||||
"go.uber.org/zap"
|
||||
|
||||
"go-sms/internal/app"
|
||||
"go-sms/internal/service/settle"
|
||||
)
|
||||
|
||||
func main() {
|
||||
period := flag.String("period", time.Now().Format("2006-01"), "对账账期 YYYY-MM(缺省=当前月)")
|
||||
asJSON := flag.Bool("json", false, "输出完整 JSON 报告(缺省=人类可读摘要+异常行)")
|
||||
flag.Parse()
|
||||
|
||||
a, err := app.New(app.Options{ServiceName: "reconcile-settle-check"})
|
||||
if err != nil {
|
||||
fmt.Fprintln(os.Stderr, "app init:", err)
|
||||
os.Exit(2)
|
||||
}
|
||||
rep, err := settle.NewService(a.DB()).ReconcilePeriod(context.Background(), *period)
|
||||
if err != nil {
|
||||
a.Lg().Error("settle_check_failed", zap.String("period", *period), zap.Error(err))
|
||||
fmt.Fprintln(os.Stderr, "reconcile:", err)
|
||||
os.Exit(2)
|
||||
}
|
||||
|
||||
if *asJSON {
|
||||
out, _ := json.MarshalIndent(rep, "", " ")
|
||||
fmt.Println(string(out))
|
||||
} else {
|
||||
s := rep.Summary
|
||||
fmt.Printf("settle-check period=%s as_of=%s\n", rep.Period, rep.AsOf.Format(time.RFC3339))
|
||||
fmt.Printf("accounts: checked=%d diffs=%d bill_missing=%d\n", s.AccountsChecked, s.AccountDiffs, s.BillMissing)
|
||||
fmt.Printf("channels: checked=%d diffs=%d\n", s.ChannelsChecked, s.ChannelDiffs)
|
||||
fmt.Printf("upstreams: checked=%d diffs=%d\n", s.UpstreamsChecked, s.UpstreamDiffs)
|
||||
for _, r := range rep.Accounts {
|
||||
fmt.Printf(" [DIFF] account=%d detail=%d consume=%d bill=%v\n",
|
||||
r.AccountID, r.DetailSuccess, r.ConsumeSuccess, r.BillSuccess)
|
||||
}
|
||||
for _, r := range rep.Channels {
|
||||
fmt.Printf(" [DIFF] channel=%d detail=%d daily=%d\n",
|
||||
r.ChannelID, r.DetailSuccess, r.DailySuccess)
|
||||
}
|
||||
for _, r := range rep.Upstreams {
|
||||
fmt.Printf(" [DIFF] upstream=%d daily=%d bill=%v\n",
|
||||
r.UpstreamID, r.DailyCount, r.BillSuccess)
|
||||
}
|
||||
fmt.Printf("all_zero=%v\n", s.AllZero)
|
||||
}
|
||||
if !rep.Summary.AllZero {
|
||||
os.Exit(1)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user