# risk_db 风控库

## 数据库定位

risk_db 保存 RTP 策略、玩家风控标签、库存池、开奖结果选择审计等数据。risk-rtp-service 根据这些数据从采集结果池中选择合适结果引用。

## 核心表

### rtp_profiles RTP 档位表

| 字段 | 类型 | 说明 |
| --- | --- | --- |
| profile_id | bigint | 档位 ID |
| profile_code | varchar(64) | 档位编码 |
| target_rtp | numeric(8, 4) | 目标 RTP |
| min_win_rate | numeric(8, 4) | 最低中奖率 |
| max_win_rate | numeric(8, 4) | 最高中奖率 |
| status | varchar(32) | 状态 |

### result_selection_audit 结果选择审计表

| 字段 | 类型 | 说明 |
| --- | --- | --- |
| audit_id | bigint | 审计 ID |
| bet_order_id | varchar(128) | 注单号 |
| game_code | varchar(64) | 游戏编码 |
| config_version | varchar(64) | 配置版本 |
| result_ref | varchar(256) | 采集结果引用 |
| selected_reason | text | 选择原因 |
| created_at | timestamptz | 创建时间 |

## 关键约束

- 每个注单必须能追溯结果来源。
- 结果选择必须写入配置版本和结果引用。
- 风控库不能作为账本或注单事实源。

## 示例 SQL

```sql
create unique index uk_result_selection_order on result_selection_audit(bet_order_id);
create index idx_result_selection_game_version on result_selection_audit(game_code, config_version);
```
