Files
x-server-mobile/backend/database/migrations/015_create_used_car_tables.sql
T
2026-03-05 13:15:05 +08:00

57 lines
3.2 KiB
SQL
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
-- 二手车相关数据表
-- 创建时间: 2026-03-05
-- 二手车主表
CREATE TABLE IF NOT EXISTS `used_car` (
`id` int(11) unsigned NOT NULL AUTO_INCREMENT,
`code` varchar(100) NOT NULL DEFAULT '' COMMENT '唯一编号(用户拼音首字母+用户ID+日期+序号)',
`user_id` int(11) unsigned NOT NULL DEFAULT 0 COMMENT '用户ID',
`role` tinyint(1) NOT NULL DEFAULT 1 COMMENT '用户角色:1管理员 2普通用户',
`product_name` varchar(255) NOT NULL DEFAULT '' COMMENT '产品名称/车辆标题',
`vin` varchar(50) DEFAULT NULL COMMENT '车辆识别码',
`price` int(11) unsigned NOT NULL DEFAULT 0 COMMENT '价格(单位:分)',
`source_place` varchar(100) DEFAULT NULL COMMENT '车源地',
`plate_place` varchar(100) DEFAULT NULL COMMENT '上牌地点',
`plate_time` varchar(50) DEFAULT NULL COMMENT '上牌时间',
`displacement` varchar(50) DEFAULT NULL COMMENT '排量',
`mileage` int(11) unsigned NOT NULL DEFAULT 0 COMMENT '里程(单位:公里)',
`power` varchar(50) DEFAULT NULL COMMENT '马力',
`body_color` varchar(50) DEFAULT NULL COMMENT '车身颜色',
`images` text DEFAULT NULL COMMENT '图片(逗号分隔的OSS路径)',
`condition_desc` text DEFAULT NULL COMMENT '车况介绍',
`attachment` text DEFAULT NULL COMMENT '附件(JSON格式:[{name:, src:}])',
`pdf_src` varchar(255) DEFAULT NULL COMMENT 'PDF文件路径',
`source_url` text DEFAULT NULL COMMENT '源URL(抓取来源)',
`crawl_title` varchar(255) DEFAULT NULL COMMENT '抓取标题',
`crawl_brand` varchar(100) DEFAULT NULL COMMENT '抓取品牌',
`crawl_brand_id` int(11) unsigned NOT NULL DEFAULT 0 COMMENT '抓取品牌ID',
`crawl_series` varchar(100) DEFAULT NULL COMMENT '抓取车系',
`crawl_series_id` int(11) unsigned NOT NULL DEFAULT 0 COMMENT '抓取车系ID',
`crawl_year` varchar(10) DEFAULT NULL COMMENT '抓取年份',
`crawl_msrp` int(11) unsigned NOT NULL DEFAULT 0 COMMENT '抓取指导价(单位:分)',
`crawl_car_id` int(11) unsigned NOT NULL DEFAULT 0 COMMENT '抓取车型ID',
`status` tinyint(1) NOT NULL DEFAULT 1 COMMENT '状态:1正常 2归档 3删除',
`sort` int(11) NOT NULL DEFAULT 0 COMMENT '排序',
`created_at` timestamp NULL DEFAULT NULL,
`updated_at` timestamp NULL DEFAULT NULL,
PRIMARY KEY (`id`),
KEY `idx_user_id` (`user_id`),
KEY `idx_code` (`code`),
KEY `idx_status` (`status`),
KEY `idx_created_at` (`created_at`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='二手车信息表';
-- 二手车PDF生成日志表
CREATE TABLE IF NOT EXISTS `used_car_pdf_log` (
`id` int(11) unsigned NOT NULL AUTO_INCREMENT,
`user_id` int(11) unsigned NOT NULL DEFAULT 0 COMMENT '用户ID',
`used_car_id` int(11) unsigned NOT NULL DEFAULT 0 COMMENT '二手车ID',
`price_snapshot` int(11) unsigned NOT NULL DEFAULT 0 COMMENT '价格快照(单位:分)',
`pdf_path` varchar(255) NOT NULL DEFAULT '' COMMENT 'PDF路径',
`created_at` timestamp NULL DEFAULT NULL,
`updated_at` timestamp NULL DEFAULT NULL,
PRIMARY KEY (`id`),
KEY `idx_user_id` (`user_id`),
KEY `idx_used_car_id` (`used_car_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='二手车PDF生成日志表';