费率管理
费率管理主要用于维护语言服务商的费率,对外提供费率查询接口。
服务项
服务项代表语言服务商可以提供的服务,它包含两个维度,一个是服务项类型,一个是该服务项可以覆盖的语言对,是否可以覆盖该语言对由是否配置了这个费率决定。
服务项类型
目前系统支持的服务项类型有:
- 翻译(Translation)
- 机器翻译+校对 (MTPE) (本期不做)
- 加急服务 (Expedited Service)(本期不做)
- 管理费(Management Fee)
服务项可以设置为(Required Service),表示这是一个必须的附加服务,如果设置为Required Service,则该服务项表示在报价服务请求工作空间的服务项时这个一定会附加这个服务项。 订单请求可选供应商(Workspace时),只考虑订单提供的服务项是否可以覆盖工作空间的服务项。 计价时,如果返回的服务项没有对应语言对的费率,则使用0计算。
场景模拟
当前系统创建订单时,首先默认了一个服务项(Translation),后续会逐渐开放服务项的选择,此时报价服务会使用Translation服务项和订单中的语言对去调用TMS中获取符合条件的供应商,此时TMS服务可以按哪些供应商(Workspace)配置了对应服务项对应语言对的费率,确定可用的供应商列表,然后如果一个供应商设置了管理费为 Required Service,那当报价服务获取费率时,应当在返回Translation相关费率的基础上,加上Required Service的费率,此时有可能会有一种情况,因为我们的服务项都是和语言对关联的,但是Required Service并没有在选择可选时作为筛选条件,所以可能出现Required Service的一些目标语的费率找不到的情况,此时按0计算。 所以费率的计算方式为:
- 先计算各个目标语的Translation费率
- 进行折扣计算
- 按照Required Service的逻辑再服务费用,比如管理费的计算Unit是总价百分比,那么就每一个语言对都计算完成后,再乘以一个百分数,这部分就是管理费。
- 然后Translation的详细按表格展示,其余服务项产生的费用按服务项---价格的格式展示。
- 展示 Total 总价
计价单位
- 字数(Word)
- 小时(Hour)
- 固定价格(Fixed)
- 总价百分比(Factors)
本期仅支持字数和总价百分比,字数服务项计算价格时,价格=字数单价折扣(或者区间价),总价百分比服务项计算价格时,价格=总价*百分比
计价单位对应的数据库数值和前端输入需求
- 字数:精确两位浮点数,前端 1.23
- 小时:精确两位浮点数,前端 1.23
- 固定价格:精确两位浮点数,前端 1.23
- 总价百分比:精确两位浮点数,前端 12%
数据库表设计
1. 服务项目表 (service_items)
用于管理语言服务商支持的服务项。
CREATE TABLE tms_services (
service_id VARCHAR(255) PRIMARY KEY,
service_name VARCHAR(255) NOT NULL,
status VARCHAR(255) NOT NULL,
description TEXT,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);
CREATE TABLE service_items (
service_item_id UUID PRIMARY KEY,
service_id VARCHAR(255) NOT NULL,
description TEXT,
workspace_id UUID NOT NULL, -- 与Workspace关联
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
CONSTRAINT fk_workspace FOREIGN KEY (workspace_id) REFERENCES workspaces(workspace_id)
);2. 价格单位表 (pricing_units)
用于维护计算价格的单位。
CREATE TABLE pricing_units (
unit_id UUID PRIMARY KEY,
name VARCHAR(255) NOT NULL,
description TEXT,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);3. 区间折扣表 (discounts)
用于维护TM匹配度对应的折扣率。
CREATE TABLE discounts (
discount_id UUID PRIMARY KEY,
match_percentage INT NOT NULL,
discount_rate DECIMAL(5, 2) NOT NULL, -- 例如:0.10 表示10%的折扣
workspace_id UUID NOT NULL, -- 与Workspace关联
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
CONSTRAINT fk_workspace FOREIGN KEY (workspace_id) REFERENCES workspaces(workspace_id)
);4. 费率表 (rates)
用于记录服务项的费率信息。
CREATE TABLE rates (
rate_id UUID PRIMARY KEY,
service_item_id UUID NOT NULL,
source_language_id UUID NOT NULL,
target_language_id UUID NOT NULL,
pricing_unit_id UUID NOT NULL,
unit_price DECIMAL(10, 2) NOT NULL,
workspace_id UUID NOT NULL,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
CONSTRAINT fk_service_item FOREIGN KEY (service_item_id) REFERENCES service_items(service_item_id),
CONSTRAINT fk_source_language FOREIGN KEY (source_language_id) REFERENCES languages(language_id),
CONSTRAINT fk_target_language FOREIGN KEY (target_language_id) REFERENCES languages(language_id),
CONSTRAINT fk_pricing_unit FOREIGN KEY (pricing_unit_id) REFERENCES pricing_units(unit_id),
CONSTRAINT fk_workspace FOREIGN KEY (workspace_id) REFERENCES workspaces(workspace_id)
);4. 定制费率表 (custom_rates)
用于直接覆盖单一区间的价格。
CREATE TABLE custom_rates (
custom_rate_id UUID PRIMARY KEY,
service_item_id UUID NOT NULL,
source_language_id UUID NOT NULL,
target_language_id UUID NOT NULL,
match_percentage_range INT NOT NULL, -- 匹配区间
pricing_unit_id UUID NOT NULL,
unit_price DECIMAL(10, 2) NOT NULL,
status VARCHAR(255) NOT NULL, -- 状态 overwrite/not overwrite
workspace_id UUID NOT NULL,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
CONSTRAINT fk_service_item FOREIGN KEY (service_item_id) REFERENCES service_items(service_item_id),
CONSTRAINT fk_source_language FOREIGN KEY (source_language_id) REFERENCES languages(language_id),
CONSTRAINT fk_target_language FOREIGN KEY (target_language_id) REFERENCES languages(language_id),
CONSTRAINT fk_pricing_unit FOREIGN KEY (pricing_unit_id) REFERENCES pricing_units(unit_id),
CONSTRAINT fk_workspace FOREIGN KEY (workspace_id) REFERENCES workspaces(workspace_id)
);API 接口设计
1. 服务项目管理
1.1 获取服务项目列表
- 方法:GET
- URL:
/api/v1/workspaces/{workspace_id}/service-items - 响应示例:json
{ "code": 200, "message": "Service items retrieved successfully", "data": [ { "service_item_id": "UUID", "name": "Translation", "description": "Translation service" } ] }
1.2 创建服务项目
- 方法:POST
- URL:
/api/v1/workspaces/{workspace_id}/service-items - 请求体:json
{ "name": "Translation", "description": "Translation service" }
1.3 更新服务项目
- 方法:PUT
- URL:
/api/v1/workspaces/{workspace_id}/service-items/{service_item_id} - 请求体:json
{ "name": "Translation", "description": "Translation service" }
1.4 删除服务项目
- 方法:DELETE
- URL:
/api/v1/workspaces/{workspace_id}/service-items/{service_item_id}
2. 价格单位管理
2.1 获取价格单位列表
- 方法:GET
- URL:
/api/v1/workspaces/{workspace_id}/pricing-units - 响应示例:json
{ "code": 200, "message": "Pricing units retrieved successfully", "data": [ { "unit_id": "UUID", "name": "Per Word", "description": "Pricing per word" } ] }
2.2 创建价格单位
- 方法:POST
- URL:
/api/v1/workspaces/{workspace_id}/pricing-units - 请求体:json
{ "name": "Per Word", "description": "Pricing per word" }
2.3 更新价格单位
- 方法:PUT
- URL:
/api/v1/workspaces/{workspace_id}/pricing-units/{unit_id} - 请求体:json
{ "name": "Per Word", "description": "Pricing per word" }
2.4 删除价格单位
- 方法:DELETE
- URL:
/api/v1/workspaces/{workspace_id}/pricing-units/{unit_id}
3. 区间折扣管理
3.1 获取区间折扣列表
- 方法:GET
- URL:
/api/v1/workspaces/{workspace_id}/discounts - 响应示例:json
{ "code": 200, "message": "Discounts retrieved successfully", "data": [ { "discount_id": "UUID", "match_percentage": 100, "discount_rate": 0.10 } ] }
3.2 创建区间折扣
- 方法:POST
- URL:
/api/v1/workspaces/{workspace_id}/discounts - 请求体:json
{ "match_percentage": 100, "discount_rate": 0.10 }
3.3 更新区间折扣
- 方法:PUT
- URL:
/api/v1/workspaces/{workspace_id}/discounts/{discount_id} - 请求体:json
{ "match_percentage": 100, "discount_rate": 0.10 }
3.4 删除区间折扣
- 方法:DELETE
- URL:
/api/v1/workspaces/{workspace_id}/discounts/{discount_id}
4. 费率管理
4.1 获取费率列表
- 方法:GET
- URL:
/api/v1/workspaces/{workspace_id}/rates - 响应示例:json
{ "code": 200, "message": "Rates retrieved successfully", "data": [ { "rate_id": "UUID", "service_item_id": "UUID", "source_language_id": "UUID", "target_language_id": "UUID", "pricing_unit_id": "UUID", "unit_price": 0.15, "workspace_id": "UUID" } ] }
4.2 创建费率
- 方法:POST
- URL:
/api/v1/workspaces/{workspace_id}/rates - 请求体:json
{ "service_item_id": "UUID", "source_language_id": "UUID", "target_language_id": "UUID", "pricing_unit_id": "UUID", "unit_price": 0.15 }
4.3 更新费率
- 方法:PUT
- URL:
/api/v1/workspaces/{workspace_id}/rates/{rate_id} - 请求体:json
{ "service_item_id": "UUID", "source_language_id": "UUID", "target_language_id": "UUID", "pricing_unit_id": "UUID", "unit_price": 0.15 }
4.4 删除费率
- 方法:DELETE
- URL:
/api/v1/workspaces/{workspace_id}/rates/{rate_id}
5. 价格表查询
- 方法:GET
- URL:
/api/v1/workspaces/{workspace_id}/price-table - 查询参数:
- source_language_id: UUID (可选)
- target_language_id: UUID (可选)
- service_item_id: UUID (可选)
- currency_code: string (可选,默认使用workspace设置的默认币种)
- 响应示例:json
{ "code": 200, "message": "Price table retrieved successfully", "data": { "price_table": [ { "source_language": { "id": "UUID", "name": "英语", "code": "en" }, "target_language": { "id": "UUID", "name": "中文", "code": "zh" }, "service_item": { "id": "UUID", "name": "翻译" }, "pricing_unit": { "id": "UUID", "name": "每词" }, "unit_price": 0.15, } ] } }