diff --git a/document/sql/mysql.sql b/document/sql/mysql.sql index 20986c36..23e5e52f 100644 --- a/document/sql/mysql.sql +++ b/document/sql/mysql.sql @@ -1,24 +1,91 @@ -create table goods -( - id int unsigned primary key auto_increment comment’商品id’, - category_id int unsigned not null default 0 comment’分类id’, - spu_id int unsigned not null default 0 comment’SPU id’, - sn varchar(20) not null default ‘’ comment’编号’, - name varchar(120) not null default ‘‘comment’名称’, - keyword varchar(255) not null default ‘’ comment’关键字’, - picture varchar(255) not null default ’’ comment’图片’, - tips varchar(255) not null default ‘’ comment’提示’, - description varchar(255) not null default ‘’ comment’描述’, - content text not null comment’详情’, - price decimal(10, 2) unsigned not null default 0 comment ‘价格’, - stock int unsigned not null default 0 comment ‘库存’, - score decimal(3, 2) unsigned not null default 0 comment’评分’, - is_on_sale tinyint unsigned not null default 0 comment’是否上架’, - is_del tinyint unsigned not null default 0 comment’是否删除’, - is_free_shipping tinyint unsigned not null default 0 comment’是否包邮’, - sell_count int unsigned not null default 0 comment’销量计数’, - comment int unsigned not null default 0 comment’评论计数’, - on_sale_time datetime default null comment’上架时间’, - create_time datetime not null default current_timestamp comment’创建时间’, - update_time datetime default null comment’更新时间’ -); +CREATE TABLE `product` ( + `id` int(11) NOT NULL AUTO_INCREMENT COMMENT '商品ID', + `name` varchar(255) NOT NULL COMMENT '商品名称', + `description` varchar(1000) NOT NULL COMMENT '商品描述', + `price` decimal(10,2) NOT NULL COMMENT '商品单价', + `category_id` int(11) NOT NULL COMMENT '所属类别ID', + `brand_id` int(11) DEFAULT NULL COMMENT '品牌ID', + `origin` varchar(255) DEFAULT NULL COMMENT '商品产地', + `weight` decimal(10,2) DEFAULT NULL COMMENT '商品重量(kg)', + `length` decimal(10,2) DEFAULT NULL COMMENT '商品长度(cm)', + `width` decimal(10,2) DEFAULT NULL COMMENT '商品宽度(cm)', + `height` decimal(10,2) DEFAULT NULL COMMENT '商品高度(cm)', + `thumbnail` varchar(255) DEFAULT NULL COMMENT '商品缩略图URL', + `image` varchar(1000) DEFAULT NULL COMMENT '商品图片URL', + `is_sale` tinyint(1) NOT NULL DEFAULT '1' COMMENT '是否上架,0:下架,1:上架', + `stock` int(11) NOT NULL COMMENT '商品库存', + `created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间', + `updated_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间', + PRIMARY KEY (`id`), + KEY `category_id` (`category_id`), + KEY `brand_id` (`brand_id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='商品表'; + +INSERT INTO product (name, description, price, category_id, brand_id, origin, weight, length, width, height, thumbnail, image, is_sale, stock, created_at, updated_at) +SELECT + CONCAT('商品', t1.n), + CONCAT('这是商品', t1.n, '的描述'), + ROUND(RAND() * 1000, 2), + FLOOR(RAND() * 10) + 1, + IF(RAND() < 0.5, NULL, FLOOR(RAND() * 10) + 1), + CONCAT('产地', t1.n), + ROUND(RAND() * 10, 2), + ROUND(RAND() * 100, 2), + ROUND(RAND() * 100, 2), + ROUND(RAND() * 100, 2), + CONCAT('http://example.com/thumbnail_', t1.n, '.jpg'), + CONCAT('http://example.com/image_', t1.n, '.jpg'), + IF(RAND() < 0.5, 0, 1), + FLOOR(RAND() * 1000), + NOW() - INTERVAL FLOOR(RAND() * 365) DAY, + NOW() - INTERVAL FLOOR(RAND() * 365) DAY +FROM + (SELECT @rownum:=0) t0, + (SELECT @rownum:=@rownum+1 AS n FROM information_schema.COLUMNS LIMIT 10000) t1 ; + + +CREATE TABLE `order` ( + `id` int(11) NOT NULL AUTO_INCREMENT COMMENT '订单ID', + `user_id` int(11) NOT NULL COMMENT '用户ID', + `total_price` decimal(10,2) NOT NULL COMMENT '订单总价', + `created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间', + `updated_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间', + PRIMARY KEY (`id`), + KEY `user_id` (`user_id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='订单表'; + +INSERT INTO `order` (user_id, total_price, created_at, updated_at) +SELECT + FLOOR(RAND() * 1000) + 1, + ROUND(RAND() * 10000, 2), + NOW() - INTERVAL FLOOR(RAND() * 365) DAY, + NOW() - INTERVAL FLOOR(RAND() * 365) DAY +FROM + (SELECT @rownum:=0) t0, + (SELECT @rownum:=@rownum+1 AS n FROM information_schema.COLUMNS LIMIT 10000) t1 ; + + +CREATE TABLE `order_item` ( + `id` int(11) NOT NULL AUTO_INCREMENT COMMENT '订单明细ID', + `order_id` int(11) NOT NULL COMMENT '订单ID', + `product_id` int(11) NOT NULL COMMENT '商品ID', + `quantity` int(11) NOT NULL COMMENT '购买数量', + `price` decimal(10,2) NOT NULL COMMENT '商品单价', + `created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间', + `updated_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间', + PRIMARY KEY (`id`), + KEY `order_id` (`order_id`), + KEY `product_id` (`product_id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='订单明细表'; + +INSERT INTO order_item (order_id, product_id, quantity, price, created_at, updated_at) +SELECT + FLOOR(RAND() * 10000) + 1, + FLOOR(RAND() * 1000) + 1, + FLOOR(RAND() * 10) + 1, + ROUND(RAND() * 1000, 2), + NOW() - INTERVAL FLOOR(RAND() * 365) DAY, + NOW() - INTERVAL FLOOR(RAND() * 365) DAY +FROM + (SELECT @rownum:=0) t0, + (SELECT @rownum:=@rownum+1 AS n FROM information_schema.COLUMNS LIMIT 10000) t1 ; \ No newline at end of file