文章目录
一、基础项目搭建
gitee 地址 : https://gitee.com/wlby/seckill
克隆项目之后导入SQL文件
主要有五张表
- t_goods 保存了所有商品列表
- t_order 保存订单信息
- t_seckill_goods 将秒杀的商品列为新的一张表,因为商品会有各种优惠活动,如果在商品表新建字段不好维护,或者秒杀渠道和不秒杀渠道可能同时开启,所以新建一张有利于维护秒杀商品
- t_seckill_order 存储秒杀订单
- t_user 用户表
并且插入一些数据用于测试
/*
Navicat MySQL Data Transfer
Source Server : localhost
Source Server Version : 50536
Source Host : localhost:3306
Source Database : seckill
Target Server Type : MYSQL
Target Server Version : 50536
File Encoding : 65001
Date: 2021-05-31 17:02:53
*/
SET FOREIGN_KEY_CHECKS=0;
-- ----------------------------
-- Table structure for `t_goods`
-- ----------------------------
DROP TABLE IF EXISTS `t_goods`;
CREATE TABLE `t_goods` (
`id` bigint(11) NOT NULL AUTO_INCREMENT COMMENT '商品ID',
`goods_name` varchar(255) DEFAULT NULL COMMENT '商品名称',
`goods_title` varchar(255) DEFAULT NULL COMMENT '商品标题',
`goods_img` varchar(255) DEFAULT NULL COMMENT '商品图片',
`goods_detail` varchar(255) DEFAULT NULL COMMENT '商品详情',
`goods_price` decimal(10,2) DEFAULT NULL COMMENT '商品价格',
`goods_stock` int(11) DEFAULT NULL COMMENT '商品库存',
PRIMARY KEY (`id`) USING BTREE
) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf8mb4 ROW_FORMAT=DYNAMIC;
-- ----------------------------
-- Records of t_goods
-- ----------------------------
INSERT INTO `t_goods` VALUES ('1', 'IPHONE 12 64GB', 'IPHONE 12 64GB', '/img/iphone12.png', 'IPHONE12 销量秒杀', '6299.00', '100');
INSERT INTO `t_goods` VALUES ('2', 'IPHONE12 PRO 128GB', 'IPHONE12 PRO 128GB', '/img/iphone12pro.png', 'IPHONE12PRO限量,限时秒杀,先到先得', '9299.00', '100');
-- ----------------------------
-- Table structure for `t_order`
-- ----------------------------
DROP TABLE IF EXISTS `t_order`;
CREATE TABLE `t_order` (
`id` bigint(11) NOT NULL AUTO_INCREMENT COMMENT '订单ID',
`user_id` bigint(11) DEFAULT NULL COMMENT '用户ID',
`goods_id` bigint(11) DEFAULT NULL COMMENT '商品ID',
`deliver_addr_id` bigint(11) DEFAULT NULL COMMENT '收获地址ID',
`goods_name` varchar(255) DEFAULT NULL COMMENT '商品名称',
`goods_count` int(11) DEFAULT NULL COMMENT '商品数量',
`goods_price` decimal(10,2) DEFAULT NULL COMMENT '商品单价',
`order_channel` int(11) DEFAULT NULL COMMENT '设备信息',
`status` int(11) DEFAULT NULL COMMENT '订单状态',
`create_date` datetime DEFAULT NULL COMMENT '订单创建时间',
`pay_date` datetime DEFAULT NULL COMMENT '支付时间',
PRIMARY KEY (`id`) USING BTREE
) ENGINE=InnoDB AUTO_INCREMENT=1548 DEFAULT CHARSET=utf8mb4 ROW_FORMAT=DYNAMIC;
-- ----------------------------
-- Records of t_order
-- ----------------------------
-- ----------------------------
-- Table structure for `t_seckill_goods`
-- ----------------------------
DROP TABLE IF EXISTS `t_seckill_goods`;
CREATE TABLE `t_seckill_goods` (
`id` bigint(11) NOT NULL AUTO_INCREMENT COMMENT '秒杀商品ID',
`goods_id` bigint(11) DEFAULT NULL COMMENT '商品ID',
`seckill_price` decimal(10,2) DEFAULT NULL COMMENT '秒杀价',
`stock_count` int(11) DEFAULT NULL COMMENT '库存数量',
`start_date` datetime DEFAULT NULL COMMENT '秒杀开始时间',
`end_date` datetime DEFAULT NULL COMMENT '秒杀结束时间',
PRIMARY KEY (`id`) USING BTREE
) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf8mb4 ROW_FORMAT=DYNAMIC;
-- ----------------------------
-- Records of t_seckill_goods
-- ----------------------------
INSERT INTO `t_seckill_goods` VALUES ('1', '1', '629.00', '10', '2021-05-25 22:47:47', '2021-06-06 21:29:57');
INSERT INTO `t_seckill_goods` VALUES ('2', '2', '929.00', '10', '2021-05-25 21:30:14', '2021-06-05 21:30:17');
-- ----------------------------
-- Table structure for `t_seckill_order`
-- ----------------------------
DROP TABLE IF EXISTS `t_seckill_order`;
CREATE TABLE `t_seckill_order` (
`id` bigint(11) NOT NULL AUTO_INCREMENT COMMENT '订单ID',
`user_id` bigint(11) DEFAULT NULL COMMENT '用户ID',
`order_id` bigint(11) DEFAULT NULL COMMENT '订单ID',
`goods_id` bigint(11) DEFAULT NULL COMMENT '商品ID',
PRIMARY KEY (`id`) USING BTREE,
UNIQUE KEY `seckill_uid_gid` (`user_id`,`goods_id`)