Files

105 lines
4.3 KiB
Markdown
Raw Permalink Normal View History

# 平台后台数据库表结构 (PocketBase)
本方案采用纯业务 ID 关联模式。PocketBase 底层的 `id` 字段由系统自动维护,业务逻辑中完全使用自定义的 `_id` 字段进行读写和关联。
---
### 1. tbl_system_dict (系统词典)
**类型:** Base Collection
**读写权限:** 所有人可读;仅 `ManagePlatform`/管理员可写
| 字段名 | 类型 | 备注 |
| :--- | :--- | :--- |
| system_dict_id | text | 自定义词id |
| dict_name | text | 词典名称 |
| dict_word_enum | text | 词典枚举 |
| dict_word_description | text | 词典描述 |
| dict_word_is_enabled | bool | 是否有效 |
| dict_word_sort_order | number | 显示顺序 |
| dict_word_parent_id | text | 实现父级字段 (存储其他 dict 的 system_dict_id) |
| dict_word_remark | text | 备注 |
**索引规划 (Indexes):**
* `CREATE UNIQUE INDEX` 针对 `system_dict_id` (确保业务主键唯一)
* `CREATE UNIQUE INDEX` 针对 `dict_name` (确保词典名称全局唯一,并支持按名称唯一索引查询)
* `CREATE INDEX` 针对 `dict_word_parent_id` (加速父子级联查询)
---
### 2. tbl_company (公司)
**类型:** Base Collection
| 字段名 | 类型 | 备注 |
| :--- | :--- | :--- |
| company_id | text | 公司业务id由数据库自动生成默认形如 `WX-COMPANY-时间串` |
| company_name | text | 公司名称 |
| company_type | text | 公司类型 |
| company_entity | text | 公司法人 |
| company_usci | text | 统一社会信用代码 |
| company_nationality | text | 国家 |
| company_nationality_code | text | 国家编码 |
| company_province | text | 省份 |
| company_province_code | text | 省份编码 |
| company_city | text | 城市 |
| company_city_code | text | 城市编码 |
| company_district | text | 区/县 |
| company_district_code | text | 区/县编码 |
| company_postalcode | text | 邮编 |
| company_add | text | 地址 |
| company_status | text | 公司状态 |
| company_level | text | 公司等级 |
| company_owner_openid | text | 公司所有者 openid |
| company_remark | text | 备注 |
**索引规划 (Indexes):**
* `CREATE UNIQUE INDEX` 针对 `company_id` (确保业务主键唯一)
* `CREATE INDEX` 针对 `company_usci` (加速信用代码检索)
* `CREATE UNIQUE INDEX` 针对 `company_owner_openid` (限制同一公司所有者仅能绑定一个公司)
---
### 3. tbl_user_groups (用户组)
**类型:** Base Collection
| 字段名 | 类型 | 备注 |
| :--- | :--- | :--- |
| usergroups_id | text | 自定义用户组id |
| usergroups_name | text | 用户组名 |
| usergroups_level | number | 权限等级 |
| usergroups_remark | text | 备注 |
**索引规划 (Indexes):**
* `CREATE UNIQUE INDEX` 针对 `usergroups_id` (确保业务主键唯一)
---
### 4. tbl_users (用户)
**类型:** Base Collection (采用纯业务记录,不使用系统 Auth以便完美适配图示字段)
| 字段名 | 类型 | 备注 |
| :--- | :--- | :--- |
| users_id | text | 自定义用户id |
| users_name | text | 用户名 |
| users_idtype | text | 证件类别 |
| users_id_number | text | 证件号 |
| users_phone | text | 用户电话号码 |
| users_wx_openid | text | 微信号 |
| users_level | text | 用户等级枚举值(新用户默认空) |
| users_type | text | 用户类型 |
| users_tag | text | 用户标签 |
| users_status | text | 用户状态 |
| company_id | text | 公司id (存储 tbl_company.company_id) |
| users_parent_id | text | 用户父级id (存储 tbl_users.users_id) |
| users_promo_code | text | 用户推广码 |
| users_id_pic_a | text | 用户证件照片(正),保存 tbl_attachments.attachments_id |
| users_id_pic_b | text | 用户证件照片(反),保存 tbl_attachments.attachments_id |
| users_title_picture | text | 用户资质照片,保存 tbl_attachments.attachments_id |
| users_picture | text | 用户头像,保存 tbl_attachments.attachments_id |
| usergroups_id | text | 用户组id (存储 tbl_user_groups.usergroups_id) |
**索引规划 (Indexes):**
* `CREATE UNIQUE INDEX` 针对 `users_id` (确保业务主键唯一)
* `CREATE UNIQUE INDEX` 针对 `users_phone` (确保手机号唯一,加速登录查询)
* `CREATE UNIQUE INDEX` 针对 `users_wx_openid` (确保微信开放ID唯一)
* `CREATE INDEX` 针对 `company_id`, `usergroups_id`, `users_parent_id` (加速这三个高频业务外键的匹配查询)