-- ===================================================== -- SPA管理系统 - 核心业务表 -- 版本: 1.0 -- 创建时间: 2025-12-30 -- ===================================================== -- 设置字符集 SET NAMES utf8mb4; SET FOREIGN_KEY_CHECKS = 0; -- ===================================================== -- 1. 技师信息表 -- ===================================================== DROP TABLE IF EXISTS `spa_technician`; CREATE TABLE `spa_technician` ( `id` bigint unsigned NOT NULL AUTO_INCREMENT COMMENT 'ID', `created_at` datetime(3) DEFAULT NULL COMMENT '创建时间', `updated_at` datetime(3) DEFAULT NULL COMMENT '更新时间', `deleted_at` datetime(3) DEFAULT NULL COMMENT '删除时间', -- 基本信息 `user_id` bigint unsigned DEFAULT NULL COMMENT '关联系统用户ID', `technician_no` varchar(50) NOT NULL COMMENT '技师工号', `name` varchar(100) NOT NULL COMMENT '技师姓名', `gender` tinyint DEFAULT 0 COMMENT '性别 0未知 1男 2女', `phone` varchar(20) DEFAULT NULL COMMENT '联系电话', `id_card` varchar(18) DEFAULT NULL COMMENT '身份证号', `avatar` varchar(500) DEFAULT NULL COMMENT '头像URL', `birthday` date DEFAULT NULL COMMENT '生日', `address` varchar(500) DEFAULT NULL COMMENT '居住地址', -- 专业信息 `level` tinyint DEFAULT 1 COMMENT '技师等级 1初级 2中级 3高级 4首席 5金牌', `specialties` json DEFAULT NULL COMMENT '擅长项目JSON数组', `certificates` json DEFAULT NULL COMMENT '资格证书JSON', `service_years` int DEFAULT 0 COMMENT '服务年限(月)', `introduction` text COMMENT '个人简介', -- 在职状态 `status` tinyint DEFAULT 1 COMMENT '在职状态 1在职 2休假 3离职 4停职', `entry_date` date DEFAULT NULL COMMENT '入职日期', `leave_date` date DEFAULT NULL COMMENT '离职日期', `contract_start` date DEFAULT NULL COMMENT '合同开始日期', `contract_end` date DEFAULT NULL COMMENT '合同结束日期', -- 薪资信息 `salary_type` tinyint DEFAULT 1 COMMENT '薪资类型 1纯提成 2底薪+提成 3固定工资', `base_salary` decimal(10,2) DEFAULT 0.00 COMMENT '基本工资', `commission_rate` decimal(5,2) DEFAULT 0.00 COMMENT '默认提成比例%', -- 代理关联 `agent_id` bigint unsigned DEFAULT NULL COMMENT '推荐代理ID', `agent_commission_rate` decimal(5,2) DEFAULT 0.00 COMMENT '代理抽成比例%', `bind_time` datetime DEFAULT NULL COMMENT '绑定代理时间', -- 统计数据 `rating` decimal(3,2) DEFAULT 5.00 COMMENT '综合评分', `total_orders` int DEFAULT 0 COMMENT '累计服务单数', `total_income` decimal(12,2) DEFAULT 0.00 COMMENT '累计收入', `total_customers` int DEFAULT 0 COMMENT '累计服务客户数', -- 其他 `is_recommended` tinyint DEFAULT 0 COMMENT '是否推荐技师 0否 1是', `sort` int DEFAULT 0 COMMENT '排序', `remark` text COMMENT '备注', PRIMARY KEY (`id`), UNIQUE KEY `idx_technician_no` (`technician_no`), KEY `idx_user_id` (`user_id`), KEY `idx_agent_id` (`agent_id`), KEY `idx_status` (`status`), KEY `idx_level` (`level`), KEY `idx_deleted_at` (`deleted_at`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='技师信息表'; -- ===================================================== -- 2. 代理信息表 -- ===================================================== DROP TABLE IF EXISTS `spa_agent`; CREATE TABLE `spa_agent` ( `id` bigint unsigned NOT NULL AUTO_INCREMENT COMMENT 'ID', `created_at` datetime(3) DEFAULT NULL COMMENT '创建时间', `updated_at` datetime(3) DEFAULT NULL COMMENT '更新时间', `deleted_at` datetime(3) DEFAULT NULL COMMENT '删除时间', -- 基本信息 `user_id` bigint unsigned DEFAULT NULL COMMENT '关联系统用户ID', `agent_no` varchar(50) NOT NULL COMMENT '代理编号', `name` varchar(100) NOT NULL COMMENT '代理姓名', `phone` varchar(20) NOT NULL COMMENT '联系电话', `avatar` varchar(500) DEFAULT NULL COMMENT '头像URL', -- 代理等级 `level` tinyint DEFAULT 1 COMMENT '代理等级 1普通 2银牌 3金牌 4钻石 5皇冠', `parent_agent_id` bigint unsigned DEFAULT NULL COMMENT '上级代理ID', `agent_path` varchar(500) DEFAULT NULL COMMENT '代理路径 如: 1/2/3/', -- 分佣比例 `technician_commission_rate` decimal(5,2) DEFAULT 0.00 COMMENT '技师订单抽成比例%', `customer_commission_rate` decimal(5,2) DEFAULT 0.00 COMMENT '客户订单抽成比例%', `sub_agent_commission_rate` decimal(5,2) DEFAULT 0.00 COMMENT '下级代理抽成比例%', -- 状态 `status` tinyint DEFAULT 1 COMMENT '状态 1正常 2冻结 3注销', `join_date` date DEFAULT NULL COMMENT '加入日期', -- 统计数据 `total_technicians` int DEFAULT 0 COMMENT '累计推荐技师数', `active_technicians` int DEFAULT 0 COMMENT '活跃技师数', `total_customers` int DEFAULT 0 COMMENT '累计推荐客户数', `active_customers` int DEFAULT 0 COMMENT '活跃客户数', `total_sub_agents` int DEFAULT 0 COMMENT '累计下级代理数', `total_income` decimal(12,2) DEFAULT 0.00 COMMENT '累计收入', `total_orders` int DEFAULT 0 COMMENT '累计关联订单数', -- 结算信息 `bank_name` varchar(100) DEFAULT NULL COMMENT '开户银行', `bank_account` varchar(50) DEFAULT NULL COMMENT '银行账号', `account_name` varchar(100) DEFAULT NULL COMMENT '账户名', `alipay_account` varchar(100) DEFAULT NULL COMMENT '支付宝账号', `wechat_account` varchar(100) DEFAULT NULL COMMENT '微信账号', `remark` text COMMENT '备注', PRIMARY KEY (`id`), UNIQUE KEY `idx_agent_no` (`agent_no`), KEY `idx_user_id` (`user_id`), KEY `idx_parent_agent_id` (`parent_agent_id`), KEY `idx_level` (`level`), KEY `idx_status` (`status`), KEY `idx_deleted_at` (`deleted_at`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='代理信息表'; -- ===================================================== -- 3. 客户信息表 -- ===================================================== DROP TABLE IF EXISTS `spa_customer`; CREATE TABLE `spa_customer` ( `id` bigint unsigned NOT NULL AUTO_INCREMENT COMMENT 'ID', `created_at` datetime(3) DEFAULT NULL COMMENT '创建时间', `updated_at` datetime(3) DEFAULT NULL COMMENT '更新时间', `deleted_at` datetime(3) DEFAULT NULL COMMENT '删除时间', -- 基本信息 `user_id` bigint unsigned DEFAULT NULL COMMENT '关联系统用户ID', `customer_no` varchar(50) NOT NULL COMMENT '客户编号', `nickname` varchar(100) DEFAULT NULL COMMENT '昵称', `real_name` varchar(100) DEFAULT NULL COMMENT '真实姓名', `gender` tinyint DEFAULT 0 COMMENT '性别 0未知 1男 2女', `phone` varchar(20) DEFAULT NULL COMMENT '联系电话', `avatar` varchar(500) DEFAULT NULL COMMENT '头像URL', `birthday` date DEFAULT NULL COMMENT '生日', -- 会员信息 `member_level` tinyint DEFAULT 0 COMMENT '会员等级 0普通 1银卡 2金卡 3钻石 4黑金', `member_expire_time` datetime DEFAULT NULL COMMENT '会员到期时间', `points` int DEFAULT 0 COMMENT '积分', -- 推荐关系 `referrer_type` tinyint DEFAULT 0 COMMENT '推荐人类型 0无 1客户 2代理', `referrer_id` bigint unsigned DEFAULT NULL COMMENT '推荐人ID', `agent_id` bigint unsigned DEFAULT NULL COMMENT '绑定代理ID', `agent_commission_rate` decimal(5,2) DEFAULT 0.00 COMMENT '代理抽成比例%', `bind_time` datetime DEFAULT NULL COMMENT '绑定时间', -- 统计数据 `total_orders` int DEFAULT 0 COMMENT '累计订单数', `total_amount` decimal(12,2) DEFAULT 0.00 COMMENT '累计消费金额', `total_referrals` int DEFAULT 0 COMMENT '累计推荐客户数', `last_order_time` datetime DEFAULT NULL COMMENT '最后下单时间', `avg_rating` decimal(3,2) DEFAULT NULL COMMENT '平均评分', -- 状态 `status` tinyint DEFAULT 1 COMMENT '状态 1正常 2黑名单 3注销', `source` varchar(50) DEFAULT NULL COMMENT '来源渠道', `remark` text COMMENT '备注', PRIMARY KEY (`id`), UNIQUE KEY `idx_customer_no` (`customer_no`), KEY `idx_user_id` (`user_id`), KEY `idx_phone` (`phone`), KEY `idx_referrer` (`referrer_type`, `referrer_id`), KEY `idx_agent_id` (`agent_id`), KEY `idx_member_level` (`member_level`), KEY `idx_deleted_at` (`deleted_at`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='客户信息表'; -- ===================================================== -- 4. 服务分类表 -- ===================================================== DROP TABLE IF EXISTS `spa_service_category`; CREATE TABLE `spa_service_category` ( `id` bigint unsigned NOT NULL AUTO_INCREMENT COMMENT 'ID', `created_at` datetime(3) DEFAULT NULL COMMENT '创建时间', `updated_at` datetime(3) DEFAULT NULL COMMENT '更新时间', `deleted_at` datetime(3) DEFAULT NULL COMMENT '删除时间', `parent_id` bigint unsigned DEFAULT 0 COMMENT '父分类ID', `name` varchar(100) NOT NULL COMMENT '分类名称', `icon` varchar(500) DEFAULT NULL COMMENT '图标', `description` text COMMENT '描述', `sort` int DEFAULT 0 COMMENT '排序', `status` tinyint DEFAULT 1 COMMENT '状态 1启用 2禁用', PRIMARY KEY (`id`), KEY `idx_parent_id` (`parent_id`), KEY `idx_deleted_at` (`deleted_at`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='服务分类表'; -- ===================================================== -- 5. 服务项目表 -- ===================================================== DROP TABLE IF EXISTS `spa_service_item`; CREATE TABLE `spa_service_item` ( `id` bigint unsigned NOT NULL AUTO_INCREMENT COMMENT 'ID', `created_at` datetime(3) DEFAULT NULL COMMENT '创建时间', `updated_at` datetime(3) DEFAULT NULL COMMENT '更新时间', `deleted_at` datetime(3) DEFAULT NULL COMMENT '删除时间', -- 基本信息 `category_id` bigint unsigned DEFAULT NULL COMMENT '服务分类ID', `item_no` varchar(50) NOT NULL COMMENT '项目编号', `name` varchar(100) NOT NULL COMMENT '项目名称', `sub_title` varchar(200) DEFAULT NULL COMMENT '副标题', `description` text COMMENT '项目描述', `cover_image` varchar(500) DEFAULT NULL COMMENT '封面图', `images` json DEFAULT NULL COMMENT '详情图片JSON数组', -- 价格信息 `duration` int NOT NULL COMMENT '标准时长(分钟)', `price` decimal(10,2) NOT NULL COMMENT '标准价格', `vip_price` decimal(10,2) DEFAULT NULL COMMENT '会员价', `cost_price` decimal(10,2) DEFAULT 0.00 COMMENT '成本价', -- 技师要求 `required_level` tinyint DEFAULT 1 COMMENT '要求技师等级', `required_gender` tinyint DEFAULT 0 COMMENT '要求技师性别 0不限 1男 2女', -- 提成设置 `commission_type` tinyint DEFAULT 1 COMMENT '提成类型 1按比例 2固定金额', `commission_value` decimal(10,2) DEFAULT 0.00 COMMENT '提成值', -- 服务详情 `service_steps` json DEFAULT NULL COMMENT '服务流程JSON', `required_products` json DEFAULT NULL COMMENT '所需产品JSON', `precautions` text COMMENT '注意事项', -- 销售信息 `sales_count` int DEFAULT 0 COMMENT '销量', `stock` int DEFAULT -1 COMMENT '库存 -1不限', `status` tinyint DEFAULT 1 COMMENT '状态 1上架 2下架', `is_hot` tinyint DEFAULT 0 COMMENT '是否热门 0否 1是', `is_new` tinyint DEFAULT 0 COMMENT '是否新品 0否 1是', `sort` int DEFAULT 0 COMMENT '排序', PRIMARY KEY (`id`), UNIQUE KEY `idx_item_no` (`item_no`), KEY `idx_category_id` (`category_id`), KEY `idx_status` (`status`), KEY `idx_deleted_at` (`deleted_at`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='服务项目表'; SET FOREIGN_KEY_CHECKS = 1;