-- ============================================================================ -- 优匠优服 · Phase 1 数据库设计(全链路 MVP) -- 约定: -- * 全部为【新增表】,不改动任何既有 fa_* 系统表结构 -- * 表前缀 fa_(与 FastAdmin 一致),引擎 InnoDB,字符集 utf8mb4 -- * 金额 decimal(10,2),时间戳 bigint(与 FastAdmin 一致) -- 回滚:见文末 DROP 脚本 -- ============================================================================ SET NAMES utf8mb4; SET FOREIGN_KEY_CHECKS = 0; -- 1. 服务类目(对应首页 15 宫格) CREATE TABLE IF NOT EXISTS `fa_service_cat` ( `id` int(10) unsigned NOT NULL AUTO_INCREMENT, `pid` int(10) unsigned NOT NULL DEFAULT '0' COMMENT '父级ID', `name` varchar(50) NOT NULL DEFAULT '' COMMENT '类目名', `icon` varchar(50) NOT NULL DEFAULT '' COMMENT '图标标识(前端CSS图元键)', `weigh` int(11) NOT NULL DEFAULT '0' COMMENT '权重,倒序', `status` enum('normal','hidden') NOT NULL DEFAULT 'normal', `createtime` bigint(16) DEFAULT NULL, `updatetime` bigint(16) DEFAULT NULL, PRIMARY KEY (`id`), KEY `pid` (`pid`), KEY `weigh` (`weigh`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='服务类目'; -- 2. 服务项目 / 标准商品模板 CREATE TABLE IF NOT EXISTS `fa_service` ( `id` int(10) unsigned NOT NULL AUTO_INCREMENT, `cat_id` int(10) unsigned NOT NULL DEFAULT '0' COMMENT '类目ID', `name` varchar(100) NOT NULL DEFAULT '' COMMENT '服务名称', `image` varchar(255) NOT NULL DEFAULT '' COMMENT '主图', `price_type` enum('fixed','quote','range') NOT NULL DEFAULT 'fixed' COMMENT '一口价/报价竞价/区间', `base_price` decimal(10,2) NOT NULL DEFAULT '0.00' COMMENT '基础价', `max_price` decimal(10,2) NOT NULL DEFAULT '0.00' COMMENT '区间上限', `unit` varchar(20) NOT NULL DEFAULT '次' COMMENT '计价单位', `floor_fee` decimal(10,2) NOT NULL DEFAULT '0.00' COMMENT '楼层费(元/层)', `free_floor` int(11) NOT NULL DEFAULT '0' COMMENT '免费楼层数', `need_model` tinyint(1) NOT NULL DEFAULT '1' COMMENT '是否需填型号', `description` varchar(500) NOT NULL DEFAULT '' COMMENT '服务说明', `sales` int(11) NOT NULL DEFAULT '0' COMMENT '销量', `weigh` int(11) NOT NULL DEFAULT '0', `status` enum('normal','hidden') NOT NULL DEFAULT 'normal', `createtime` bigint(16) DEFAULT NULL, `updatetime` bigint(16) DEFAULT NULL, PRIMARY KEY (`id`), KEY `cat_id` (`cat_id`), KEY `status` (`status`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='服务项目'; -- 3. 服务地址 CREATE TABLE IF NOT EXISTS `fa_address` ( `id` int(10) unsigned NOT NULL AUTO_INCREMENT, `user_id` int(10) unsigned NOT NULL DEFAULT '0', `contact` varchar(50) NOT NULL DEFAULT '' COMMENT '联系人', `mobile` varchar(20) NOT NULL DEFAULT '' COMMENT '联系电话', `province` varchar(50) NOT NULL DEFAULT '', `city` varchar(50) NOT NULL DEFAULT '', `district` varchar(50) NOT NULL DEFAULT '', `address` varchar(255) NOT NULL DEFAULT '' COMMENT '详细地址', `lng` varchar(20) NOT NULL DEFAULT '' COMMENT '经度(地图选点)', `lat` varchar(20) NOT NULL DEFAULT '' COMMENT '纬度(地图选点)', `floor` int(11) NOT NULL DEFAULT '1' COMMENT '楼层', `has_elevator` tinyint(1) NOT NULL DEFAULT '1' COMMENT '有无电梯', `is_default` tinyint(1) NOT NULL DEFAULT '0' COMMENT '默认地址', `createtime` bigint(16) DEFAULT NULL, `updatetime` bigint(16) DEFAULT NULL, PRIMARY KEY (`id`), KEY `user_id` (`user_id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='服务地址'; -- 4. 师傅档案(入驻 / 资质 / 信用) CREATE TABLE IF NOT EXISTS `fa_master` ( `id` int(10) unsigned NOT NULL AUTO_INCREMENT, `user_id` int(10) unsigned NOT NULL DEFAULT '0' COMMENT '关联 fa_user.id', `realname` varchar(50) NOT NULL DEFAULT '' COMMENT '真实姓名', `mobile` varchar(20) NOT NULL DEFAULT '' COMMENT '手机号', `idcard_no` varchar(40) NOT NULL DEFAULT '' COMMENT '身份证号(脱敏)', `idcard_front` varchar(255) NOT NULL DEFAULT '' COMMENT '身份证正面', `idcard_back` varchar(255) NOT NULL DEFAULT '' COMMENT '身份证反面', `avatar` varchar(255) NOT NULL DEFAULT '' COMMENT '头像', `cert_images` varchar(1000) NOT NULL DEFAULT '' COMMENT '技能证书(json)', `city` varchar(50) NOT NULL DEFAULT '' COMMENT '服务城市', `lng` varchar(20) NOT NULL DEFAULT '' COMMENT '当前经度', `lat` varchar(20) NOT NULL DEFAULT '' COMMENT '当前纬度', `serve_radius` int(11) NOT NULL DEFAULT '10' COMMENT '服务半径(km)', `level` tinyint(2) NOT NULL DEFAULT '1' COMMENT '等级1-5', `score` decimal(3,2) NOT NULL DEFAULT '5.00' COMMENT '综合评分', `order_count` int(11) NOT NULL DEFAULT '0' COMMENT '累计订单', `accept_rate` decimal(5,2) NOT NULL DEFAULT '100.00' COMMENT '接单率%', `ontime_rate` decimal(5,2) NOT NULL DEFAULT '100.00' COMMENT '准时率%', `work_status` enum('off','on') NOT NULL DEFAULT 'on' COMMENT '接单开关', `verify_status` enum('pending','pass','reject') NOT NULL DEFAULT 'pending' COMMENT '审核状态', `audit_msg` varchar(255) NOT NULL DEFAULT '' COMMENT '审核意见', `money` decimal(10,2) NOT NULL DEFAULT '0.00' COMMENT '可提现余额', `frozen_money` decimal(10,2) NOT NULL DEFAULT '0.00' COMMENT '冻结金额', `createtime` bigint(16) DEFAULT NULL, `updatetime` bigint(16) DEFAULT NULL, PRIMARY KEY (`id`), UNIQUE KEY `user_id` (`user_id`), KEY `verify_status` (`verify_status`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='师傅档案'; -- 5. 师傅技能(可接单类目) CREATE TABLE IF NOT EXISTS `fa_master_skill` ( `id` int(10) unsigned NOT NULL AUTO_INCREMENT, `master_id` int(10) unsigned NOT NULL DEFAULT '0', `cat_id` int(10) unsigned NOT NULL DEFAULT '0', `cert_image` varchar(255) NOT NULL DEFAULT '' COMMENT '技能证书', `status` enum('normal','hidden') NOT NULL DEFAULT 'normal', `createtime` bigint(16) DEFAULT NULL, PRIMARY KEY (`id`), KEY `master_id` (`master_id`), KEY `cat_id` (`cat_id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='师傅技能'; -- 6. 订单主表(全链路核心) -- status: 0待支付 1待接单 2报价中 3已接单 4待上门 5已到达 6服务中 -- 7待验收 8已完成 9已取消 10售后中 CREATE TABLE IF NOT EXISTS `fa_order` ( `id` int(10) unsigned NOT NULL AUTO_INCREMENT, `order_no` varchar(32) NOT NULL DEFAULT '' COMMENT '订单号', `user_id` int(10) unsigned NOT NULL DEFAULT '0' COMMENT '下单用户', `master_id` int(10) unsigned NOT NULL DEFAULT '0' COMMENT '接单师傅', `cat_id` int(10) unsigned NOT NULL DEFAULT '0', `service_id` int(10) unsigned NOT NULL DEFAULT '0', `service_name` varchar(100) NOT NULL DEFAULT '' COMMENT '服务名称(快照)', `service_image` varchar(255) NOT NULL DEFAULT '' COMMENT '服务主图(快照)', `price_type` enum('fixed','quote','range','custom') NOT NULL DEFAULT 'fixed' COMMENT '一口价/报价竞价/区间/用户自主定价', `goods_images` varchar(1000) NOT NULL DEFAULT '' COMMENT '商品图片(json)', `goods_model` varchar(100) NOT NULL DEFAULT '' COMMENT '商品型号', `goods_num` int(11) NOT NULL DEFAULT '1', `floor` int(11) NOT NULL DEFAULT '1' COMMENT '楼层', `has_elevator` tinyint(1) NOT NULL DEFAULT '1' COMMENT '有无电梯', `urgent` tinyint(1) NOT NULL DEFAULT '0' COMMENT '急单标识', `remark` varchar(500) NOT NULL DEFAULT '' COMMENT '备注/施工要求', `contact` varchar(50) NOT NULL DEFAULT '', `mobile` varchar(20) NOT NULL DEFAULT '', `province` varchar(50) NOT NULL DEFAULT '', `city` varchar(50) NOT NULL DEFAULT '', `district` varchar(50) NOT NULL DEFAULT '', `address` varchar(255) NOT NULL DEFAULT '', `lng` varchar(20) NOT NULL DEFAULT '', `lat` varchar(20) NOT NULL DEFAULT '', `appoint_time` bigint(16) DEFAULT NULL COMMENT '预约上门时间', `base_amount` decimal(10,2) NOT NULL DEFAULT '0.00' COMMENT '基础价', `floor_amount` decimal(10,2) NOT NULL DEFAULT '0.00' COMMENT '楼层费', `distance_amount` decimal(10,2) NOT NULL DEFAULT '0.00' COMMENT '距离费', `urgent_amount` decimal(10,2) NOT NULL DEFAULT '0.00' COMMENT '加急费', `discount_amount` decimal(10,2) NOT NULL DEFAULT '0.00' COMMENT '优惠金额', `total_amount` decimal(10,2) NOT NULL DEFAULT '0.00' COMMENT '订单总额', `pay_amount` decimal(10,2) NOT NULL DEFAULT '0.00' COMMENT '实付金额', `status` tinyint(2) NOT NULL DEFAULT '0' COMMENT '状态', `pay_status` tinyint(1) NOT NULL DEFAULT '0' COMMENT '0未付1已付2已退', `pay_type` varchar(20) NOT NULL DEFAULT '' COMMENT 'wxpay/balance/cash', `pay_time` bigint(16) DEFAULT NULL, `transaction_id` varchar(64) NOT NULL DEFAULT '', `coupon_id` int(10) unsigned NOT NULL DEFAULT '0', `accept_time` bigint(16) DEFAULT NULL COMMENT '接单时间', `contact_time` bigint(16) DEFAULT NULL COMMENT '联系客户时间', `arrive_time` bigint(16) DEFAULT NULL, `start_time` bigint(16) DEFAULT NULL, `finish_time` bigint(16) DEFAULT NULL, `verify_time` bigint(16) DEFAULT NULL, `verify_code` varchar(10) NOT NULL DEFAULT '' COMMENT '验收码', `settle_status` tinyint(1) NOT NULL DEFAULT '0', `settle_amount` decimal(10,2) NOT NULL DEFAULT '0.00', `cancel_reason` varchar(255) NOT NULL DEFAULT '', `refund_amount` decimal(10,2) NOT NULL DEFAULT '0.00', `is_review` tinyint(1) NOT NULL DEFAULT '0', `createtime` bigint(16) DEFAULT NULL, `updatetime` bigint(16) DEFAULT NULL, PRIMARY KEY (`id`), UNIQUE KEY `order_no` (`order_no`), KEY `user_id` (`user_id`), KEY `master_id` (`master_id`), KEY `status` (`status`), KEY `cat_id` (`cat_id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='订单'; -- 7. 订单状态流水 CREATE TABLE IF NOT EXISTS `fa_order_log` ( `id` int(10) unsigned NOT NULL AUTO_INCREMENT, `order_id` int(10) unsigned NOT NULL DEFAULT '0', `status` tinyint(2) NOT NULL DEFAULT '0' COMMENT '变更后状态', `remark` varchar(255) NOT NULL DEFAULT '', `operator_type` enum('user','master','admin','system') NOT NULL DEFAULT 'system', `operator_id` int(10) unsigned NOT NULL DEFAULT '0', `createtime` bigint(16) DEFAULT NULL, PRIMARY KEY (`id`), KEY `order_id` (`order_id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='订单状态流水'; -- 8. 现场取证(拍照/录像/水印/损坏申报) CREATE TABLE IF NOT EXISTS `fa_order_media` ( `id` int(10) unsigned NOT NULL AUTO_INCREMENT, `order_id` int(10) unsigned NOT NULL DEFAULT '0', `master_id` int(10) unsigned NOT NULL DEFAULT '0', `stage` enum('arrive','work','finish','damage') NOT NULL DEFAULT 'work' COMMENT '节点', `type` enum('image','video') NOT NULL DEFAULT 'image', `url` varchar(500) NOT NULL DEFAULT '', `watermark` varchar(255) NOT NULL DEFAULT '' COMMENT '水印(时间/地址)', `remark` varchar(255) NOT NULL DEFAULT '' COMMENT '损坏申报说明', `createtime` bigint(16) DEFAULT NULL, PRIMARY KEY (`id`), KEY `order_id` (`order_id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='现场取证'; -- 9. 报价竞标 CREATE TABLE IF NOT EXISTS `fa_order_quote` ( `id` int(10) unsigned NOT NULL AUTO_INCREMENT, `order_id` int(10) unsigned NOT NULL DEFAULT '0', `master_id` int(10) unsigned NOT NULL DEFAULT '0', `amount` decimal(10,2) NOT NULL DEFAULT '0.00' COMMENT '报价金额', `description` varchar(500) NOT NULL DEFAULT '' COMMENT '服务说明', `valid_hours` int(11) NOT NULL DEFAULT '24' COMMENT '有效期(小时)', `expire_time` bigint(16) DEFAULT NULL, `status` enum('wait','accept','reject','expired') NOT NULL DEFAULT 'wait', `createtime` bigint(16) DEFAULT NULL, PRIMARY KEY (`id`), KEY `order_id` (`order_id`), UNIQUE KEY `order_master` (`order_id`,`master_id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='报价竞标'; -- 10. 评价 CREATE TABLE IF NOT EXISTS `fa_review` ( `id` int(10) unsigned NOT NULL AUTO_INCREMENT, `order_id` int(10) unsigned NOT NULL DEFAULT '0', `user_id` int(10) unsigned NOT NULL DEFAULT '0', `master_id` int(10) unsigned NOT NULL DEFAULT '0', `score` tinyint(1) NOT NULL DEFAULT '5' COMMENT '星级1-5', `tags` varchar(255) NOT NULL DEFAULT '' COMMENT '标签(json)', `content` varchar(500) NOT NULL DEFAULT '', `images` varchar(1000) NOT NULL DEFAULT '', `is_anonymous` tinyint(1) NOT NULL DEFAULT '0', `reply` varchar(500) NOT NULL DEFAULT '' COMMENT '师傅回复', `status` enum('normal','hidden') NOT NULL DEFAULT 'normal', `createtime` bigint(16) DEFAULT NULL, PRIMARY KEY (`id`), KEY `order_id` (`order_id`), KEY `master_id` (`master_id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='评价'; -- 11. 优惠券模板 / 用户持有券 CREATE TABLE IF NOT EXISTS `fa_coupon` ( `id` int(10) unsigned NOT NULL AUTO_INCREMENT, `name` varchar(100) NOT NULL DEFAULT '', `type` enum('cash','discount') NOT NULL DEFAULT 'cash' COMMENT '满减/折扣', `amount` decimal(10,2) NOT NULL DEFAULT '0.00' COMMENT '满减金额', `discount` decimal(4,2) NOT NULL DEFAULT '1.00' COMMENT '折扣(0.9=9折)', `min_amount` decimal(10,2) NOT NULL DEFAULT '0.00' COMMENT '使用门槛', `total` int(11) NOT NULL DEFAULT '0' COMMENT '发行量(0不限)', `received` int(11) NOT NULL DEFAULT '0' COMMENT '已领取', `start_time` bigint(16) DEFAULT NULL, `end_time` bigint(16) DEFAULT NULL, `status` enum('normal','hidden') NOT NULL DEFAULT 'normal', `createtime` bigint(16) DEFAULT NULL, PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='优惠券模板'; CREATE TABLE IF NOT EXISTS `fa_user_coupon` ( `id` int(10) unsigned NOT NULL AUTO_INCREMENT, `user_id` int(10) unsigned NOT NULL DEFAULT '0', `coupon_id` int(10) unsigned NOT NULL DEFAULT '0', `order_id` int(10) unsigned NOT NULL DEFAULT '0' COMMENT '使用的订单', `status` enum('unused','used','expired') NOT NULL DEFAULT 'unused', `use_time` bigint(16) DEFAULT NULL, `createtime` bigint(16) DEFAULT NULL, PRIMARY KEY (`id`), KEY `user_id` (`user_id`), KEY `status` (`status`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='用户优惠券'; -- 12. 资金流水 CREATE TABLE IF NOT EXISTS `fa_wallet_log` ( `id` int(10) unsigned NOT NULL AUTO_INCREMENT, `user_type` enum('user','master') NOT NULL DEFAULT 'user', `user_id` int(10) unsigned NOT NULL DEFAULT '0', `type` enum('recharge','consume','income','withdraw','refund','settle') NOT NULL DEFAULT 'consume', `amount` decimal(10,2) NOT NULL DEFAULT '0.00' COMMENT '正入账/负出账', `balance` decimal(10,2) NOT NULL DEFAULT '0.00' COMMENT '变动后余额', `order_id` int(10) unsigned NOT NULL DEFAULT '0', `remark` varchar(255) NOT NULL DEFAULT '', `createtime` bigint(16) DEFAULT NULL, PRIMARY KEY (`id`), KEY `user` (`user_type`,`user_id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='资金流水'; -- 13. 师傅提现 CREATE TABLE IF NOT EXISTS `fa_withdraw` ( `id` int(10) unsigned NOT NULL AUTO_INCREMENT, `master_id` int(10) unsigned NOT NULL DEFAULT '0', `amount` decimal(10,2) NOT NULL DEFAULT '0.00' COMMENT '申请金额', `fee` decimal(10,2) NOT NULL DEFAULT '0.00' COMMENT '手续费', `arrive_amount` decimal(10,2) NOT NULL DEFAULT '0.00' COMMENT '到账金额', `channel` enum('wechat','bank') NOT NULL DEFAULT 'wechat', `account` varchar(100) NOT NULL DEFAULT '' COMMENT '收款账号', `status` enum('wait','pass','reject','done') NOT NULL DEFAULT 'wait', `audit_msg` varchar(255) NOT NULL DEFAULT '', `createtime` bigint(16) DEFAULT NULL, `updatetime` bigint(16) DEFAULT NULL, PRIMARY KEY (`id`), KEY `master_id` (`master_id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='提现申请'; -- 14. 结算单 CREATE TABLE IF NOT EXISTS `fa_settle` ( `id` int(10) unsigned NOT NULL AUTO_INCREMENT, `order_id` int(10) unsigned NOT NULL DEFAULT '0', `master_id` int(10) unsigned NOT NULL DEFAULT '0', `order_amount` decimal(10,2) NOT NULL DEFAULT '0.00' COMMENT '订单实付', `commission_rate` decimal(5,2) NOT NULL DEFAULT '10.00' COMMENT '平台抽成%', `commission` decimal(10,2) NOT NULL DEFAULT '0.00' COMMENT '抽成金额', `settle_amount` decimal(10,2) NOT NULL DEFAULT '0.00' COMMENT '师傅应得', `status` enum('wait','settled','offline') NOT NULL DEFAULT 'wait', `settle_time` bigint(16) DEFAULT NULL, `createtime` bigint(16) DEFAULT NULL, PRIMARY KEY (`id`), UNIQUE KEY `order_id` (`order_id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='结算单'; -- 15. 消息中心 CREATE TABLE IF NOT EXISTS `fa_message` ( `id` int(10) unsigned NOT NULL AUTO_INCREMENT, `receive_type` enum('user','master') NOT NULL DEFAULT 'user', `receive_id` int(10) unsigned NOT NULL DEFAULT '0', `type` enum('order','system','audit','remind') NOT NULL DEFAULT 'system', `title` varchar(100) NOT NULL DEFAULT '', `content` varchar(500) NOT NULL DEFAULT '', `order_id` int(10) unsigned NOT NULL DEFAULT '0', `is_read` tinyint(1) NOT NULL DEFAULT '0', `createtime` bigint(16) DEFAULT NULL, PRIMARY KEY (`id`), KEY `receive` (`receive_type`,`receive_id`,`is_read`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='消息中心'; SET FOREIGN_KEY_CHECKS = 1; -- ============================================================================ -- 回滚(仅在彻底撤销时执行,会丢失业务数据) -- DROP TABLE IF EXISTS `fa_message`,`fa_settle`,`fa_withdraw`,`fa_wallet_log`, -- `fa_user_coupon`,`fa_coupon`,`fa_review`,`fa_order_quote`,`fa_order_media`, -- `fa_order_log`,`fa_order`,`fa_master_skill`,`fa_master`,`fa_address`, -- `fa_service`,`fa_service_cat`; -- ============================================================================