S2-D1 结算域表设计评审+迁移 v20+契约草案: 六项裁决定稿(docs/review/s2-settle-table-review.md)——R1 出账时刻计价(用户拍板:明细 Fee 保持片数/send 域零改动,金额=Σ日成功条数×生效单价,时间线+阶梯 D4 price.go 单点推导)/R2 消耗事实源统一 billing_consume_log+stats_channel_daily,stats_user_daily 废弃/R3 充值双通道(即时+BillingOrder 审核)/R4 rebate_rate 单级返点历史不重算/R5 settle_ladder 阶梯表/R6 条/元口径单点换算;v20_settle_domain(billing_consume_log +unknown_count/updated_at,account_user +rebate_rate,DROP stats_user_daily,settle_ladder 建表,casbin 补 ops settle:write/customer settle:read;显式 ALTER+HasColumn 守卫/空库 HasTable 守卫三路径收敛,零新增索引复用 v16);实体同步 All() 39 个;openapi v1.3.0 +20 结算端点(js-yaml 84 paths 过);迁移测试末七窗口 v14..v20 两遍幂等+五项 v20 断言;门禁全绿:vet 0/-race 38 包零 FAIL/lint 0/集成 AutoMigrate 39 表+Casbin PASS;dev 库实跑 v19→v20+information_schema 五项核验过;验收单 s2-d1.md+CHANGELOG+memory-bank 回填
This commit is contained in:
@@ -2,6 +2,13 @@
|
||||
|
||||
> 本仓 CHANGELOG 自重建起记(POC 明细见归档仓 /data/poc-archive/repos/go-sms.git 的 CHANGELOG.md,已冻结)。
|
||||
|
||||
## 2026-11-14(上午)· S2-D1 结算域表设计评审 + 迁移 v20 + 契约草案
|
||||
|
||||
- **S2 结算域开工(D 层,5 工作日,出口=结算单测+对账差异 0)**。方案细化(12 维上下文研读+代码实证:结算 5 表 v0 已建且业务代码零使用/StatsUserDaily·StatsChannelDaily 双空壳/明细 Fee=片数非金额/v16 已建通道聚合索引)→ **六项表设计裁决定稿**(`docs/review/s2-settle-table-review.md`):R1 出账时刻计价(用户拍板:明细 Fee 保持片数、**send 域零改动**,金额=Σ日成功条数×生效单价按时间线+阶梯推导)/R2 消耗事实源统一 billing_consume_log+stats_channel_daily、**stats_user_daily 废弃**/R3 充值双通道(即时到账保留+BillingOrder 审核流)/R4 rebate_rate 单级返点、历史不重算/R5 settle_ladder 阶梯表/R6 条/元口径单点换算(出账引擎)。
|
||||
- **迁移 v20_settle_domain**:billing_consume_log +unknown_count/updated_at;account_user +rebate_rate;DROP stats_user_daily;新表 settle_ladder;casbin 补 ops settle:write/customer settle:read(NOT EXISTS 逐条守卫)。加列=显式 SQL+HasColumn 守卫、空库=HasTable 守卫整表 AutoMigrate(v16/v17 抹索引教训,三路径收敛);**零新增索引**(复用 v16 idx_detail_channel_created);init_schema.sql 不动(Day11 基线惯例)。实体同步(All() 39 个,SettleLadder 随 v18/v19 惯例不进 All())。
|
||||
- **openapi v1.3.0 契约草案**:+20 端点(billing/orders 审核族/consume 消耗查询/settle customer·upstream 生成-确认-结账-导出/ladder 阶梯 CRUD/profit 双分析/ops 手动汇总),js-yaml 解析 84 paths 通过;gen-dict 无新增 x-isc-dict 零影响。
|
||||
- **门禁全绿**:vet 0 / **-race 全量 38 包 ok 零 FAIL** / lint 0 issues / 迁移单测(末七窗口 v14..v20 两遍幂等+五项 v20 断言)/ 集成 TestMySQL_AutoMigrate 39 表 + Casbin PASS;**dev 库实跑 v19→v20**(存量 ALTER 路径)+ information_schema 五项核验全过。验收单 `docs/acceptance/s2-d1.md`。
|
||||
|
||||
## 2026-11-13(深夜)· 前端质量门根修 + Dashboard 信息密度重构(FE-Design P0~P3)
|
||||
|
||||
- **P0 · vitest 91/137 红→138/138 绿(新机首跑暴露的环境级 bug)**:根因=vitest(mode=test)不加载 `.env.development` → `request.ts` 模块顶层 `baseURL=undefined`,而各 spec 内 `vi.stubEnv` 晚于被测模块求值无效 → 全部请求相对路径裸奔 → msw 全量 unhandled(实测打印 `POST /auth/login`)。老机靠 gitignored 本地 env 掩盖。修法=**`vitest.setup.ts` 顶部 stubEnv 一处生效**(setupFiles 先于测试文件模块求值);附带 pnpm 自动 install 对 pnpm-lock.yaml 的无关重排已回滚(最小变更纪律)。
|
||||
|
||||
+236
-1
@@ -1,7 +1,7 @@
|
||||
openapi: 3.0.3
|
||||
info:
|
||||
title: go-sms API v1(阶段 2:账号与权限)
|
||||
version: 1.2.0
|
||||
version: 1.3.0
|
||||
description: |
|
||||
阶段 2(Day 21-30)交付的账号与权限域全部端点。
|
||||
统一响应 {code,msg,data}:code=ISC:000 成功;错误码三位制(ISC:4xx/5xx)。
|
||||
@@ -19,6 +19,8 @@ tags:
|
||||
- {name: permissions, description: 二级权限与导出(Day 25)}
|
||||
- {name: audit, description: 审计查询(Day 29)}
|
||||
- {name: channel, description: 通道 CRUD/测试工具/拦截配置(Day 31-36)}
|
||||
- {name: billing, description: 充值订单审核/消耗日汇总(S2)}
|
||||
- {name: settle, description: 下家/上家月结与阶梯价(S2)}
|
||||
paths:
|
||||
/auth/login:
|
||||
post:
|
||||
@@ -751,6 +753,239 @@ paths:
|
||||
cmpp_max_conns: {type: integer, description: "Day 62:每账号最大 CMPP 连接数(0=不修改;-1=恢复系统默认;1~1024=设置)"}
|
||||
cmpp_speed: {type: integer, description: "Day 62:单链提交限速 条/s(0=不修改;-1=恢复系统默认;1~100000=设置)"}
|
||||
responses: {"200": {description: "secret(=库值原文,重发/自定义时返回);cmpp_password(库值即密码)"}}
|
||||
# ---- S2 结算域(契约草案 2026-11-14;表设计裁决 docs/review/s2-settle-table-review.md;
|
||||
# 金额口径=元,条数口径=条;R1=出账时刻按日成功条数×生效单价推导,明细 Fee 不金额化) ----
|
||||
/billing/orders:
|
||||
get:
|
||||
tags: [billing]
|
||||
summary: 充值订单分页(account_id/pay_status 过滤;admin/ops)
|
||||
parameters:
|
||||
- {name: page, in: query, schema: {type: integer, default: 1}}
|
||||
- {name: page_size, in: query, schema: {type: integer, default: 20, maximum: 100}}
|
||||
- {name: account_id, in: query, schema: {type: integer, format: int64}}
|
||||
- {name: pay_status, in: query, schema: {type: integer, enum: [0, 1, 2], description: "0待确认 1已到账 2失败"}}
|
||||
responses: {"200": {description: total+list}}
|
||||
post:
|
||||
tags: [billing]
|
||||
summary: 创建充值订单(pay_status=0 待确认,不动余额;复用 account:recharge 二级权限;count=到账条数,amount=元记账)
|
||||
requestBody:
|
||||
required: true
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
type: object
|
||||
required: [account_id, count]
|
||||
properties:
|
||||
account_id: {type: integer, format: int64}
|
||||
count: {type: integer, format: int64, description: 到账条数(>0;确认后余额自增此值)}
|
||||
amount: {type: number, description: 金额(元;记账与账单展示,不参与余额)}
|
||||
pay_type: {type: string}
|
||||
remark: {type: string}
|
||||
responses: {"200": {description: 订单(含 order_no)}, "400": {description: 参数非法}}
|
||||
/billing/orders/{id}/confirm:
|
||||
post:
|
||||
tags: [billing]
|
||||
summary: 付款审核确认(0→1;事务=状态 CAS+余额原子自增 count+流水 ref_id=order_no;并发/重复确认被 CAS 拒)
|
||||
parameters: [{name: id, in: path, required: true, schema: {type: integer}}]
|
||||
responses: {"200": {description: 新余额}, "409": {description: 状态非 0(已确认/已驳回)}}
|
||||
/billing/orders/{id}/reject:
|
||||
post:
|
||||
tags: [billing]
|
||||
summary: 驳回(0→2;不涉余额)
|
||||
parameters: [{name: id, in: path, required: true, schema: {type: integer}}]
|
||||
responses: {"200": {description: ok}, "409": {description: 状态非 0}}
|
||||
/billing/consume:
|
||||
get:
|
||||
tags: [billing]
|
||||
summary: 消耗日汇总查询(账号×业务×天;admin/ops 全量,customer 仅自己;默认近 7 天)
|
||||
parameters:
|
||||
- {name: account_id, in: query, schema: {type: integer, format: int64}}
|
||||
- {name: business, in: query, schema: {type: string}}
|
||||
- {name: date_from, in: query, schema: {type: string, format: date}}
|
||||
- {name: date_to, in: query, schema: {type: string, format: date}}
|
||||
- {name: page, in: query, schema: {type: integer, default: 1}}
|
||||
- {name: page_size, in: query, schema: {type: integer, default: 20, maximum: 100}}
|
||||
responses: {"200": {description: "list{account_id,business,stat_date,submit/success/fail/unknown_count,fee_total(单位=条)"}}
|
||||
/settle/customer:
|
||||
get:
|
||||
tags: [settle]
|
||||
summary: 下家月结单分页(period/account_id/status 过滤;admin/ops 全量,customer 仅自己)
|
||||
parameters:
|
||||
- {name: page, in: query, schema: {type: integer, default: 1}}
|
||||
- {name: page_size, in: query, schema: {type: integer, default: 20, maximum: 100}}
|
||||
- {name: period, in: query, schema: {type: string, description: 账期 YYYY-MM}}
|
||||
- {name: account_id, in: query, schema: {type: integer, format: int64}}
|
||||
- {name: status, in: query, schema: {type: integer, enum: [0, 1, 2], description: "0草稿 1已确认 2已结账"}}
|
||||
responses: {"200": {description: total+list}}
|
||||
/settle/customer/generate:
|
||||
post:
|
||||
tags: [settle]
|
||||
summary: 生成/重算下家账期结算单(settle:write;幂等 uk(account,period);status=2 拒重算;金额=Σ日成功条数×生效单价,阶梯档覆写)
|
||||
requestBody:
|
||||
required: true
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
type: object
|
||||
required: [period]
|
||||
properties:
|
||||
period: {type: string, description: 账期 YYYY-MM}
|
||||
account_id: {type: integer, format: int64, description: 缺省=全账号逐个生成}
|
||||
responses: {"200": {description: 生成/重算统计}, "409": {description: 含已结账单}}
|
||||
/settle/customer/{id}:
|
||||
get:
|
||||
tags: [settle]
|
||||
summary: 结算单详情(单头+按天明细,取自 billing_consume_log;customer 仅自己)
|
||||
parameters: [{name: id, in: path, required: true, schema: {type: integer}}]
|
||||
responses: {"200": {description: "单头+days[]"}, "404": {description: 不存在}}
|
||||
/settle/customer/{id}/confirm:
|
||||
post:
|
||||
tags: [settle]
|
||||
summary: 确认结算单(0草稿→1已确认;人工核对锁账,拒绝静默重算;settle:write)
|
||||
parameters: [{name: id, in: path, required: true, schema: {type: integer}}]
|
||||
responses: {"200": {description: ok}, "409": {description: 状态非 0}}
|
||||
/settle/customer/{id}/settle:
|
||||
post:
|
||||
tags: [settle]
|
||||
summary: 结账(1→2;写 settle_record(direction=1);终态拒重算;settle:write)
|
||||
parameters: [{name: id, in: path, required: true, schema: {type: integer}}]
|
||||
requestBody:
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
type: object
|
||||
properties:
|
||||
pay_type: {type: string}
|
||||
remark: {type: string}
|
||||
responses: {"200": {description: ok}, "409": {description: 状态非 1}}
|
||||
/settle/customer/{id}/export:
|
||||
get:
|
||||
tags: [settle]
|
||||
summary: 结算单 XLSX 导出(单头+按天明细)
|
||||
parameters: [{name: id, in: path, required: true, schema: {type: integer}}]
|
||||
responses: {"200": {description: application/octet-stream}}
|
||||
/settle/upstream:
|
||||
get:
|
||||
tags: [settle]
|
||||
summary: 上家月结单分页(period/upstream_id/status 过滤;admin/ops)
|
||||
parameters:
|
||||
- {name: page, in: query, schema: {type: integer, default: 1}}
|
||||
- {name: page_size, in: query, schema: {type: integer, default: 20, maximum: 100}}
|
||||
- {name: period, in: query, schema: {type: string}}
|
||||
- {name: upstream_id, in: query, schema: {type: integer, format: int64}}
|
||||
- {name: status, in: query, schema: {type: integer, enum: [0, 1, 2]}}
|
||||
responses: {"200": {description: total+list}}
|
||||
/settle/upstream/generate:
|
||||
post:
|
||||
tags: [settle]
|
||||
summary: 生成/重算上家账期结算单(settle:write;按 channel.upstream_id 归并;计费口径随通道 billing_mode=success/success_unknown/all)
|
||||
requestBody:
|
||||
required: true
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
type: object
|
||||
required: [period]
|
||||
properties:
|
||||
period: {type: string, description: 账期 YYYY-MM}
|
||||
upstream_id: {type: integer, format: int64, description: 缺省=全上家逐个生成}
|
||||
responses: {"200": {description: 生成/重算统计}, "409": {description: 含已结账单}}
|
||||
/settle/upstream/{id}:
|
||||
get:
|
||||
tags: [settle]
|
||||
summary: 上家结算单详情(单头+按通道×天明细,取自 stats_channel_daily)
|
||||
parameters: [{name: id, in: path, required: true, schema: {type: integer}}]
|
||||
responses: {"200": {description: "单头+channels[]days[]"}, "404": {description: 不存在}}
|
||||
/settle/upstream/{id}/settle:
|
||||
post:
|
||||
tags: [settle]
|
||||
summary: 结账(1→2;写 settle_record(direction=2);settle:write)
|
||||
parameters: [{name: id, in: path, required: true, schema: {type: integer}}]
|
||||
requestBody:
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
type: object
|
||||
properties:
|
||||
pay_type: {type: string}
|
||||
remark: {type: string}
|
||||
responses: {"200": {description: ok}, "409": {description: 状态非 1}}
|
||||
/settle/upstream/{id}/export:
|
||||
get:
|
||||
tags: [settle]
|
||||
summary: 上家结算单 XLSX 导出(单头+通道×天明细)
|
||||
parameters: [{name: id, in: path, required: true, schema: {type: integer}}]
|
||||
responses: {"200": {description: application/octet-stream}}
|
||||
/settle/ladder:
|
||||
get:
|
||||
tags: [settle]
|
||||
summary: 阶梯价档位列表(owner_type/owner_id 过滤;settle:write 可写,read 全角色)
|
||||
parameters:
|
||||
- {name: owner_type, in: query, schema: {type: string, enum: [account, upstream]}}
|
||||
- {name: owner_id, in: query, schema: {type: integer, format: int64}}
|
||||
responses: {"200": {description: 档位列表(按 tier_from 升序)}}
|
||||
post:
|
||||
tags: [settle]
|
||||
summary: 新增档位(owner×tier_from 唯一;0=首档下限;settle:write)
|
||||
requestBody:
|
||||
required: true
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
type: object
|
||||
required: [owner_type, owner_id, tier_from, price]
|
||||
properties:
|
||||
owner_type: {type: string, enum: [account, upstream]}
|
||||
owner_id: {type: integer, format: int64}
|
||||
tier_from: {type: integer, format: int64, description: 档位下限(含,条/月)}
|
||||
price: {type: number, description: 该档单价(元/条)}
|
||||
responses: {"200": {description: ok}, "400": {description: 档位重叠/参数非法}}
|
||||
/settle/ladder/{id}:
|
||||
put:
|
||||
tags: [settle]
|
||||
summary: 修改档位(price/tier_from;settle:write)
|
||||
parameters: [{name: id, in: path, required: true, schema: {type: integer}}]
|
||||
requestBody:
|
||||
content:
|
||||
application/json:
|
||||
schema: {type: object, properties: {tier_from: {type: integer, format: int64}, price: {type: number}}}
|
||||
responses: {"200": {description: ok}}
|
||||
delete:
|
||||
tags: [settle]
|
||||
summary: 删除档位(settle:write)
|
||||
parameters: [{name: id, in: path, required: true, schema: {type: integer}}]
|
||||
responses: {"200": {description: ok}}
|
||||
/stats/profit/users:
|
||||
get:
|
||||
tags: [settle]
|
||||
summary: 用户利润分析(含下级树聚合:revenue=Σ结算额,cost=其流量通道成本分摊,rebate=返点支出;历史归属不随换上级重算)
|
||||
parameters:
|
||||
- {name: date_from, in: query, schema: {type: string, format: date}}
|
||||
- {name: date_to, in: query, schema: {type: string, format: date}}
|
||||
- {name: parent_id, in: query, schema: {type: integer, format: int64, description: 以该账号为根的子树(缺省=全平台)}}
|
||||
- {name: page, in: query, schema: {type: integer, default: 1}}
|
||||
- {name: page_size, in: query, schema: {type: integer, default: 20, maximum: 100}}
|
||||
responses: {"200": {description: "list{account_id,revenue,cost,rebate,profit}(元)"}}
|
||||
/stats/profit/channels:
|
||||
get:
|
||||
tags: [settle]
|
||||
summary: 通道利润分析(收入=Σ日成功条数×用户价,成本=Σ×通道价;date_from/date_to/channel_id)
|
||||
parameters:
|
||||
- {name: date_from, in: query, schema: {type: string, format: date}}
|
||||
- {name: date_to, in: query, schema: {type: string, format: date}}
|
||||
- {name: channel_id, in: query, schema: {type: integer, format: int64}}
|
||||
- {name: page, in: query, schema: {type: integer, default: 1}}
|
||||
- {name: page_size, in: query, schema: {type: integer, default: 20, maximum: 100}}
|
||||
responses: {"200": {description: "list{channel_id,upstream_id,success_count,revenue,cost,profit}(元)"}}
|
||||
/ops/settle/aggregate:
|
||||
post:
|
||||
tags: [settle]
|
||||
summary: 手动触发消耗日汇总回补(date 缺省=昨日;幂等 UPSERT;运维口径,admin)
|
||||
requestBody:
|
||||
content:
|
||||
application/json:
|
||||
schema: {type: object, properties: {date: {type: string, format: date, description: 可回补历史日期(明细热窗内)}}}
|
||||
responses: {"200": {description: "落账行数(账号/通道两表)"}}
|
||||
components:
|
||||
securitySchemes:
|
||||
bearerAuth: {type: http, scheme: bearer, bearerFormat: JWT}
|
||||
|
||||
@@ -0,0 +1,45 @@
|
||||
# S2-D1 表设计评审 + 迁移 v20 + 契约草案 人工验收单(2026-11-14)
|
||||
|
||||
> 前置:S1 泳道收官(s1-b-closeout.md,24h 门槛在途 11-14 17:55 期满回填)。
|
||||
> 本单覆盖 S2 结算域 D1:六项表设计裁决定稿 + v20_settle_domain 落地 + openapi 契约草案。
|
||||
|
||||
## 一、交付物
|
||||
|
||||
| # | 任务 | 结果 | 证据 |
|
||||
|---|---|---|---|
|
||||
| 1 | **表设计评审纪要**(六项裁决 R1~R6) | ✅ | `docs/review/s2-settle-table-review.md`;R1 计价模型=出账时刻计价(用户 2026-11-14 拍板:明细 Fee 保持片数、send 域零改动) |
|
||||
| 2 | **迁移 v20_settle_domain** | ✅ | migrations.go 末块:billing_consume_log +unknown_count/updated_at;account_user +rebate_rate;DROP stats_user_daily(R2 单一事实源);新表 settle_ladder;casbin 补 ops settle:write / customer settle:read(NOT EXISTS 逐条守卫) |
|
||||
| 3 | **实体同步** | ✅ | entity/billing.go(补列+SettleLadder+SettleCustomer 状态注释对齐 0草稿/1已确认/2已结账);account.go(RebateRate);system.go(StatsUserDaily 删除留裁决注记);base.go All() 39 实体 |
|
||||
| 4 | **openapi 契约草案 v1.3.0** | ✅ | 20 个新端点(billing 5/settle 15:充值订单审核/消耗查询/下家/上家月结/阶梯/利润/手动汇总);js-yaml 解析通过(84 paths);版本 1.2.0→1.3.0 |
|
||||
| 5 | **迁移测试更新** | ✅ | base_test.go:末七窗口 v13..v19→v14..v20,终版断言 v20,新增 v20 五项断言;v13 断言随窗口右移移除(注记留痕) |
|
||||
|
||||
## 二、门禁(七件套后端件)
|
||||
|
||||
| 项 | 结果 |
|
||||
|---|---|
|
||||
| go vet ./... | ✅ RC=0 |
|
||||
| go test -race ./...(全量) | ✅ 全绿(回填于本单尾部) |
|
||||
| golangci-lint v2.1.6 | ✅ 0 issues |
|
||||
| 迁移单测(sqlite 末七两遍幂等) | ✅ TestMigrations_IdempotentAndVersioned 含 v20 断言通过 |
|
||||
| openapi YAML 解析 | ✅ js-yaml 84 paths |
|
||||
| gen-dict/-check | ✅ 未新增 x-isc-dict,dict.ts 无需再生成 |
|
||||
|
||||
## 三、设计要点留痕
|
||||
|
||||
1. **不触碰已收官 send 域**(R1):计价全部收拢 D4 出账引擎 settle/price.go(PriceAt 时间线回溯+阶梯落档);条→元换算全链单点(R6)。
|
||||
2. **v20 加列走显式 SQL+HasColumn 守卫、空库走 HasTable 守卫 AutoMigrate 整表**——glebarez SQLite 下 entity 加字段触发表 diff 重建抹索引(v16/v17 教训,三条路径收敛:全量新库 v0 直含/存量库 ALTER/末七窗口空库建表)。
|
||||
3. **零新增聚合索引**:通道日汇总复用 v16 `idx_detail_channel_created(channel_id, created_at)`。
|
||||
4. **init_schema.sql 不动**(Day11 基线参考,权威=migrate 链,v16/v17 演进均未回写,维持惯例)。
|
||||
5. **stats_channel_daily 零 schema 变更**(unknown_count/cost_total 原有;grain=通道×天,不加 business——通道价格体系不分业务,视频走独立通道)。
|
||||
6. **casbin 策略随 v20 逐条 NOT EXISTS 守卫种入**(v5 的 n>0 整体跳过守卫不适用于增量)。
|
||||
|
||||
## 四、验收结论
|
||||
|
||||
**S2-D1 通过。** D2(消耗日汇总引擎)开工前置=本单归档+CHANGELOG+进度回填。
|
||||
|
||||
## 五、附:真库验证(dev MySQL 13306,2026-11-14)
|
||||
|
||||
- `cmd/migrate version` v19_longsms_pending → `up` → **v20_settle_domain**(存量库 ALTER 路径实测通过);
|
||||
- information_schema 核验:billing_consume_log unknown_count/updated_at 两列 ✓、account_user.rebate_rate ✓、settle_ladder 建表 ✓、stats_user_daily 已 DROP ✓、casbin_rule 新增 ops settle:write / customer settle:read ✓;
|
||||
- 集成测试:TestMySQL_AutoMigrate 39 表 PASS;Casbin 集成 PASS(新策略不破坏 enforcer 加载);
|
||||
- `go test -race ./...` 全量 38 包 ok,零 FAIL。
|
||||
@@ -0,0 +1,52 @@
|
||||
# S2 结算域·表设计评审纪要(D1,2026-11-14)
|
||||
|
||||
> 评审输入:《Go-sms-重建计划.md》S2 行(5 工作日,D 层结算域后端全量,出口=结算单测+对账差异=0)/
|
||||
> 《Go-sms-需求分析.md》§2.6 计费与结算(下家结算·上家结算·消耗日志·充值日志·利润分析,P1)/
|
||||
> 《Go-sms-重建设计规范.md》性能三律与幂等三锚 / 代码实证(结算 5 表实体自 v0 已建且业务代码零使用、
|
||||
> StatsUserDaily/StatsChannelDaily 同为零写入方空壳、明细 Fee=片数非金额、v16 已建 idx_detail_channel_created)。
|
||||
|
||||
## 一、六项裁决
|
||||
|
||||
| # | 决策点 | 裁决 | 依据 |
|
||||
|---|---|---|---|
|
||||
| **R1** | 计价模型 | **出账时刻计价**:明细 Fee 保持片数语义(send 域零改动);结算金额=Σ(日成功条数×生效单价),按 AccountPrice/ChannelPrice 时间线(EffectiveAt≤当日取最近)+阶梯档推导 | 用户 2026-11-14 拍板。与需求「分时单价与结算联动」一致;不触碰已收官域;调价可追溯;Fee≡片数口径(Day70)不动摇 |
|
||||
| **R2** | 消耗事实源 | **billing_consume_log(账号×业务×天)+ stats_channel_daily(通道×天)为事实源;stats_user_daily 废弃**(v20 DROP,实体删除,All() 移除) | 两表同粒度双空壳;单一事实源纪律,双写必漂移;表名即域归属 |
|
||||
| **R3** | 充值双通道 | **保留** `/accounts/:id/recharge` 即时到账(语义=已确认付款快捷入账)+ **新增** BillingOrder 审核流(0待→1到账/2失败;confirm=状态 CAS+余额自增 count+流水 ref_id=order_no 同事务) | 兼容存量 API 与权限测试;「付款审核确认」为需求 §2.6 明示项 |
|
||||
| **R4** | 返点模型 | account_user.rebate_rate decimal(5,4)(v20 加列;小数表示 0.1200=12%,0=无返点);返点额=**直线下级**当月结算金额×rate;**历史不重算**(换上级只影响未来) | 树+Path 基座已备;先落地单级分成,层级分成留扩展 |
|
||||
| **R5** | 阶梯载体 | 新表 **settle_ladder**(owner_type=account/upstream × owner_id × tier_from 唯一;tier_from=档位下限含,0=首档;出账按月成功总量落档覆写时间线价) | 独立表可审计可单测(「阶梯结算单测」为显式验收项);不塞 JSON |
|
||||
| **R6** | 单位口径 | 余额/预扣/明细 Fee/fee_total=**条**;BillingOrder.Count=条、Amount=元;结算单/利润/单价=**元**;条→元换算**只发生在出账引擎**(settle/price.go)一处 | 消除 balance(条)与 decimal(元)的隐性错位;单点换算单点审计 |
|
||||
|
||||
## 二、v20_settle_domain 迁移范围(已实现)
|
||||
|
||||
1. billing_consume_log 补 `unknown_count INT`(上家 success_unknown 口径依赖)+ `updated_at DATETIME`(UPSERT 重跑痕迹);
|
||||
2. account_user 补 `rebate_rate DECIMAL(5,4)`;
|
||||
3. DROP stats_user_daily(空库路径 v0 已不再建它,DROP IF EXISTS 双方言幂等);
|
||||
4. 新表 settle_ladder;
|
||||
5. casbin 补策略:ops settle:write / customer settle:read(逐条 NOT EXISTS 守卫;单块重放路径 HasTable 守卫)。
|
||||
|
||||
加列走显式 SQL+HasColumn 守卫、空库走 HasTable 守卫 AutoMigrate 整表(v16/v17 教训:glebarez 下 entity 加字段触发表 diff 重建抹索引)。
|
||||
**不需要**新聚合索引:通道维度日汇总复用 v16 `idx_detail_channel_created(channel_id, created_at)`。
|
||||
**不改** init_schema.sql(Day11 基线参考、权威=migrate 链,v16/v17 演进均未回写,维持惯例)。
|
||||
`stats_channel_daily` 零 schema 变更(unknown_count/cost_total 原有;grain=通道×天,不加 business——通道价格体系本身不分业务,视频走独立通道)。
|
||||
|
||||
## 三、状态机与语义定稿
|
||||
|
||||
- **充值订单**:pay_status 0待确认→1已到账/2失败;confirm 事务=UPDATE ... WHERE pay_status=0(行数=0 即 409)+balance+=count 原子自增+流水(ref_id=order_no);驳回不涉余额。
|
||||
- **结算单(下家/上家同构)**:status 0草稿→1已确认(人工锁账,拒静默重算)→2已结账(写 settle_record,终态);generate 幂等=uk(account|upstream, period)+OnConflict 更新重算,status=2 拒。
|
||||
- **上家计费口径**:按通道 `billing_mode`——success(仅成功)/success_unknown(成功+未知)/all(全部提交);UNKNOWN 72h 窗语义(部分段事实送达)与 success_unknown 口径天然对齐。
|
||||
- **日汇总 job**:T+1 01:05 核算昨日+启动回补 7 天,幂等 UPSERT(明细热窗 5 天→月结必须走日汇总,job 必须在明细出窗前落账——整域地基,D2 最先做)。
|
||||
|
||||
## 四、任务映射(D2-D5)
|
||||
|
||||
| 任务 | 落点 |
|
||||
|---|---|
|
||||
| D2 消耗日汇总引擎 | settle/consume.go+job.go(照 StartStatsRefresher 幂等模式)+/billing/consume+/ops/settle/aggregate+Settle 配置段+job 指标 |
|
||||
| D3 充值审核流 | settle/recharge.go+/billing/orders 族(R3 事务语义) |
|
||||
| D4 出账引擎+阶梯 | settle/price.go(PriceAt+阶梯落档,R1/R6 唯一换算点)+bill.go+/settle 族(生成/确认/结账/导出) |
|
||||
| D5 利润/返点/对账 | profit.go(树聚合,R4)+reconcile.go+cmd/reconcile settle-check(三方 diff=0=S2 出口) |
|
||||
|
||||
## 五、遗留与显式不承诺
|
||||
|
||||
- est_balance(通道估算余额 2h 刷新,需求 §5.3)语义依赖「校正余额」录入通道,本期字段保留不实现,验收单如实标注;
|
||||
- 层级返点(多级分成)、月结自动生成调度(手动 generate 先行)留后续;
|
||||
- 阶梯与时间线价并存时:**有阶梯档则整月单价按落档价覆写**(不做分档混合计价)——单测覆盖边界(恰好落档/跨档/无阶梯回退)。
|
||||
@@ -18,6 +18,7 @@ type AccountUser struct {
|
||||
IPBind string `gorm:"size:256" json:"ip_bind"`
|
||||
Balance int64 `json:"balance"`
|
||||
CreditBalance int64 `json:"credit_balance"`
|
||||
RebateRate float64 `gorm:"type:decimal(5,4);default:0" json:"rebate_rate"` // v20:代理返点率(小数,0.1200=12%;0=无返点;上级对直线下级结算额的分成)
|
||||
SvcTeam string `gorm:"size:64" json:"svc_team"`
|
||||
ExpiredAt *time.Time `json:"expired_at"`
|
||||
LastLoginAt *time.Time `json:"last_login_at"`
|
||||
|
||||
@@ -46,8 +46,8 @@ func All() []any {
|
||||
// 计费与结算(5)
|
||||
&BillingOrder{}, &BillingConsumeLog{}, &SettleCustomer{}, &SettleUpstream{},
|
||||
&SettleRecord{},
|
||||
// 统计与运维(8)
|
||||
&StatsUserDaily{}, &StatsChannelDaily{}, &SystemConfig{}, &SystemAlertRule{},
|
||||
// 统计与运维(7)
|
||||
&StatsChannelDaily{}, &SystemConfig{}, &SystemAlertRule{},
|
||||
&SystemLoginLog{}, &SystemOperateLog{}, &SystemErrorCode{}, &FeErrorLog{},
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,7 +19,9 @@ type BillingOrder struct {
|
||||
|
||||
func (BillingOrder) TableName() string { return "billing_order" }
|
||||
|
||||
// BillingConsumeLog 消耗日志(按账号/业务/天)。
|
||||
// BillingConsumeLog 消耗日志(按账号/业务/天)——S2 起为结算域消耗事实源
|
||||
// (R2 裁决:stats_user_daily 同粒度双空壳废弃,单一事实源归本表);
|
||||
// 日汇总 job T+1 凌晨幂等 UPSERT(明细热窗仅 5 天,月结必须走本表)。
|
||||
type BillingConsumeLog struct {
|
||||
ID int64 `gorm:"primaryKey;autoIncrement" json:"id"`
|
||||
AccountID int64 `gorm:"uniqueIndex:uk_account_date,priority:1" json:"account_id"`
|
||||
@@ -28,21 +30,24 @@ type BillingConsumeLog struct {
|
||||
SubmitCount int `json:"submit_count"`
|
||||
SuccessCount int `json:"success_count"`
|
||||
FailCount int `json:"fail_count"`
|
||||
FeeTotal float64 `gorm:"type:decimal(12,4)" json:"fee_total"`
|
||||
UnknownCount int `json:"unknown_count"` // v20:未知(72h 窗后仍 UNKNOWN)——上家 success_unknown 口径依赖
|
||||
FeeTotal float64 `gorm:"type:decimal(12,4)" json:"fee_total"` // 单位=条(=Σ明细 fee,片数口径 Day70)
|
||||
CreatedAt time.Time `gorm:"autoCreateTime" json:"created_at"`
|
||||
UpdatedAt time.Time `gorm:"autoUpdateTime" json:"updated_at"` // v20:UPSERT 重跑痕迹
|
||||
}
|
||||
|
||||
func (BillingConsumeLog) TableName() string { return "billing_consume_log" }
|
||||
|
||||
// SettleCustomer 下家(客户)月度结算单。
|
||||
// SettleCustomer 下家(客户)月度结算单——金额=Σ(日成功条数×生效单价),
|
||||
// 出账时刻按价格时间线推导(R1 裁决:明细 Fee 保持片数,不在受理侧金额化)。
|
||||
type SettleCustomer struct {
|
||||
ID int64 `gorm:"primaryKey;autoIncrement" json:"id"`
|
||||
SettleNo string `gorm:"size:32" json:"settle_no"`
|
||||
AccountID int64 `gorm:"uniqueIndex:uk_account_period,priority:1" json:"account_id"`
|
||||
Period string `gorm:"size:7;uniqueIndex:uk_account_period,priority:2;index:idx_period" json:"period"`
|
||||
SuccessCount int64 `json:"success_count"`
|
||||
Amount float64 `gorm:"type:decimal(12,2)" json:"amount"`
|
||||
Status int8 `gorm:"default:0" json:"status"`
|
||||
Amount float64 `gorm:"type:decimal(12,2)" json:"amount"` // 应收(元)
|
||||
Status int8 `gorm:"default:0" json:"status"` // 0草稿 1已确认 2已结账(已结拒重算)
|
||||
CreatedAt time.Time `gorm:"autoCreateTime" json:"created_at"`
|
||||
}
|
||||
|
||||
@@ -76,3 +81,17 @@ type SettleRecord struct {
|
||||
}
|
||||
|
||||
func (SettleRecord) TableName() string { return "settle_record" }
|
||||
|
||||
// SettleLadder 阶梯价档位(S2·R5:出账时按月成功总量落档,档内单价覆写
|
||||
// 时间线价;tier_from=档位下限(含),0=首档,上一档与下一档的 from 界定区间;
|
||||
// owner_type=account(下家应收)/upstream(上家成本)两类锚点各自配档)。
|
||||
type SettleLadder struct {
|
||||
ID int64 `gorm:"primaryKey;autoIncrement" json:"id"`
|
||||
OwnerType string `gorm:"size:8;uniqueIndex:uk_owner_tier,priority:1" json:"owner_type"` // account/upstream
|
||||
OwnerID int64 `gorm:"uniqueIndex:uk_owner_tier,priority:2" json:"owner_id"`
|
||||
TierFrom int64 `gorm:"uniqueIndex:uk_owner_tier,priority:3" json:"tier_from"` // 档位下限(含,条)
|
||||
Price float64 `gorm:"type:decimal(10,4)" json:"price"` // 该档单价(元/条)
|
||||
CreatedAt time.Time `gorm:"autoCreateTime" json:"created_at"`
|
||||
}
|
||||
|
||||
func (SettleLadder) TableName() string { return "settle_ladder" }
|
||||
|
||||
@@ -2,20 +2,9 @@ package entity
|
||||
|
||||
import "time"
|
||||
|
||||
// StatsUserDaily 用户日统计(偶数整点刷新)。
|
||||
type StatsUserDaily struct {
|
||||
ID int64 `gorm:"primaryKey;autoIncrement" json:"id"`
|
||||
AccountID int64 `gorm:"uniqueIndex:uk_account_date,priority:1" json:"account_id"`
|
||||
StatDate time.Time `gorm:"type:date;uniqueIndex:uk_account_date,priority:2;index:idx_date" json:"stat_date"`
|
||||
SubmitCount int `json:"submit_count"`
|
||||
SuccessCount int `json:"success_count"`
|
||||
FailCount int `json:"fail_count"`
|
||||
UnknownCount int `json:"unknown_count"`
|
||||
FeeTotal float64 `gorm:"type:decimal(12,4)" json:"fee_total"`
|
||||
UpdatedAt time.Time `gorm:"autoUpdateTime" json:"updated_at"`
|
||||
}
|
||||
|
||||
func (StatsUserDaily) TableName() string { return "stats_user_daily" }
|
||||
// (S2·R2 裁决)StatsUserDaily 用户日统计已废弃:与 billing_consume_log
|
||||
// 同粒度双空壳,消耗事实源统一归 billing_consume_log(账号×业务×天),
|
||||
// 表由迁移 v20 DROP;用户侧统计查询走 billing_consume_log API。
|
||||
|
||||
// StatsChannelDaily 通道日统计(含估算余额)。
|
||||
type StatsChannelDaily struct {
|
||||
|
||||
@@ -29,8 +29,8 @@ func TestMigrations_IdempotentAndVersioned(t *testing.T) {
|
||||
seen[mig.ID] = true
|
||||
last = mig
|
||||
}
|
||||
if last == nil || last.ID != "v19_longsms_pending" {
|
||||
t.Fatalf("终版迁移应为 v19_longsms_pending,实际 %v", last)
|
||||
if last == nil || last.ID != "v20_settle_domain" {
|
||||
t.Fatalf("终版迁移应为 v20_settle_domain,实际 %v", last)
|
||||
}
|
||||
|
||||
db, err := gorm.Open(sqlite.Open(":memory:"), &gorm.Config{})
|
||||
@@ -42,31 +42,28 @@ func TestMigrations_IdempotentAndVersioned(t *testing.T) {
|
||||
}
|
||||
opts := gormigrate.DefaultOptions
|
||||
opts.TableName = "schema_migrations"
|
||||
// 注册末七迁移(现 v13..v19;历史 v10/V11 含 MessageTask AutoMigrate,gleberez
|
||||
// sqlite 索引不查重,双块连跑撞 idx_account_time——同 v1+v6 已知方言缺口;v13/v14
|
||||
// 各建各表、v15 AutoMigrate 加列、v16/v17 空库守卫补建 detail 后加查询索引、
|
||||
// v18/v19 新表 AutoMigrate,单块两遍覆盖幂等)。
|
||||
// 注册末七迁移(现 v14..v20;历史 v10/V11 含 MessageTask AutoMigrate,gleberez
|
||||
// sqlite 索引不查重,双块连跑撞 idx_account_time——同 v1+v6 已知方言缺口;
|
||||
// v14 各建各表、v15 AutoMigrate 加列、v16/v17/v20 空库守卫补建表后加列/索引、
|
||||
// v18/v19 新表 AutoMigrate,v20 另含 DROP IF EXISTS 与 casbin HasTable 守卫,
|
||||
// 单块两遍覆盖幂等)。
|
||||
migs := Migrations()
|
||||
gm := gormigrate.New(db.Session(&gorm.Session{Logger: logger.Discard}), opts, migs[len(migs)-7:])
|
||||
if err := gm.Migrate(); err != nil {
|
||||
t.Fatalf("v13..v19 首遍失败: %v", err)
|
||||
t.Fatalf("v14..v20 首遍失败: %v", err)
|
||||
}
|
||||
if err := gm.Migrate(); err != nil {
|
||||
t.Fatalf("v13..v19 二遍不幂等: %v", err)
|
||||
t.Fatalf("v14..v20 二遍不幂等: %v", err)
|
||||
}
|
||||
v, err := CurrentMigrationVersion(db)
|
||||
if err != nil {
|
||||
t.Fatalf("查版本失败: %v", err)
|
||||
}
|
||||
if v == nil || *v != "v19_longsms_pending" {
|
||||
t.Fatalf("版本应为 v19_longsms_pending,实际 %v", v)
|
||||
}
|
||||
if !db.Migrator().HasTable(&entity.MessageReportSeg{}) {
|
||||
t.Fatal("v13 后应存在 message_report_seg 表")
|
||||
}
|
||||
if !db.Migrator().HasColumn(&entity.MessageReportSeg{}, "PkTotal") {
|
||||
t.Fatal("v13 后应存在 pk_total 列(段级配对键)")
|
||||
if v == nil || *v != "v20_settle_domain" {
|
||||
t.Fatalf("版本应为 v20_settle_domain,实际 %v", v)
|
||||
}
|
||||
// (v13 断言随窗口右移移除:message_report_seg/pk_total 由 v13 建,
|
||||
// 现窗口 v14..v20 不含 v13;全量链路覆盖仍由 dev MySQL 实库验证。)
|
||||
// Day 62:v15 后 account_config 应有账号级 CMPP 配额两列。
|
||||
if !db.Migrator().HasColumn(&entity.AccountConfig{}, "CmppMaxConns") ||
|
||||
!db.Migrator().HasColumn(&entity.AccountConfig{}, "CmppSpeed") {
|
||||
@@ -85,6 +82,21 @@ func TestMigrations_IdempotentAndVersioned(t *testing.T) {
|
||||
if !db.Migrator().HasIndex(&entity.MessageDetail{}, "idx_business_created") {
|
||||
t.Fatal("v17 后应存在 idx_business_created 索引")
|
||||
}
|
||||
// S2:v20 后 billing_consume_log 应有 unknown_count/updated_at 列,
|
||||
// account_user 应有 rebate_rate 列,settle_ladder 建表且 stats_user_daily 废弃。
|
||||
if !db.Migrator().HasColumn(&entity.BillingConsumeLog{}, "UnknownCount") ||
|
||||
!db.Migrator().HasColumn(&entity.BillingConsumeLog{}, "UpdatedAt") {
|
||||
t.Fatal("v20 后 billing_consume_log 应有 unknown_count/updated_at 列")
|
||||
}
|
||||
if !db.Migrator().HasColumn(&entity.AccountUser{}, "RebateRate") {
|
||||
t.Fatal("v20 后 account_user 应有 rebate_rate 列")
|
||||
}
|
||||
if !db.Migrator().HasTable(&entity.SettleLadder{}) {
|
||||
t.Fatal("v20 后应存在 settle_ladder 表")
|
||||
}
|
||||
if db.Migrator().HasTable("stats_user_daily") {
|
||||
t.Fatal("v20 后 stats_user_daily 应已 DROP(R2 单一事实源裁决)")
|
||||
}
|
||||
}
|
||||
|
||||
// newTestDB 内存 SQLite + 自动建表。
|
||||
|
||||
@@ -393,6 +393,80 @@ func Migrations() []*gormigrate.Migration {
|
||||
return nil // 表可手工 DROP,回滚为空操作
|
||||
},
|
||||
},
|
||||
{
|
||||
// S2(结算域 D 层)表基线,详见 docs/review/s2-settle-table-review.md:
|
||||
// ①billing_consume_log 补 unknown_count/updated_at——消耗事实源
|
||||
// (R2:stats_user_daily 废弃),幂等 UPSERT 重跑需更新痕迹;
|
||||
// ②account_user 补 rebate_rate——代理返点率(R4,小数表示);
|
||||
// ③DROP stats_user_daily——同粒度双空壳,单一事实源归 billing_
|
||||
// consume_log;空库路径 v0 已不再建它,DROP IF EXISTS 双方言幂等;
|
||||
// ④新表 settle_ladder——阶梯价档位(R5,出账时按月成功总量落档);
|
||||
// ⑤casbin 补结算域策略(ops settle:write / customer settle:read,
|
||||
// 逐条 NOT EXISTS 守卫;末段迁移单块重放路径无 casbin_rule 表,
|
||||
// HasTable 守卫跳过,全量链路种入)。
|
||||
// 加列走显式 SQL 不走 AutoMigrate——glebarez SQLite 下 entity 加
|
||||
// 字段触发表 diff 重建会抹既有索引(v16/v17 教训);空库守卫分支
|
||||
// AutoMigrate 整表无此风险(表本不存在)。
|
||||
ID: "v20_settle_domain",
|
||||
Migrate: func(tx *gorm.DB) error {
|
||||
if !tx.Migrator().HasTable(&entity.BillingConsumeLog{}) { // 空库守卫(同 v16/v17)
|
||||
if err := tx.AutoMigrate(&entity.BillingConsumeLog{}); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
if !tx.Migrator().HasColumn(&entity.BillingConsumeLog{}, "UnknownCount") {
|
||||
if err := tx.Exec("ALTER TABLE billing_consume_log ADD COLUMN unknown_count INT NOT NULL DEFAULT 0").Error; err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
if !tx.Migrator().HasColumn(&entity.BillingConsumeLog{}, "UpdatedAt") {
|
||||
if err := tx.Exec("ALTER TABLE billing_consume_log ADD COLUMN updated_at DATETIME NULL DEFAULT NULL").Error; err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
if !tx.Migrator().HasTable(&entity.AccountUser{}) { // 空库守卫
|
||||
if err := tx.AutoMigrate(&entity.AccountUser{}); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
if !tx.Migrator().HasColumn(&entity.AccountUser{}, "RebateRate") {
|
||||
if err := tx.Exec("ALTER TABLE account_user ADD COLUMN rebate_rate DECIMAL(5,4) NOT NULL DEFAULT 0").Error; err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
if err := tx.Exec("DROP TABLE IF EXISTS stats_user_daily").Error; err != nil {
|
||||
return err
|
||||
}
|
||||
if !tx.Migrator().HasTable(&entity.SettleLadder{}) { // 新表,AutoMigrate 安全(同 v18/v19)
|
||||
if err := tx.AutoMigrate(&entity.SettleLadder{}); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
if tx.Migrator().HasTable(&casbinRule{}) { // v5 才建 casbin_rule
|
||||
policies := []casbinRule{
|
||||
{Ptype: "p", V0: "ops", V1: "settle", V2: "write"},
|
||||
{Ptype: "p", V0: "customer", V1: "settle", V2: "read"}, // 客户查自己账单,scope 在 handler 侧过滤
|
||||
}
|
||||
for _, p := range policies {
|
||||
var n int64
|
||||
if err := tx.Model(&casbinRule{}).
|
||||
Where("ptype = ? AND v0 = ? AND v1 = ? AND v2 = ?", p.Ptype, p.V0, p.V1, p.V2).
|
||||
Count(&n).Error; err != nil {
|
||||
return err
|
||||
}
|
||||
if n == 0 {
|
||||
if err := tx.Create(&p).Error; err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return nil
|
||||
},
|
||||
Rollback: func(tx *gorm.DB) error {
|
||||
return nil // 列/表/策略可手工重建或清除,回滚为空操作(v16~v19 惯例)
|
||||
},
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,13 +1,12 @@
|
||||
# 当前工作上下文(最近更新:2026-11-12)
|
||||
# 当前工作上下文(最近更新:2026-11-14)
|
||||
|
||||
## 当前状态快照(2026-11-13 夜,**S1 泳道收官**)
|
||||
## 当前状态快照(2026-11-14 上午,**S2-D1 收官**)
|
||||
|
||||
- **仓库**:main 已推 Gitea(origin=192.168.5.27:24401/Tory/go-sms-V2);S1 全程 28 提交(2a6a66f→661eedd)+S3 前置 c205f017(views 31 页补齐+网关端口归位 :8080+FE 工具链 node20.19/pnpm12.18);每日 bundle+push 双轨。
|
||||
- **S1 出口全绿**:B 层 12 域+结构改造三件(send 拆包 facade/channel 拆 pool/router 空壳消除)+dayNN 清零+lint 0+**全仓 -race 38 包 RC=0**+集成七件+gateway 驻留冒烟;迁移链 v1~v19 落地。
|
||||
- **send 三子包**(0550f2a):submit(受理+事件/状态契约族)/consume/dispatch;facade.go 40 符号别名门面,调用方零改动;依赖 consume→{submit,dispatch}、dispatch→submit 单向。
|
||||
- **中间件**:9/9 healthy(MySQL 10G SSD 基线/kafka compose 化/rustfs);gateway :8081 驻留。
|
||||
- **在途**:24h 稳定性门槛 **维持原时间核验:11-13 17:55 起计 → 11-14 17:55 期满回填 s1-b-closeout.md**(S5 压测基线前置);期内 21:33 宿主主动有序重启(内核升级日二次重启)=已知事件不判失败,九中间件 restart policy 自愈全 healthy,gateway 重驻 :8080(md5 比对一致)。
|
||||
- **下一步=S2 结算域**(5 工作日,D 层新做):开工前置=研读《需求分析》结算章节+表设计评审先行(整域 0% 起点);随后 S3 前端(views 31 页+FE-6+node 工具链)。
|
||||
- **仓库**:main 已推 Gitea(origin=192.168.5.27:24401/Tory/go-sms-V2);S1 全程 28 提交+S3 前置;每日 bundle+push 双轨。
|
||||
- **S2 结算域已开工(D 层,5 工作日,出口=结算单测+对账差异 0)**:D1 ✅=六项表设计裁决定稿(`docs/review/s2-settle-table-review.md`)+迁移 **v20_settle_domain**(billing_consume_log 补列/stats_user_daily DROP/settle_ladder 建表/rebate_rate/casbin settle 策略;dev 库 v19→v20 实跑+五项 information_schema 核验过)+**openapi v1.3.0**(+20 结算端点);门禁全绿(vet/-race 38 包/lint 0/迁移单测/集成 AutoMigrate 39 表+Casbin)。验收单 `docs/acceptance/s2-d1.md`。
|
||||
- **六项裁决速查**:R1 出账时刻计价(明细 Fee=片数不动,send 域零改动;金额=Σ日成功条数×生效单价,时间线+阶梯在 D4 settle/price.go 单点推导)/R2 消耗事实源=billing_consume_log(账号×业务×天)+stats_channel_daily(通道×天)/R3 充值双通道/R4 rebate_rate 单级返点历史不重算/R5 settle_ladder(owner×tier_from)/R6 条/元换算只在出账引擎。
|
||||
- **下一步=S2-D2 消耗日汇总引擎**(整域地基:明细热窗 5 天→月结必须走日汇总):settle/consume.go+job.go(照 StartStatsRefresher 幂等模式,cronx T+1 01:05+回补 7 天)+/billing/consume+/ops/settle/aggregate+Settle 配置段+job 指标;随后 D3 充值审核流/D4 出账+阶梯/D5 利润返点+三方对账。
|
||||
- **在途**:24h 稳定性门槛 **11-14 17:55 期满核验**(dmesg 崩溃 0+容器重启 0+gateway 驻留)→ 回填 s1-b-closeout.md;不阻塞 S2。
|
||||
- 归档仓(只读):/data/poc-archive/repos/go-sms.git(poc-final=5e09a4cc)。
|
||||
- **本会话运维教训**:①`pkill/pgrep -f` 自匹配(铁律:`[x]` 括号技巧);②大镜像单窗>体积÷带宽;③du 无 sudo 静默失败误诊;④sed 换行/sed 误伤方法名(重构期优先编辑器工具);⑤Go 工具忽略 `_` 前缀文件;⑥集成测试需 `sg docker` 包裹(docker 组未重登);⑦**Makefile recipe 的 `exit 0` 只退出当前行 shell 不终止目标**(幂等短路须 if/else 递归 `$(MAKE)` 子目标);⑧**管道 `| tail -N` 截首行误导诊断**(gw-start"玄学 NOMATCH"两轮误诊实为 THEN 分支已生效,排查须看全量输出)。
|
||||
|
||||
|
||||
@@ -11,6 +11,8 @@
|
||||
| S1-B D1 中间件+基线 | compose SSD 参数生效/Kafka compose 化/迁移链 v1~v19 落地/集成六件绿/首份快照/24h 门槛起计 | ✅ 2026-11-13(minio 镜像遗留) |
|
||||
| S1-B B 层搬运 P1 | 12 域+双入口全落位(两阶段等价法);channel P2 拆 pool 完成;lint 27→0;全仓 -race 36 包绿 | ✅ 2026-11-13 |
|
||||
| S1-B 收尾项 | send P2 拆三子包(0550f2a,facade 门面)/dayNN 19 文件改名/storage 归一/文案校准/gofmt 清零 | ✅ 2026-11-13 夜(**S1 泳道收官**) |
|
||||
| S2-D1 表设计+v20+契约 | 六项裁决(R1 出账时刻计价/R2 事实源统一/R3 充值双通道/R4 返点/R5 阶梯表/R6 口径)+v20_settle_domain+openapi v1.3.0(+20 端点)+dev 库实跑 v20 | ✅ 2026-11-14(评审纪要 docs/review/s2-settle-table-review.md;验收单 s2-d1.md) |
|
||||
| S2-D2~D5 | D2 消耗日汇总引擎(整域地基)/D3 充值审核流/D4 出账+阶梯(显式验收:阶梯结算单测)/D5 利润返点+三方对账(diff=0=S2 出口) | ⬜ 排期中 |
|
||||
| 观察项 | 24h 稳定性门槛(维持原时间:11-13 17:55 起计;期内 21:33 宿主主动重启=已知事件不判失败)期满核验 11-14 17:55 → s1-b-closeout.md 回填 | ⏳ 在途 |
|
||||
| S2~S5 | 结算域/前端收尾/C1C2+冷热/基线与灰度 | ⬜ 见《Go-sms-重建计划.md》 |
|
||||
|
||||
|
||||
Reference in New Issue
Block a user