Commit f7bbe180 by 潘诗林

财务文档提交

1 parent 6b65c61d
......@@ -776,7 +776,7 @@ goodsOrderDTO.setMainOrderProfit(getByOrderCode(orderCode));
thiz.saveProfitAndReconciliation(goodsOrderDTO);
```
> 详见 [saveProfitAndReconciliation-对账接口文档.md](./saveProfitAndReconciliation-对账接口文档.md)
> 详见 [saveProfitAndReconciliation-对账接口文档.md](saveProfitAndReconciliation-对账接口文档.md)
---
......
# 财务、对账、分账 ER 图
> 表名省略 `dj_car_life_` 前缀。关系符号: `||--o{` = 一对多, `||--||` = 一对一。
---
## 一、生效记录 → 三套规则主表
```mermaid
erDiagram
division_rule_effect_record {
int id PK
int merchant_id "商户号"
varchar merchant_name
tinyint rule_type "1财务 2分账 3对账"
tinyint scene_type "0会员权益 1精品升级"
varchar base_scene_code "业务场景编码"
int rule_id FK "指向规则主表"
int division_rule_id FK "分账规则ID"
datetime effect_start_date "生效开始"
datetime effect_end_date "生效结束(空=长期)"
char deleted_flag
}
merchant_settle_account_rule {
int id PK
int merchant_id
tinyint scene_type
varchar base_scene_code
char deleted_flag
}
merchant_reconciliation_rule {
int id PK
int merchant_id
tinyint scene_type
varchar base_scene_code
char deleted_flag
}
merchant_division_rule {
int id PK
int merchant_id
tinyint scene_type
varchar base_scene_code
char deleted_flag
}
merchant_settle_account_rule ||--o{ division_rule_effect_record : "rule_type=1 时 rule_id"
merchant_division_rule ||--o{ division_rule_effect_record : "division_rule_id"
merchant_reconciliation_rule ||--o{ division_rule_effect_record : "rule_type=3 时 rule_id"
```
---
## 二、财务规则树 + 对账规则树
```mermaid
erDiagram
merchant_settle_account_rule ||--o{ merchant_goods_type_group_settle_rule : "settle_rule_id"
merchant_goods_type_group_settle_rule {
int id PK
int settle_rule_id FK
tinyint group_type "1全部品类 2特殊品类"
tinyint goods_source "商品来源"
int goods_type_group_id FK "指向 goods_type_group"
char goods_cost_flag "5组成本标志+折算比例"
decimal goods_cost_convert_rate
char deleted_flag
}
merchant_goods_type_group_settle_rule ||--o{ merchant_expense_category_rule : "goods_type_group_rule_id"
merchant_goods_type_group_settle_rule ||--o{ goods_type_group_relation : "goods_type_group_rule_id"
merchant_reconciliation_rule ||--o{ merchant_goods_type_group_reconciliation_rule : "reconciliation_rule_id"
merchant_goods_type_group_reconciliation_rule {
int id PK
int reconciliation_rule_id FK
tinyint rule_type "3"
tinyint group_type
tinyint goods_source
char deleted_flag
}
merchant_goods_type_group_reconciliation_rule ||--o{ merchant_expense_category_rule : "goods_type_group_rule_id"
merchant_goods_type_group_reconciliation_rule ||--o{ goods_type_group_relation : "goods_type_group_rule_id"
merchant_expense_category_rule {
int id PK
tinyint rule_type "1财务 3对账"
int goods_type_group_rule_id FK "= 分组表主键 id"
int expense_category_id FK "指向 fee_category_name.id"
varchar expense_category_name
tinyint target_type "1-4S店 2-服务商 3-公共"
tinyint calculate_mode "1按类目 2按整单"
tinyint expense_category_calculate_type "公式类型"
decimal expense_category_value "公式参数"
tinyint node_type "普通/可拓展父/可拓展子"
int parent_id FK "自关联(可拓展父子)"
char deleted_flag
}
goods_type_group_relation {
int id PK
tinyint rule_type "1财务 3对账"
int goods_type_group_rule_id FK "财务=分组的goods_type_group_id / 对账=对账分组主键id"
tinyint category_type "1按品类 2按具体商品 3按套餐"
int goods_type "品类ID"
varchar goods_type_name
varchar merchant_goods_code "商品编码"
int upgrade_goods_id FK "上架商品ID"
varchar package_code FK "套餐编码"
char deleted_flag
}
merchant_expense_category_rule ||--o{ merchant_expense_category_rule : "parent_id 自关联"
goods_type_group {
int id PK "品类组ID"
tinyint use_type "用途类型(1财务分账规则设置)"
tinyint goods_source
char deleted_flag
}
merchant_goods_type_group_settle_rule }o--o| goods_type_group : "goods_type_group_id (ALL分组为null)"
goods_type_group ||--o{ goods_type_group_relation : "经由分组的 goods_type_group_id 关联"
upgrade_goods {
int id PK
varchar upgrade_goods_name
varchar commodity_code
}
merchant_package_goods_info {
int id PK
varchar package_code
varchar package_name
}
goods_type_group_relation }o--|| upgrade_goods : "upgrade_goods_id"
goods_type_group_relation }o--|| merchant_package_goods_info : "package_code"
fee_category_name {
int id PK "被 expense_category_id 引用"
int fee_category_id FK
varchar fee_category_name
int parent_id "自关联"
tinyint node_type
char deleted_flag
}
merchant_expense_category_rule }o--|| fee_category_name : "expense_category_id"
```
> **注意 1**: `merchant_expense_category_rule` 和 `goods_type_group_relation` 被财务和对账**共用**, 靠 `rule_type` 区分(1=财务, 3=对账)。
> **注意 2**: `goods_type_group_rule_id` 在两张共用表里指向不同, 写排查 SQL 时必须区分:
>
> | 表 | 指向 | 示例 |
> |----|------|------|
> | `merchant_expense_category_rule` | 所属分组的**主键 id** | 财务/对账都一样 |
> | `goods_type_group_relation`(rule_type=1 财务) | 分组的 **`goods_type_group_id`**(品类组ID) | `rel.goods_type_group_rule_id = settle分组.goods_type_group_id` |
> | `goods_type_group_relation`(rule_type=3 对账) | 对账分组的**主键 id** | `rel.goods_type_group_rule_id = reconciliation分组.id` |
>
> 原因: 财务分组有独立的 `goods_type_group`(品类组)概念, 对账分组表没有 `goods_type_group_id` 字段, 因此直接用自己的主键。
---
## 三、分账规则树
```mermaid
erDiagram
merchant_division_rule ||--o{ merchant_goods_type_group_division_rule : "division_rule_id"
merchant_division_rule {
int id PK
int merchant_id
tinyint scene_type
varchar base_scene_code
int reality_platform_merchant_id "实际平台商户"
char deleted_flag
}
merchant_goods_type_group_division_rule {
int id PK
int division_rule_id FK
tinyint group_type "1全部品类 2特殊品类"
int goods_type_group_id FK
tinyint test_flag
decimal goods_cost_convert_rate "5组成本折算比例(无标志位)"
decimal dj_cost_convert_rate
char deleted_flag
}
merchant_goods_type_group_division_rule ||--o{ merchant_distribution_rule : "goods_type_group_rule_id"
merchant_distribution_rule {
int id PK
int goods_type_group_rule_id FK "= 分账分组表主键 id"
tinyint rule_type "1费用归属 2实际分账"
int expense_category_id FK "指向 fee_category_name.id"
varchar expense_category_name
tinyint target_merchant_type "1平台方 2服务商 3-4S店 4子商户"
tinyint target_merchant_level "层级"
int merchant_id "收款商户号"
varchar merchant_name
char deleted_flag
}
fee_category_name ||--o{ merchant_distribution_rule : "expense_category_id"
```
---
## 四、订单 → 财务结果 → 对账结果
```mermaid
erDiagram
goods_order ||--o{ goods_sub_order : "order_code"
goods_order ||--o{ pay_order : "order_code"
goods_order ||--o| goods_order_customer : "order_code"
goods_order ||--o{ order_expense_category_calculated : "order_code"
goods_order ||--o{ goods_order_profit_allocation : "order_code"
goods_order {
int id PK
varchar order_code "业务主键"
int merchant_id
int seller_merchant_id "园区店"
tinyint scene_type
varchar base_scene_code
tinyint profit_allocation_status "分账状态"
datetime wait_profit_allocation_date "延迟分账到期"
int specify_account_rule_id FK "手工指定财务规则"
int specify_division_rule_id FK "手工指定分账规则"
int specify_reconciliation_rule_id FK "手工指定对账规则"
}
goods_sub_order {
int id PK
varchar order_code FK
varchar sub_order_code "子订单号"
varchar package_code "套餐编码"
varchar merchant_goods_code
int upgrade_goods_id
tinyint upgrade_goods_type "一级品类"
tinyint upgrade_secondary_goods_type "二级品类"
tinyint upgrade_third_level_goods_type "三级品类"
char finance_check_flag "需财务审核"
decimal upgrade_shop_price
int number
}
pay_order {
int id PK
varchar order_code FK
decimal actual_money
tinyint pay_type
varchar payment_channel_id
datetime success_date "用于匹配生效规则"
varchar trade_no
}
goods_order_customer {
int id PK
varchar order_code FK
tinyint sales_type "2=散客"
}
order_expense_category_calculated {
int id PK
varchar order_code FK
varchar sub_order_code
varchar package_code
tinyint rule_type "1财务 3对账"
int expense_category_id FK
int expense_category_rule_id FK "指向 merchant_expense_category_rule"
tinyint expense_category_calculate_type
decimal expense_category_value
decimal expense_category_result "计算结果金额"
tinyint calculate_mode
tinyint target_type
tinyint node_type
int parent_id "自关联"
char deleted_flag "D=整单取最大落选"
}
goods_order_profit_allocation {
int id PK
varchar order_code FK
varchar sub_order_code
varchar package_code
tinyint grain_size_type "1主订单 2子订单 3套餐"
char order_flag "Y=主订单粒度"
int settle_rule_id FK "指向财务规则"
int reconciliation_rule_id FK "指向对账规则"
int goods_type_group_rule_id FK "= 费用类目所属分组主键 id"
decimal service_charge
decimal gross_profit
decimal shop_profit_money "4S店分润"
decimal shop_traffic_money "流量费"
decimal yq_profit_money "园区店分润"
decimal franchisee_profit_money "服务商分润"
decimal gl_profit_money "平台收益"
decimal goods_cost
decimal install_cost "对账更新"
decimal marketing_cost "对账更新"
decimal reward_and_penalty_cost "对账更新"
}
merchant_expense_category_rule ||--o{ order_expense_category_calculated : "expense_category_rule_id"
merchant_settle_account_rule ||--o{ goods_order_profit_allocation : "settle_rule_id"
merchant_reconciliation_rule ||--o{ goods_order_profit_allocation : "reconciliation_rule_id"
fee_category_name ||--o{ order_expense_category_calculated : "expense_category_id"
```
---
## 五、分账结果
```mermaid
erDiagram
goods_order ||--o{ order_division : "order_code"
pay_order ||--o| order_division : "pay_order_id"
order_division ||--o{ merchant_distribution : "order_code + division_order_code"
goods_order ||--o{ merchant_expense_distribution : "order_code"
order_division {
int id PK
varchar order_code FK
int pay_order_id FK
varchar division_order_code "分账单号"
tinyint division_type "1线下对账 2线上分账"
decimal pay_money "支付金额"
decimal actual_income_money "实际收入(扣手续费)"
decimal division_money "分账金额"
decimal shop_division_money "4S店实分"
decimal gl_division_money "平台实分"
decimal djzhy_sub_merchant_division_money "子商户实分"
decimal shop_owning_division_money "4S店费用归属"
decimal gl_owning_division_money "平台费用归属"
varchar payment_channel_id
char auto_flag
tinyint settle_time_type
tinyint division_status "分账状态"
}
merchant_distribution {
int id PK
varchar order_code FK
varchar division_order_code FK
tinyint rule_type "1费用归属 2实际分账"
tinyint target_merchant_type "1平台方 2服务商 3-4S店 4子商户"
tinyint target_merchant_level
int merchant_id "应收商户"
varchar merchant_name
int reality_merchant_id "实际收款方"
varchar reality_merchant_name
decimal should_division_money "应付金额"
decimal division_money "实付金额"
tinyint division_type
}
merchant_expense_distribution {
int id PK
varchar order_code FK
varchar sub_order_code
tinyint rule_type "1费用归属 2实际分账"
int division_rule_id FK "指向 merchant_division_rule"
int distribution_rule_id FK "指向 merchant_distribution_rule"
int expense_category_id FK
varchar expense_category_name
decimal expense_category_result "费用金额"
decimal convert_rate "折算比例"
decimal convert_amount "折算后金额"
tinyint target_merchant_type
int merchant_id
varchar merchant_name
}
merchant_division_rule ||--o{ merchant_expense_distribution : "division_rule_id"
merchant_distribution_rule ||--o{ merchant_expense_distribution : "distribution_rule_id"
fee_category_name ||--o{ merchant_expense_distribution : "expense_category_id"
```
---
## 六、全链路关系总图
```mermaid
erDiagram
division_rule_effect_record }o--|| merchant_settle_account_rule : "财务规则"
division_rule_effect_record }o--|| merchant_reconciliation_rule : "对账规则"
division_rule_effect_record }o--|| merchant_division_rule : "分账规则"
merchant_settle_account_rule ||--o{ merchant_goods_type_group_settle_rule : "settle_rule_id"
merchant_reconciliation_rule ||--o{ merchant_goods_type_group_reconciliation_rule : "reconciliation_rule_id"
merchant_division_rule ||--o{ merchant_goods_type_group_division_rule : "division_rule_id"
merchant_goods_type_group_settle_rule ||--o{ merchant_expense_category_rule : "费用类目(rule_type=1)"
merchant_goods_type_group_reconciliation_rule ||--o{ merchant_expense_category_rule : "费用类目(rule_type=3)"
merchant_goods_type_group_division_rule ||--o{ merchant_distribution_rule : "归属规则"
goods_order ||--o{ goods_sub_order : "order_code"
goods_order ||--o{ pay_order : "order_code"
goods_order ||--o{ order_expense_category_calculated : "order_code"
goods_order ||--o{ goods_order_profit_allocation : "order_code"
goods_order ||--o{ order_division : "order_code"
order_division ||--o{ merchant_distribution : "division_order_code"
goods_order ||--o{ merchant_expense_distribution : "order_code"
merchant_expense_category_rule ||--o{ order_expense_category_calculated : "expense_category_rule_id"
merchant_distribution_rule ||--o{ merchant_expense_distribution : "distribution_rule_id"
```
---
## 附: 表清单
| # | 表名 | 中文名 | 层级 |
|---|------|-------|------|
| 1 | `dj_car_life_division_rule_effect_record` | 规则生效记录 | 配置 |
| 2 | `dj_car_life_merchant_settle_account_rule` | 财务规则主表 | 配置 |
| 3 | `dj_car_life_merchant_reconciliation_rule` | 对账规则主表 | 配置 |
| 4 | `dj_car_life_merchant_division_rule` | 分账规则主表 | 配置 |
| 5 | `dj_car_life_merchant_goods_type_group_settle_rule` | 财务品类分组 | 配置 |
| 6 | `dj_car_life_merchant_goods_type_group_reconciliation_rule` | 对账品类分组 | 配置 |
| 7 | `dj_car_life_merchant_goods_type_group_division_rule` | 分账品类分组 | 配置 |
| 8 | `dj_car_life_merchant_expense_category_rule` | 费用类目规则(财务/对账共用) | 配置 |
| 9 | `dj_car_life_goods_type_group_relation` | 品类关联(财务/对账共用) | 配置 |
| 10 | `dj_car_life_merchant_distribution_rule` | 分账归属规则 | 配置 |
| 11 | `dj_car_life_goods_type_group` | 品类组 | 配置 |
| 12 | `dj_car_life_fee_category` | 费用类目主表 | 基础 |
| 13 | `dj_car_life_fee_category_name` | 费用类目名称 | 基础 |
| 14 | `dj_car_life_upgrade_goods` | 上架商品 | 基础 |
| 15 | `dj_car_life_merchant_package_goods_info` | 商户套餐商品 | 基础 |
| 16 | `dj_car_life_goods_order` | 订单 | 订单 |
| 17 | `dj_car_life_goods_sub_order` | 子订单 | 订单 |
| 18 | `dj_car_life_pay_order` | 支付单 | 订单 |
| 19 | `dj_car_life_goods_order_customer` | 订单客户 | 订单 |
| 20 | `dj_car_life_order_expense_category_calculated` | 费用类目计算结果(财务/对账) | 计算 |
| 21 | `dj_car_life_goods_order_profit_allocation` | 财务结果(三级粒度) | 计算 |
| 22 | `dj_car_life_order_division` | 分账单 | 分账 |
| 23 | `dj_car_life_merchant_distribution` | 商户分账明细 | 分账 |
| 24 | `dj_car_life_merchant_expense_distribution` | 费用归属明细 | 分账 |
## 七、查询示例
```mysql
SELECT * from dj_car_life_division_rule_effect_record WHERE merchant_id = 44213218 and base_scene_code = '100101' and effect_end_date is null; -- 规则生效记录
SELECT * from dj_car_life_merchant_settle_account_rule WHERE id = 50830; -- 财务规则
SELECT * from dj_car_life_merchant_division_rule WHERE id = 51083; -- 分账规则
SELECT * from dj_car_life_merchant_reconciliation_rule where id = 32052; -- 对账规则
SELECT * from dj_car_life_goods_type_group where id =540352;
SELECT * from dj_car_life_merchant_goods_type_group_settle_rule WHERE settle_rule_id = 50830 and deleted_flag = 'N'; -- 财务品类配置
SELECT * from dj_car_life_merchant_goods_type_group_reconciliation_rule WHERE reconciliation_rule_id = 32052 and deleted_flag = 'N'; -- 对账品类配置
SELECT * from dj_car_life_merchant_goods_type_group_division_rule WHERE division_rule_id = 51083 and deleted_flag = 'N'; -- 分账品类配置
SELECT * from dj_car_life_merchant_expense_category_rule WHERE goods_type_group_rule_id = 576404 and deleted_flag = 'N'; -- 费用计算规则
SELECT * from dj_car_life_goods_type_group_relation WHERE goods_type_group_rule_id = 540348 and deleted_flag = 'N'; -- 品类配置规则
SELECT * from dj_car_life_goods_type_group_relation WHERE goods_type_group_rule_id = 162745 and deleted_flag = 'N' and rule_type = 3; -- 品类配置规则,对账
SELECT * from dj_car_life_merchant_distribution_rule where goods_type_group_rule_id = 578384;-- 费用归属
SELECT * from dj_car_life_order_expense_category_calculated where order_code = '260910123525831'; -- 订单费用计算明细
SELECT * from dj_car_life_goods_order_profit_allocation WHERE order_code = '260910123525831';-- 订单财务结果(三级粒度)
SELECT * from dj_car_life_order_division WHERE order_code = '260910123525831'; -- 商品订单分账信息
SELECT * from dj_car_life_merchant_distribution WHERE order_code = '260910123525831'; -- 订单分账明细
SELECT * from dj_car_life_merchant_expense_distribution WHERE order_code = '260910123525831'; -- 订单费用分账归属明细
select * from dj_car_life_abnormal_order; -- 分账异常订单
select * from dj_platform_payment.dj_payment_merchant_bank_info; -- 分帐方账户信息
```
## 页面配置对应表
#### 1.财务/分账
![image-20260910180058447](photo/image-20260910180058447.png)
![image-20260910180941660](photo\image-20260910180941660.png)
![image-20260910180952073](photo\image-20260910180952073.png)
![image-20260910181025137](photo\image-20260910181025137.png)
![image-20260910181403077](photo\image-20260910181403077.png)
![image-20260910181440590](photo\image-20260910181440590.png)
#### 对账
![image-20260910181604546](photo\image-20260910181604546.png)
#### 对账方账号
![image-20260911154151933](photo\image-20260911154151933.png)
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!