Files
go-sms-V2/internal/model/entity/billing.go
T
Tory bb60d60529
ci / test (push) Canceled after 0s
ci / web-test (push) Canceled after 0s
ci / build (push) Canceled after 0s
ci / deploy-dev (push) Canceled after 0s
S4-D1/D2: C1 回调推送引擎+C2 上行自动拉黑——验收项「死信可查/拒收即拉黑」✅: ①C1=callback_task 队列表(迁移 v21,状态机 pending→sent/dead+attempt/next_retry_at/last_code)+PushWorker(2s 扫/批 100/并发 8/2^n 秒指数退避封顶 10min/10 次耗尽死信/UPDATE CAS 防竞态)+双挂点(report 终态首锁[Consumer+PairService,与 CMPP Deliver 同点同语义]+uplink 消费尾)+URL 门控 account_config.report_url/uplink_url(60s TTL 缓存,未配置零任务)+GET /ops/callback(列表+状态计数面板)/POST /ops/callback/:id/resend(casbin ops callback:read/write v21 所种)+前端回调管理页(ops-callback 路由系统管理组+api/callback.ts+状态面板/筛选/载荷展开/死信重派;matrix+guard 33 菜单显式更)+metrics callback_push_total{type,result}/blacklist_total+openapi v1.4.0;②C2=AutoBlacklister 等值词表(trim+lower 防误伤,默认 R/TD/退订/拒收;SystemConfig uplink.blacklist.keywords 可配 60s 刷新)→policy_blacklist(source=2/账号级/uk 幂等)+Redis Set 即时生效,拉黑不影响上行推送(需求原文);③真机全链六步实证(dev 中间件):回执 DELIVRD→detail 终态→HTTP 回调 JSON 送达(200/sent)+上行 R→拉黑(source=2+Redis=1)+推送送达+坏 URL→attempt10→dead→resend ISC:000→修复重投 sent+status_counts 面板;一次性探针 cmd/cbprobe 用后即删+冒烟数据全清;④单测 +13(callback 6[入队门控/载荷/状态机全链/并发批]+uplink 5[词表/配置覆盖/幂等缓存/消费链]+report 2[首锁一次/nil]);⑤门禁=build/vet/-race 40 包/lint 0/eslint0/vue-tsc0/vitest 148/build 全绿;迁移测试 v15..v21 两遍幂等+dev 实跑 v21;gofmt 存量 8 文件顺手清零(S2 遗留);⑥口径诚实标注:载荷无签名挂账/拦截终态 HTTP 未挂(CMPP 侧已有)/PushWorker 单实例 at-least-once;验收单 s4-d1d2-callback.md+CHANGELOG+memory-bank 回填
2026-11-16 11:19:55 +08:00

98 lines
5.3 KiB
Go

package entity
import "time"
// BillingOrder 充值订单(付款审核确认后到账)。
type BillingOrder struct {
ID int64 `gorm:"primaryKey;autoIncrement" json:"id"`
OrderNo string `gorm:"size:32;uniqueIndex:uk_order_no" json:"order_no"`
AccountID int64 `gorm:"index:idx_account_time,priority:1" json:"account_id"`
Amount float64 `gorm:"type:decimal(12,2)" json:"amount"`
Count int64 `json:"count"`
PayType string `gorm:"size:16" json:"pay_type"`
PayStatus int8 `gorm:"index:idx_pay_status;default:0" json:"pay_status"` // 0待1到账2失败
Operator string `gorm:"size:64" json:"operator"`
PaidAt *time.Time `json:"paid_at"`
Remark string `gorm:"size:255" json:"remark"`
CreatedAt time.Time `gorm:"autoCreateTime;index:idx_account_time,priority:2" json:"created_at"`
}
func (BillingOrder) TableName() string { return "billing_order" }
// 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"`
Business string `gorm:"size:16;uniqueIndex:uk_account_date,priority:2;default:sms" json:"business"`
StatDate time.Time `gorm:"type:date;uniqueIndex:uk_account_date,priority:3" json:"stat_date"`
SubmitCount int `json:"submit_count"`
SuccessCount int `json:"success_count"`
FailCount int `json:"fail_count"`
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 下家(客户)月度结算单——金额=Σ(日成功条数×生效单价),
// 出账时刻按价格时间线推导(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"` // 0草稿 1已确认 2已结账(已结拒重算)
CreatedAt time.Time `gorm:"autoCreateTime" json:"created_at"`
}
func (SettleCustomer) TableName() string { return "settle_customer" }
// SettleUpstream 上家月度结算单。
type SettleUpstream struct {
ID int64 `gorm:"primaryKey;autoIncrement" json:"id"`
SettleNo string `gorm:"size:32" json:"settle_no"`
UpstreamID int64 `gorm:"uniqueIndex:uk_upstream_period,priority:1" json:"upstream_id"`
Period string `gorm:"size:7;uniqueIndex:uk_upstream_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"`
CreatedAt time.Time `gorm:"autoCreateTime" json:"created_at"`
}
func (SettleUpstream) TableName() string { return "settle_upstream" }
// SettleRecord 结账记录。
type SettleRecord struct {
ID int64 `gorm:"primaryKey;autoIncrement" json:"id"`
SettleNo string `gorm:"size:32;index:idx_settle_no" json:"settle_no"`
Direction int8 `gorm:"default:1" json:"direction"` // 1下家 2上家
Amount float64 `gorm:"type:decimal(12,2)" json:"amount"`
PayType string `gorm:"size:16" json:"pay_type"`
Operator string `gorm:"size:64" json:"operator"`
SettledAt time.Time `json:"settled_at"`
Remark string `gorm:"size:255" json:"remark"`
CreatedAt time.Time `gorm:"autoCreateTime" json:"created_at"`
}
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" }