37 KiB
37 KiB
智能项目定价模型 - 数据库设计
版本:v1.0
创建日期:2026-01-19
最后更新:2026-01-19
负责人:待定
1. 数据库规范
遵循《瑞小美系统技术栈标准与字符标准》:
| 项目 | 标准 |
|---|---|
| 数据库 | MySQL 8.0 |
| 字符集 | utf8mb4 |
| 排序规则 | utf8mb4_unicode_ci |
| 时区 | Asia/Shanghai (UTC+8) |
| 日期格式 | ISO 8601 (YYYY-MM-DDTHH:mm:ss) |
命名规范
| 类型 | 规范 | 示例 |
|---|---|---|
| 表名 | 小写,下划线分隔,复数形式 | projects, cost_items |
| 字段名 | 小写,下划线分隔 | project_name, created_at |
| 主键 | id,自增整数或 UUID |
id BIGINT AUTO_INCREMENT |
| 外键 | {关联表}_id |
project_id |
| 时间戳 | created_at, updated_at |
- |
| 布尔值 | is_ 或 has_ 前缀 |
is_active, has_discount |
| 金额 | DECIMAL(12, 2) | unit_price DECIMAL(12, 2) |
| 百分比 | DECIMAL(5, 2) | discount_rate DECIMAL(5, 2) |
2. ER 图
┌─────────────────────────────────────────────────────────────────────────────────────┐
│ 成本核算模块 │
├─────────────────────────────────────────────────────────────────────────────────────┤
│ │
│ ┌─────────────────┐ ┌─────────────────┐ ┌─────────────────┐ │
│ │ projects │ │ materials │ │ equipments │ │
│ │ 服务项目 │ │ 耗材 │ │ 设备 │ │
│ └────────┬────────┘ └────────┬────────┘ └────────┬────────┘ │
│ │ │ │ │
│ │ 1:N │ M:N │ M:N │
│ ▼ ▼ ▼ │
│ ┌──────────────────────────────────────────────────────────────┐ │
│ │ project_cost_items │ │
│ │ 项目成本明细 │ │
│ └──────────────────────────────────────────────────────────────┘ │
│ │ │
│ │ ┌─────────────────┐ │
│ │ │ staff_levels │ │
│ │ │ 人员级别 │ │
│ │ └────────┬────────┘ │
│ │ │ │
│ ▼ ▼ │
│ ┌─────────────────────────────────────────────────────────────┐ │
│ │ project_labor_costs │ │
│ │ 项目人工成本 │ │
│ └─────────────────────────────────────────────────────────────┘ │
│ │
│ ┌─────────────────┐ │
│ │ fixed_costs │ ────────────────────────────────────────────────────────────► │
│ │ 固定成本 │ │
│ └─────────────────┘ │
│ │
└─────────────────────────────────────────────────────────────────────────────────────┘
┌─────────────────────────────────────────────────────────────────────────────────────┐
│ 市场行情模块 │
├─────────────────────────────────────────────────────────────────────────────────────┤
│ │
│ ┌─────────────────┐ ┌─────────────────┐ │
│ │ competitors │ ─────1:N────► │ competitor_prices│ │
│ │ 竞品机构 │ │ 竞品价格 │ │
│ └─────────────────┘ └────────┬────────┘ │
│ │ │
│ │ N:1 │
│ ▼ │
│ ┌─────────────────┐ │
│ │ projects │ │
│ └─────────────────┘ │
│ │
│ ┌─────────────────┐ │
│ │ benchmark_prices│ 标杆价格参考 │
│ └─────────────────┘ │
│ │
└─────────────────────────────────────────────────────────────────────────────────────┘
┌─────────────────────────────────────────────────────────────────────────────────────┐
│ 定价与模拟模块 │
├─────────────────────────────────────────────────────────────────────────────────────┤
│ │
│ ┌─────────────────┐ ┌─────────────────┐ │
│ │ pricing_plans │ ─────1:N────► │profit_simulations│ │
│ │ 定价方案 │ │ 利润模拟 │ │
│ └────────┬────────┘ └─────────────────┘ │
│ │ │
│ │ N:1 │
│ ▼ │
│ ┌─────────────────┐ │
│ │ projects │ │
│ └─────────────────┘ │
│ │
└─────────────────────────────────────────────────────────────────────────────────────┘
3. 表结构设计
3.1 基础模块
3.1.1 projects(服务项目)
| 字段 | 类型 | 约束 | 说明 |
|---|---|---|---|
| id | BIGINT | PK, AUTO_INCREMENT | 主键 |
| project_code | VARCHAR(50) | UNIQUE, NOT NULL | 项目编码 |
| project_name | VARCHAR(100) | NOT NULL | 项目名称 |
| category_id | BIGINT | FK → categories.id | 项目分类 |
| description | TEXT | - | 项目描述 |
| duration_minutes | INT | NOT NULL, DEFAULT 0 | 操作时长(分钟) |
| is_active | TINYINT(1) | NOT NULL, DEFAULT 1 | 是否启用 |
| created_at | DATETIME | NOT NULL | 创建时间 |
| updated_at | DATETIME | NOT NULL | 更新时间 |
| created_by | BIGINT | FK → users.id | 创建人 |
索引:
idx_project_code(project_code)idx_category_id(category_id)idx_is_active(is_active)
CREATE TABLE projects (
id BIGINT AUTO_INCREMENT PRIMARY KEY,
project_code VARCHAR(50) NOT NULL UNIQUE,
project_name VARCHAR(100) NOT NULL,
category_id BIGINT,
description TEXT,
duration_minutes INT NOT NULL DEFAULT 0,
is_active TINYINT(1) NOT NULL DEFAULT 1,
created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
updated_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
created_by BIGINT,
INDEX idx_project_code (project_code),
INDEX idx_category_id (category_id),
INDEX idx_is_active (is_active)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
3.1.2 categories(项目分类)
| 字段 | 类型 | 约束 | 说明 |
|---|---|---|---|
| id | BIGINT | PK, AUTO_INCREMENT | 主键 |
| category_name | VARCHAR(50) | NOT NULL | 分类名称 |
| parent_id | BIGINT | FK → categories.id | 父分类 |
| sort_order | INT | NOT NULL, DEFAULT 0 | 排序 |
| is_active | TINYINT(1) | NOT NULL, DEFAULT 1 | 是否启用 |
| created_at | DATETIME | NOT NULL | 创建时间 |
| updated_at | DATETIME | NOT NULL | 更新时间 |
CREATE TABLE categories (
id BIGINT AUTO_INCREMENT PRIMARY KEY,
category_name VARCHAR(50) NOT NULL,
parent_id BIGINT,
sort_order INT NOT NULL DEFAULT 0,
is_active TINYINT(1) NOT NULL DEFAULT 1,
created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
updated_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
INDEX idx_parent_id (parent_id)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
3.2 成本核算模块
3.2.1 materials(耗材)
| 字段 | 类型 | 约束 | 说明 |
|---|---|---|---|
| id | BIGINT | PK, AUTO_INCREMENT | 主键 |
| material_code | VARCHAR(50) | UNIQUE, NOT NULL | 耗材编码 |
| material_name | VARCHAR(100) | NOT NULL | 耗材名称 |
| unit | VARCHAR(20) | NOT NULL | 单位(支/ml/个) |
| unit_price | DECIMAL(12,2) | NOT NULL | 单价 |
| supplier | VARCHAR(100) | - | 供应商 |
| material_type | VARCHAR(20) | NOT NULL | 类型:consumable/injectable/product |
| is_active | TINYINT(1) | NOT NULL, DEFAULT 1 | 是否启用 |
| created_at | DATETIME | NOT NULL | 创建时间 |
| updated_at | DATETIME | NOT NULL | 更新时间 |
CREATE TABLE materials (
id BIGINT AUTO_INCREMENT PRIMARY KEY,
material_code VARCHAR(50) NOT NULL UNIQUE,
material_name VARCHAR(100) NOT NULL,
unit VARCHAR(20) NOT NULL,
unit_price DECIMAL(12,2) NOT NULL,
supplier VARCHAR(100),
material_type VARCHAR(20) NOT NULL COMMENT 'consumable-耗材, injectable-针剂, product-产品',
is_active TINYINT(1) NOT NULL DEFAULT 1,
created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
updated_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
INDEX idx_material_code (material_code),
INDEX idx_material_type (material_type)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
3.2.2 equipments(设备)
| 字段 | 类型 | 约束 | 说明 |
|---|---|---|---|
| id | BIGINT | PK, AUTO_INCREMENT | 主键 |
| equipment_code | VARCHAR(50) | UNIQUE, NOT NULL | 设备编码 |
| equipment_name | VARCHAR(100) | NOT NULL | 设备名称 |
| original_value | DECIMAL(12,2) | NOT NULL | 设备原值 |
| residual_rate | DECIMAL(5,2) | NOT NULL, DEFAULT 5.00 | 残值率(%) |
| service_years | INT | NOT NULL | 预计使用年限 |
| estimated_uses | INT | NOT NULL | 预计使用次数 |
| depreciation_per_use | DECIMAL(12,4) | NOT NULL | 单次折旧成本(计算字段) |
| purchase_date | DATE | - | 购入日期 |
| is_active | TINYINT(1) | NOT NULL, DEFAULT 1 | 是否启用 |
| created_at | DATETIME | NOT NULL | 创建时间 |
| updated_at | DATETIME | NOT NULL | 更新时间 |
CREATE TABLE equipments (
id BIGINT AUTO_INCREMENT PRIMARY KEY,
equipment_code VARCHAR(50) NOT NULL UNIQUE,
equipment_name VARCHAR(100) NOT NULL,
original_value DECIMAL(12,2) NOT NULL,
residual_rate DECIMAL(5,2) NOT NULL DEFAULT 5.00,
service_years INT NOT NULL,
estimated_uses INT NOT NULL,
depreciation_per_use DECIMAL(12,4) NOT NULL COMMENT '单次折旧 = (原值 - 残值) / 总次数',
purchase_date DATE,
is_active TINYINT(1) NOT NULL DEFAULT 1,
created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
updated_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
INDEX idx_equipment_code (equipment_code)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
3.2.3 staff_levels(人员级别)
| 字段 | 类型 | 约束 | 说明 |
|---|---|---|---|
| id | BIGINT | PK, AUTO_INCREMENT | 主键 |
| level_code | VARCHAR(20) | UNIQUE, NOT NULL | 级别编码 |
| level_name | VARCHAR(50) | NOT NULL | 级别名称 |
| hourly_rate | DECIMAL(10,2) | NOT NULL | 时薪(元/小时) |
| is_active | TINYINT(1) | NOT NULL, DEFAULT 1 | 是否启用 |
| created_at | DATETIME | NOT NULL | 创建时间 |
| updated_at | DATETIME | NOT NULL | 更新时间 |
CREATE TABLE staff_levels (
id BIGINT AUTO_INCREMENT PRIMARY KEY,
level_code VARCHAR(20) NOT NULL UNIQUE,
level_name VARCHAR(50) NOT NULL,
hourly_rate DECIMAL(10,2) NOT NULL COMMENT '元/小时',
is_active TINYINT(1) NOT NULL DEFAULT 1,
created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
updated_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
3.2.4 project_cost_items(项目成本明细-耗材设备)
| 字段 | 类型 | 约束 | 说明 |
|---|---|---|---|
| id | BIGINT | PK, AUTO_INCREMENT | 主键 |
| project_id | BIGINT | FK, NOT NULL | 项目ID |
| item_type | VARCHAR(20) | NOT NULL | 类型:material/equipment |
| item_id | BIGINT | NOT NULL | 耗材/设备ID |
| quantity | DECIMAL(10,4) | NOT NULL | 用量 |
| unit_cost | DECIMAL(12,4) | NOT NULL | 单位成本 |
| total_cost | DECIMAL(12,2) | NOT NULL | 总成本(计算) |
| remark | VARCHAR(200) | - | 备注 |
| created_at | DATETIME | NOT NULL | 创建时间 |
| updated_at | DATETIME | NOT NULL | 更新时间 |
CREATE TABLE project_cost_items (
id BIGINT AUTO_INCREMENT PRIMARY KEY,
project_id BIGINT NOT NULL,
item_type VARCHAR(20) NOT NULL COMMENT 'material-耗材, equipment-设备',
item_id BIGINT NOT NULL,
quantity DECIMAL(10,4) NOT NULL,
unit_cost DECIMAL(12,4) NOT NULL,
total_cost DECIMAL(12,2) NOT NULL COMMENT '= quantity * unit_cost',
remark VARCHAR(200),
created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
updated_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
INDEX idx_project_id (project_id),
INDEX idx_item_type (item_type)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
3.2.5 project_labor_costs(项目人工成本)
| 字段 | 类型 | 约束 | 说明 |
|---|---|---|---|
| id | BIGINT | PK, AUTO_INCREMENT | 主键 |
| project_id | BIGINT | FK, NOT NULL | 项目ID |
| staff_level_id | BIGINT | FK, NOT NULL | 人员级别ID |
| duration_minutes | INT | NOT NULL | 操作时长(分钟) |
| hourly_rate | DECIMAL(10,2) | NOT NULL | 时薪(记录时快照) |
| labor_cost | DECIMAL(12,2) | NOT NULL | 人工成本(计算) |
| remark | VARCHAR(200) | - | 备注 |
| created_at | DATETIME | NOT NULL | 创建时间 |
| updated_at | DATETIME | NOT NULL | 更新时间 |
CREATE TABLE project_labor_costs (
id BIGINT AUTO_INCREMENT PRIMARY KEY,
project_id BIGINT NOT NULL,
staff_level_id BIGINT NOT NULL,
duration_minutes INT NOT NULL,
hourly_rate DECIMAL(10,2) NOT NULL COMMENT '记录时的时薪快照',
labor_cost DECIMAL(12,2) NOT NULL COMMENT '= duration/60 * hourly_rate',
remark VARCHAR(200),
created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
updated_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
INDEX idx_project_id (project_id),
INDEX idx_staff_level_id (staff_level_id)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
3.2.6 fixed_costs(固定成本)
| 字段 | 类型 | 约束 | 说明 |
|---|---|---|---|
| id | BIGINT | PK, AUTO_INCREMENT | 主键 |
| cost_name | VARCHAR(100) | NOT NULL | 成本名称 |
| cost_type | VARCHAR(20) | NOT NULL | 类型:rent/utilities/property/other |
| monthly_amount | DECIMAL(12,2) | NOT NULL | 月度金额 |
| year_month | VARCHAR(7) | NOT NULL | 年月:2026-01 |
| allocation_method | VARCHAR(20) | NOT NULL, DEFAULT 'count' | 分摊方式:count/revenue/duration |
| is_active | TINYINT(1) | NOT NULL, DEFAULT 1 | 是否启用 |
| created_at | DATETIME | NOT NULL | 创建时间 |
| updated_at | DATETIME | NOT NULL | 更新时间 |
CREATE TABLE fixed_costs (
id BIGINT AUTO_INCREMENT PRIMARY KEY,
cost_name VARCHAR(100) NOT NULL,
cost_type VARCHAR(20) NOT NULL COMMENT 'rent-房租, utilities-水电, property-物业, other-其他',
monthly_amount DECIMAL(12,2) NOT NULL,
year_month VARCHAR(7) NOT NULL COMMENT '格式:2026-01',
allocation_method VARCHAR(20) NOT NULL DEFAULT 'count' COMMENT 'count-按项目数, revenue-按营收, duration-按时长',
is_active TINYINT(1) NOT NULL DEFAULT 1,
created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
updated_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
INDEX idx_year_month (year_month)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
3.2.7 project_cost_summaries(项目成本汇总-视图或表)
| 字段 | 类型 | 说明 |
|---|---|---|
| id | BIGINT | 主键 |
| project_id | BIGINT | 项目ID |
| material_cost | DECIMAL(12,2) | 耗材成本 |
| equipment_cost | DECIMAL(12,2) | 设备折旧成本 |
| labor_cost | DECIMAL(12,2) | 人工成本 |
| fixed_cost_allocation | DECIMAL(12,2) | 固定成本分摊 |
| total_cost | DECIMAL(12,2) | 总成本(最低成本线) |
| calculated_at | DATETIME | 计算时间 |
CREATE TABLE project_cost_summaries (
id BIGINT AUTO_INCREMENT PRIMARY KEY,
project_id BIGINT NOT NULL UNIQUE,
material_cost DECIMAL(12,2) NOT NULL DEFAULT 0.00,
equipment_cost DECIMAL(12,2) NOT NULL DEFAULT 0.00,
labor_cost DECIMAL(12,2) NOT NULL DEFAULT 0.00,
fixed_cost_allocation DECIMAL(12,2) NOT NULL DEFAULT 0.00,
total_cost DECIMAL(12,2) NOT NULL DEFAULT 0.00 COMMENT '最低成本线',
calculated_at DATETIME NOT NULL,
created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
updated_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
INDEX idx_project_id (project_id)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
3.3 市场行情模块
3.3.1 competitors(竞品机构)
| 字段 | 类型 | 约束 | 说明 |
|---|---|---|---|
| id | BIGINT | PK, AUTO_INCREMENT | 主键 |
| competitor_name | VARCHAR(100) | NOT NULL | 机构名称 |
| address | VARCHAR(200) | - | 地址 |
| distance_km | DECIMAL(5,2) | - | 距离(公里) |
| positioning | VARCHAR(20) | NOT NULL | 定位:high/medium/budget |
| contact | VARCHAR(50) | - | 联系方式 |
| is_key_competitor | TINYINT(1) | NOT NULL, DEFAULT 0 | 是否重点关注 |
| is_active | TINYINT(1) | NOT NULL, DEFAULT 1 | 是否启用 |
| created_at | DATETIME | NOT NULL | 创建时间 |
| updated_at | DATETIME | NOT NULL | 更新时间 |
CREATE TABLE competitors (
id BIGINT AUTO_INCREMENT PRIMARY KEY,
competitor_name VARCHAR(100) NOT NULL,
address VARCHAR(200),
distance_km DECIMAL(5,2),
positioning VARCHAR(20) NOT NULL COMMENT 'high-高端, medium-中端, budget-大众',
contact VARCHAR(50),
is_key_competitor TINYINT(1) NOT NULL DEFAULT 0,
is_active TINYINT(1) NOT NULL DEFAULT 1,
created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
updated_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
INDEX idx_positioning (positioning),
INDEX idx_is_key (is_key_competitor)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
3.3.2 competitor_prices(竞品价格)
| 字段 | 类型 | 约束 | 说明 |
|---|---|---|---|
| id | BIGINT | PK, AUTO_INCREMENT | 主键 |
| competitor_id | BIGINT | FK, NOT NULL | 竞品机构ID |
| project_id | BIGINT | FK | 关联本店项目ID(可空) |
| project_name | VARCHAR(100) | NOT NULL | 竞品项目名称 |
| original_price | DECIMAL(12,2) | NOT NULL | 原价 |
| promo_price | DECIMAL(12,2) | - | 促销价 |
| member_price | DECIMAL(12,2) | - | 会员价 |
| price_source | VARCHAR(20) | NOT NULL | 来源:official/meituan/dianping/survey |
| collected_at | DATE | NOT NULL | 采集日期 |
| remark | VARCHAR(200) | - | 备注 |
| created_at | DATETIME | NOT NULL | 创建时间 |
| updated_at | DATETIME | NOT NULL | 更新时间 |
CREATE TABLE competitor_prices (
id BIGINT AUTO_INCREMENT PRIMARY KEY,
competitor_id BIGINT NOT NULL,
project_id BIGINT COMMENT '关联本店项目',
project_name VARCHAR(100) NOT NULL COMMENT '竞品项目名称',
original_price DECIMAL(12,2) NOT NULL,
promo_price DECIMAL(12,2),
member_price DECIMAL(12,2),
price_source VARCHAR(20) NOT NULL COMMENT 'official-官网, meituan-美团, dianping-大众点评, survey-实地调研',
collected_at DATE NOT NULL,
remark VARCHAR(200),
created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
updated_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
INDEX idx_competitor_id (competitor_id),
INDEX idx_project_id (project_id),
INDEX idx_collected_at (collected_at)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
3.3.3 benchmark_prices(标杆价格)
| 字段 | 类型 | 约束 | 说明 |
|---|---|---|---|
| id | BIGINT | PK, AUTO_INCREMENT | 主键 |
| benchmark_name | VARCHAR(100) | NOT NULL | 标杆机构名称 |
| category_id | BIGINT | FK | 项目分类ID |
| min_price | DECIMAL(12,2) | NOT NULL | 最低价 |
| max_price | DECIMAL(12,2) | NOT NULL | 最高价 |
| avg_price | DECIMAL(12,2) | NOT NULL | 均价 |
| price_tier | VARCHAR(20) | NOT NULL | 价格带:low/medium/high/premium |
| effective_date | DATE | NOT NULL | 生效日期 |
| remark | VARCHAR(200) | - | 备注 |
| created_at | DATETIME | NOT NULL | 创建时间 |
| updated_at | DATETIME | NOT NULL | 更新时间 |
CREATE TABLE benchmark_prices (
id BIGINT AUTO_INCREMENT PRIMARY KEY,
benchmark_name VARCHAR(100) NOT NULL,
category_id BIGINT,
min_price DECIMAL(12,2) NOT NULL,
max_price DECIMAL(12,2) NOT NULL,
avg_price DECIMAL(12,2) NOT NULL,
price_tier VARCHAR(20) NOT NULL COMMENT 'low-低端, medium-中端, high-高端, premium-奢华',
effective_date DATE NOT NULL,
remark VARCHAR(200),
created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
updated_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
INDEX idx_category_id (category_id),
INDEX idx_effective_date (effective_date)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
3.3.4 market_analysis_results(市场分析结果)
| 字段 | 类型 | 约束 | 说明 |
|---|---|---|---|
| id | BIGINT | PK, AUTO_INCREMENT | 主键 |
| project_id | BIGINT | FK, NOT NULL | 项目ID |
| analysis_date | DATE | NOT NULL | 分析日期 |
| competitor_count | INT | NOT NULL | 样本竞品数量 |
| market_min_price | DECIMAL(12,2) | NOT NULL | 市场最低价 |
| market_max_price | DECIMAL(12,2) | NOT NULL | 市场最高价 |
| market_avg_price | DECIMAL(12,2) | NOT NULL | 市场均价 |
| market_median_price | DECIMAL(12,2) | NOT NULL | 市场中位价 |
| suggested_range_min | DECIMAL(12,2) | NOT NULL | 建议区间下限 |
| suggested_range_max | DECIMAL(12,2) | NOT NULL | 建议区间上限 |
| created_at | DATETIME | NOT NULL | 创建时间 |
CREATE TABLE market_analysis_results (
id BIGINT AUTO_INCREMENT PRIMARY KEY,
project_id BIGINT NOT NULL,
analysis_date DATE NOT NULL,
competitor_count INT NOT NULL,
market_min_price DECIMAL(12,2) NOT NULL,
market_max_price DECIMAL(12,2) NOT NULL,
market_avg_price DECIMAL(12,2) NOT NULL,
market_median_price DECIMAL(12,2) NOT NULL,
suggested_range_min DECIMAL(12,2) NOT NULL,
suggested_range_max DECIMAL(12,2) NOT NULL,
created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
INDEX idx_project_id (project_id),
INDEX idx_analysis_date (analysis_date)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
3.4 定价与模拟模块
3.4.1 pricing_plans(定价方案)
| 字段 | 类型 | 约束 | 说明 |
|---|---|---|---|
| id | BIGINT | PK, AUTO_INCREMENT | 主键 |
| project_id | BIGINT | FK, NOT NULL | 项目ID |
| plan_name | VARCHAR(100) | NOT NULL | 方案名称 |
| strategy_type | VARCHAR(20) | NOT NULL | 策略:traffic/profit/premium |
| base_cost | DECIMAL(12,2) | NOT NULL | 基础成本 |
| target_margin | DECIMAL(5,2) | NOT NULL | 目标毛利率(%) |
| suggested_price | DECIMAL(12,2) | NOT NULL | 建议价格 |
| final_price | DECIMAL(12,2) | - | 最终定价 |
| ai_advice | TEXT | - | AI 建议内容 |
| is_active | TINYINT(1) | NOT NULL, DEFAULT 1 | 是否启用 |
| created_at | DATETIME | NOT NULL | 创建时间 |
| updated_at | DATETIME | NOT NULL | 更新时间 |
| created_by | BIGINT | FK → users.id | 创建人 |
CREATE TABLE pricing_plans (
id BIGINT AUTO_INCREMENT PRIMARY KEY,
project_id BIGINT NOT NULL,
plan_name VARCHAR(100) NOT NULL,
strategy_type VARCHAR(20) NOT NULL COMMENT 'traffic-引流款, profit-利润款, premium-高端款',
base_cost DECIMAL(12,2) NOT NULL,
target_margin DECIMAL(5,2) NOT NULL,
suggested_price DECIMAL(12,2) NOT NULL,
final_price DECIMAL(12,2),
ai_advice TEXT,
is_active TINYINT(1) NOT NULL DEFAULT 1,
created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
updated_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
created_by BIGINT,
INDEX idx_project_id (project_id),
INDEX idx_strategy_type (strategy_type)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
3.4.2 profit_simulations(利润模拟)
| 字段 | 类型 | 约束 | 说明 |
|---|---|---|---|
| id | BIGINT | PK, AUTO_INCREMENT | 主键 |
| pricing_plan_id | BIGINT | FK, NOT NULL | 定价方案ID |
| simulation_name | VARCHAR(100) | NOT NULL | 模拟名称 |
| price | DECIMAL(12,2) | NOT NULL | 模拟价格 |
| estimated_volume | INT | NOT NULL | 预估客量 |
| period_type | VARCHAR(20) | NOT NULL | 周期:daily/weekly/monthly |
| estimated_revenue | DECIMAL(14,2) | NOT NULL | 预估收入 |
| estimated_cost | DECIMAL(14,2) | NOT NULL | 预估成本 |
| estimated_profit | DECIMAL(14,2) | NOT NULL | 预估利润 |
| profit_margin | DECIMAL(5,2) | NOT NULL | 利润率(%) |
| breakeven_volume | INT | NOT NULL | 盈亏平衡客量 |
| created_at | DATETIME | NOT NULL | 创建时间 |
| created_by | BIGINT | FK → users.id | 创建人 |
CREATE TABLE profit_simulations (
id BIGINT AUTO_INCREMENT PRIMARY KEY,
pricing_plan_id BIGINT NOT NULL,
simulation_name VARCHAR(100) NOT NULL,
price DECIMAL(12,2) NOT NULL,
estimated_volume INT NOT NULL,
period_type VARCHAR(20) NOT NULL COMMENT 'daily-日, weekly-周, monthly-月',
estimated_revenue DECIMAL(14,2) NOT NULL,
estimated_cost DECIMAL(14,2) NOT NULL,
estimated_profit DECIMAL(14,2) NOT NULL,
profit_margin DECIMAL(5,2) NOT NULL,
breakeven_volume INT NOT NULL,
created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
created_by BIGINT,
INDEX idx_pricing_plan_id (pricing_plan_id)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
3.4.3 sensitivity_analyses(敏感性分析)
| 字段 | 类型 | 约束 | 说明 |
|---|---|---|---|
| id | BIGINT | PK, AUTO_INCREMENT | 主键 |
| simulation_id | BIGINT | FK, NOT NULL | 模拟ID |
| price_change_rate | DECIMAL(5,2) | NOT NULL | 价格变动率(%):-20,-15,-10,-5,0,5,10,15,20 |
| adjusted_price | DECIMAL(12,2) | NOT NULL | 调整后价格 |
| adjusted_profit | DECIMAL(14,2) | NOT NULL | 调整后利润 |
| profit_change_rate | DECIMAL(5,2) | NOT NULL | 利润变动率(%) |
| created_at | DATETIME | NOT NULL | 创建时间 |
CREATE TABLE sensitivity_analyses (
id BIGINT AUTO_INCREMENT PRIMARY KEY,
simulation_id BIGINT NOT NULL,
price_change_rate DECIMAL(5,2) NOT NULL COMMENT '如 -20, -10, 0, 10, 20',
adjusted_price DECIMAL(12,2) NOT NULL,
adjusted_profit DECIMAL(14,2) NOT NULL,
profit_change_rate DECIMAL(5,2) NOT NULL,
created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
INDEX idx_simulation_id (simulation_id)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
3.5 系统模块
3.5.1 users(用户-与门户系统关联)
| 字段 | 类型 | 约束 | 说明 |
|---|---|---|---|
| id | BIGINT | PK, AUTO_INCREMENT | 主键 |
| portal_user_id | BIGINT | UNIQUE, NOT NULL | 门户用户ID |
| username | VARCHAR(50) | NOT NULL | 用户名 |
| role | VARCHAR(20) | NOT NULL | 角色:admin/manager/operator |
| is_active | TINYINT(1) | NOT NULL, DEFAULT 1 | 是否启用 |
| created_at | DATETIME | NOT NULL | 创建时间 |
| updated_at | DATETIME | NOT NULL | 更新时间 |
CREATE TABLE users (
id BIGINT AUTO_INCREMENT PRIMARY KEY,
portal_user_id BIGINT NOT NULL UNIQUE,
username VARCHAR(50) NOT NULL,
role VARCHAR(20) NOT NULL COMMENT 'admin-管理员, manager-经理, operator-操作员',
is_active TINYINT(1) NOT NULL DEFAULT 1,
created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
updated_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
INDEX idx_portal_user_id (portal_user_id)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
3.5.2 operation_logs(操作日志)
| 字段 | 类型 | 约束 | 说明 |
|---|---|---|---|
| id | BIGINT | PK, AUTO_INCREMENT | 主键 |
| user_id | BIGINT | FK | 用户ID |
| module | VARCHAR(50) | NOT NULL | 模块:cost/market/pricing/profit |
| action | VARCHAR(50) | NOT NULL | 操作:create/update/delete/export |
| target_type | VARCHAR(50) | NOT NULL | 对象类型 |
| target_id | BIGINT | - | 对象ID |
| detail | JSON | - | 详情 |
| ip_address | VARCHAR(45) | - | IP地址 |
| created_at | DATETIME | NOT NULL | 操作时间 |
CREATE TABLE operation_logs (
id BIGINT AUTO_INCREMENT PRIMARY KEY,
user_id BIGINT,
module VARCHAR(50) NOT NULL,
action VARCHAR(50) NOT NULL,
target_type VARCHAR(50) NOT NULL,
target_id BIGINT,
detail JSON,
ip_address VARCHAR(45),
created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
INDEX idx_user_id (user_id),
INDEX idx_module (module),
INDEX idx_created_at (created_at)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
4. 数据字典
4.1 枚举值定义
material_type(耗材类型)
| 值 | 说明 |
|---|---|
| consumable | 一般耗材 |
| injectable | 针剂 |
| product | 产品 |
allocation_method(分摊方式)
| 值 | 说明 |
|---|---|
| count | 按项目数量平均分摊 |
| revenue | 按项目营收占比分摊 |
| duration | 按项目时长占比分摊 |
positioning(机构定位)
| 值 | 说明 |
|---|---|
| high | 高端 |
| medium | 中端 |
| budget | 大众 |
price_source(价格来源)
| 值 | 说明 |
|---|---|
| official | 官网 |
| meituan | 美团 |
| dianping | 大众点评 |
| survey | 实地调研 |
strategy_type(定价策略)
| 值 | 说明 |
|---|---|
| traffic | 引流款 |
| profit | 利润款 |
| premium | 高端款 |
period_type(周期类型)
| 值 | 说明 |
|---|---|
| daily | 日 |
| weekly | 周 |
| monthly | 月 |
5. 索引设计原则
- 主键:所有表使用
id BIGINT AUTO_INCREMENT作为主键 - 外键索引:所有外键字段建立索引
- 查询优化:高频查询字段建立索引
- 联合索引:多条件查询使用联合索引,遵循最左前缀原则
- 避免过度索引:权衡查询性能与写入性能
6. 数据迁移
6.1 初始化脚本
-- 创建数据库
CREATE DATABASE IF NOT EXISTS pricing_model
DEFAULT CHARACTER SET utf8mb4
DEFAULT COLLATE utf8mb4_unicode_ci;
USE pricing_model;
-- 按依赖顺序创建表
-- 1. 基础表(无依赖)
-- categories, materials, equipments, staff_levels, fixed_costs, competitors
-- 2. 依赖基础表
-- projects, benchmark_prices
-- 3. 依赖项目表
-- project_cost_items, project_labor_costs, project_cost_summaries
-- competitor_prices, market_analysis_results
-- pricing_plans
-- 4. 依赖定价方案
-- profit_simulations
-- 5. 依赖模拟
-- sensitivity_analyses
-- 6. 系统表
-- users, operation_logs
6.2 初始数据
-- 人员级别初始数据
INSERT INTO staff_levels (level_code, level_name, hourly_rate) VALUES
('L1', '初级美容师', 30.00),
('L2', '中级美容师', 50.00),
('L3', '高级美容师', 80.00),
('L4', '资深美容师', 120.00),
('D1', '主治医师', 200.00),
('D2', '副主任医师', 350.00),
('D3', '主任医师', 500.00);
-- 项目分类初始数据
INSERT INTO categories (category_name, parent_id, sort_order) VALUES
('皮肤管理', NULL, 1),
('注射类', NULL, 2),
('光电类', NULL, 3),
('手术类', NULL, 4);
7. 附录
7.1 参考文档
- 《瑞小美系统技术栈标准与字符标准》
- MySQL 8.0 官方文档
瑞小美技术团队 · 2026-01-19