58 lines
3.4 KiB
Markdown
58 lines
3.4 KiB
Markdown
# 经理中心团队工资统计
|
||
|
||
经理中心首页 4 张卡片(本月团队工资、上月团队工资、活跃主播数、环比增长)的数据链路。
|
||
|
||
## 口径
|
||
|
||
- 团队范围:经理 → BD Leader(`bd_leader_profiles.created_by_user_id`)→ BD(`bd_profiles.parent_leader_user_id`)→ Agency(`agencies.parent_bd_user_id`),Agency 可直接挂 Leader 或挂 Leader 下属 BD;全链路只统计 active 状态。
|
||
- 主播归属:按 wallet 周期账户 `host_period_diamond_accounts.agency_owner_user_id`(送礼入账时的收款人快照)圈定,与工资结算同一口径。
|
||
- 预收入(estimated):进行中周期 = max(已结算累计, 当前档位累计工资 + 剩余钻石按月底费率折美元),即“立刻月结能拿多少”;已 month_end 关闭的周期直接取已结算累计(含剩余折算),不用当前政策重估,避免政策上调后显示从未发放的金额。政策取区域当前生效政策(不区分结算模式/触发方式),与 H5 平台政策展示一致。
|
||
- 周期:UTC 月(`cycle_key = yyyy-MM`),本月 + 上月两个周期。
|
||
- 活跃主播:该周期累计钻石 > 0 的主播数。
|
||
- 环比:`(本月预收入 - 上月预收入) / 上月预收入`,上月为 0 时有收入记 +100%,无收入记 0%。
|
||
- 时效:gateway 内存缓存 2 分钟(按 app_code + 经理 user_id),产品接受分钟级延迟。
|
||
|
||
## HTTP 接口
|
||
|
||
`GET /api/v1/manager-center/overview`(JWT,需 `manager_center` 能力)
|
||
|
||
响应 `data` 在原有身份/权限字段基础上新增 `dashboard`;统计链路故障时省略该字段,H5 显示占位符:
|
||
|
||
```json
|
||
{
|
||
"dashboard": {
|
||
"month_label": "Jul 2026",
|
||
"cycle_key": "2026-07",
|
||
"last_cycle_key": "2026-06",
|
||
"this_month_salary": 12152,
|
||
"this_month_salary_usd_minor": 1215200,
|
||
"last_month_salary": 9269,
|
||
"last_month_salary_usd_minor": 926900,
|
||
"active_hosts": 128,
|
||
"active_hosts_last_month": 96,
|
||
"growth": "+31%",
|
||
"team_bd_leaders": 2,
|
||
"team_bds": 5,
|
||
"team_agencies": 3,
|
||
"team_stats_truncated": false,
|
||
"updated_at_ms": 1783500000000
|
||
}
|
||
}
|
||
```
|
||
|
||
金额字段 `*_salary` 是美元数值(分转元),`*_usd_minor` 是美分整数;`growth` 直接下发带符号百分比字符串。`team_stats_truncated=true` 表示团队 Agency 超过单次拉取上限(5000),统计口径不完整。
|
||
|
||
## 内部 RPC
|
||
|
||
- user-service `UserHostService.ListManagerTeamAgencies(manager_user_id, page_size)` → 团队树内全部有效 Agency + BD Leader/BD 数量 + truncated 标记;经理身份停用返回 PermissionDenied。
|
||
- wallet-service `WalletService.GetTeamHostSalaryStats(agency_owner_user_ids[], cycle_keys[], now_ms)` → 每个周期的 estimated/settled 主播工资美分、活跃主播数、总钻石。只读聚合,不加锁不推进结算进度。
|
||
|
||
## 索引
|
||
|
||
- `bd_leader_profiles`:新增 `idx_bd_leader_profiles_created_by (app_code, created_by_user_id, status)`(migration 007 + initdb)。
|
||
- `host_period_diamond_accounts`:新增 `idx_host_period_diamond_cycle_owner (app_code, cycle_key, agency_owner_user_id, total_diamonds)`(initdb 幂等补建)。
|
||
|
||
## 对应 H5
|
||
|
||
`hyapp-h5/gonghui/manager-center`:`renderDashboard` 读取 `overview.dashboard.*`;拿到 overview 但缺 `dashboard` 时 4 张卡片显示 `--` 且月份标签按 UTC 当月计算,只有本地预览(无 API 注入)才显示设计稿假数据。
|