Files
FlashSaleSystem/sql/flash_sale_db_2025-07-04_231121.sql
2025-07-09 17:56:02 +08:00

377 lines
19 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.
-- MySQL dump 10.13 Distrib 5.7.24, for osx11.1 (x86_64)
--
-- Host: 127.0.0.1 Database: flash_sale_db
-- ------------------------------------------------------
-- Server version 8.0.36
/*!40101 SET @OLD_CHARACTER_SET_CLIENT = @@CHARACTER_SET_CLIENT */;
/*!40101 SET @OLD_CHARACTER_SET_RESULTS = @@CHARACTER_SET_RESULTS */;
/*!40101 SET @OLD_COLLATION_CONNECTION = @@COLLATION_CONNECTION */;
/*!40101 SET NAMES utf8 */;
/*!40103 SET @OLD_TIME_ZONE = @@TIME_ZONE */;
/*!40103 SET TIME_ZONE = '+00:00' */;
/*!40014 SET @OLD_UNIQUE_CHECKS = @@UNIQUE_CHECKS, UNIQUE_CHECKS = 0 */;
/*!40014 SET @OLD_FOREIGN_KEY_CHECKS = @@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS = 0 */;
/*!40101 SET @OLD_SQL_MODE = @@SQL_MODE, SQL_MODE = 'NO_AUTO_VALUE_ON_ZERO' */;
/*!40111 SET @OLD_SQL_NOTES = @@SQL_NOTES, SQL_NOTES = 0 */;
--
-- Temporary table structure for view `active_flash_sales`
--
DROP TABLE IF EXISTS `active_flash_sales`;
/*!50001 DROP VIEW IF EXISTS `active_flash_sales`*/;
SET @saved_cs_client = @@character_set_client;
SET character_set_client = utf8;
/*!50001 CREATE VIEW `active_flash_sales` AS
SELECT 1 AS `id`,
1 AS `product_id`,
1 AS `product_name`,
1 AS `original_price`,
1 AS `flash_price`,
1 AS `flash_stock`,
1 AS `start_time`,
1 AS `end_time`,
1 AS `status`,
1 AS `image_url`
*/;
SET character_set_client = @saved_cs_client;
--
-- Table structure for table `flash_sales`
--
DROP TABLE IF EXISTS `flash_sales`;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `flash_sales`
(
`id` bigint NOT NULL AUTO_INCREMENT COMMENT '秒杀活动ID',
`product_id` bigint NOT NULL COMMENT '商品ID',
`flash_price` decimal(10, 2) NOT NULL COMMENT '秒杀价格',
`flash_stock` int NOT NULL COMMENT '秒杀库存',
`start_time` timestamp NOT NULL COMMENT '开始时间',
`end_time` timestamp NOT NULL COMMENT '结束时间',
`status` tinyint DEFAULT '1' COMMENT '状态1-未开始2-进行中3-已结束',
`created_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
`updated_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
PRIMARY KEY (`id`),
KEY `idx_product_id` (`product_id`),
KEY `idx_start_time` (`start_time`),
KEY `idx_end_time` (`end_time`),
KEY `idx_status` (`status`),
KEY `idx_created_at` (`created_at`),
CONSTRAINT `flash_sales_ibfk_1` FOREIGN KEY (`product_id`) REFERENCES `products` (`id`) ON DELETE CASCADE
) ENGINE = InnoDB
AUTO_INCREMENT = 10
DEFAULT CHARSET = utf8mb4
COLLATE = utf8mb4_unicode_ci COMMENT ='秒杀活动表';
/*!40101 SET character_set_client = @saved_cs_client */;
--
-- Dumping data for table `flash_sales`
--
/*!40000 ALTER TABLE `flash_sales`
DISABLE KEYS */;
INSERT INTO `flash_sales`
VALUES (1, 1, 7999.00, 19, '2025-06-29 02:06:16', '2025-07-12 07:07:00', 2, '2025-06-29 02:07:16',
'2025-07-04 14:02:39'),
(2, 4, 1299.00, 49, '2025-06-29 02:06:16', '2025-07-12 07:07:00', 2, '2025-06-29 02:07:16',
'2025-07-03 07:37:53'),
(3, 6, 1999.00, 15, '2025-06-29 02:06:16', '2025-07-12 07:07:00', 2, '2025-06-29 02:07:16',
'2025-07-03 03:23:51'),
(4, 2, 19999.00, 10, '2025-06-29 02:06:16', '2025-06-29 06:07:16', 2, '2025-06-29 02:07:16',
'2025-07-02 08:39:07'),
(5, 9, 899.00, 29, '2025-06-29 02:06:16', '2025-07-12 07:07:00', 2, '2025-06-29 02:07:16',
'2025-07-03 03:23:51'),
(7, 7, 3999.00, 10, '2025-06-29 02:06:16', '2025-07-12 07:07:00', 2, '2025-06-29 02:07:16',
'2025-07-03 03:23:51'),
(8, 11, 59.00, 100, '2025-06-29 02:06:16', '2025-07-12 07:07:00', 2, '2025-06-29 02:07:16',
'2025-07-03 03:23:51'),
(9, 12, 1.00, 1, '2025-07-05 22:44:00', '2025-07-12 22:44:00', 1, '2025-07-04 22:44:57', '2025-07-04 14:44:56');
/*!40000 ALTER TABLE `flash_sales`
ENABLE KEYS */;
--
-- Temporary table structure for view `order_statistics`
--
DROP TABLE IF EXISTS `order_statistics`;
/*!50001 DROP VIEW IF EXISTS `order_statistics`*/;
SET @saved_cs_client = @@character_set_client;
SET character_set_client = utf8;
/*!50001 CREATE VIEW `order_statistics` AS
SELECT 1 AS `order_date`,
1 AS `total_orders`,
1 AS `pending_orders`,
1 AS `paid_orders`,
1 AS `completed_orders`,
1 AS `flash_sale_orders`,
1 AS `total_amount`
*/;
SET character_set_client = @saved_cs_client;
--
-- Table structure for table `orders`
--
DROP TABLE IF EXISTS `orders`;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `orders`
(
`id` bigint NOT NULL AUTO_INCREMENT COMMENT '订单ID',
`user_id` bigint NOT NULL COMMENT '用户ID',
`product_id` bigint NOT NULL COMMENT '商品ID',
`quantity` int NOT NULL DEFAULT '1' COMMENT '购买数量',
`total_price` decimal(10, 2) NOT NULL COMMENT '总价',
`status` tinyint DEFAULT '1' COMMENT '状态1-待支付2-已支付3-已发货4-已完成5-已取消',
`order_type` tinyint DEFAULT '1' COMMENT '订单类型1-普通订单2-秒杀订单',
`created_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
`updated_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
PRIMARY KEY (`id`),
KEY `idx_user_id` (`user_id`),
KEY `idx_product_id` (`product_id`),
KEY `idx_status` (`status`),
KEY `idx_order_type` (`order_type`),
KEY `idx_created_at` (`created_at`),
KEY `idx_user_product` (`user_id`, `product_id`),
CONSTRAINT `orders_ibfk_1` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON DELETE CASCADE,
CONSTRAINT `orders_ibfk_2` FOREIGN KEY (`product_id`) REFERENCES `products` (`id`) ON DELETE CASCADE
) ENGINE = InnoDB
AUTO_INCREMENT = 20
DEFAULT CHARSET = utf8mb4
COLLATE = utf8mb4_unicode_ci COMMENT ='订单表';
/*!40101 SET character_set_client = @saved_cs_client */;
--
-- Dumping data for table `orders`
--
/*!40000 ALTER TABLE `orders`
DISABLE KEYS */;
INSERT INTO `orders`
VALUES (1, 1, 11, 1, 89.00, 4, 1, '2025-06-27 02:07:16', '2025-06-28 02:07:16'),
(2, 1, 12, 1, 79.00, 2, 1, '2025-06-28 02:07:16', '2025-06-28 02:07:16'),
(3, 2, 14, 1, 168.00, 3, 1, '2025-06-28 23:07:16', '2025-06-29 00:07:16'),
(4, 2, 7, 1, 3999.00, 1, 2, '2025-06-29 01:07:16', '2025-06-29 01:07:16'),
(6, 5, 10, 1, 1599.00, 4, 1, '2025-06-28 14:07:16', '2025-06-28 16:07:16'),
(7, 6, 8, 1, 2599.00, 3, 1, '2025-06-28 02:07:16', '2025-06-28 06:07:16'),
(8, 11, 5, 1, 3199.00, 2, 1, '2025-06-27 02:07:16', '2025-07-02 08:57:17'),
(10, 11, 9, 1, 1299.00, 2, 1, '2025-07-03 00:11:39', '2025-07-03 00:46:10'),
(11, 11, 14, 1, 168.00, 2, 1, '2025-07-03 00:18:55', '2025-07-03 00:39:56'),
(12, 11, 13, 1, 2680.00, 1, 1, '2025-07-03 08:48:38', '2025-07-03 08:48:38'),
(13, 11, 13, 1, 2680.00, 1, 1, '2025-07-03 08:56:50', '2025-07-03 08:56:50'),
(14, 11, 14, 1, 168.00, 1, 1, '2025-07-03 08:57:46', '2025-07-03 08:57:46'),
(15, 11, 14, 1, 168.00, 2, 1, '2025-07-03 11:08:56', '2025-07-03 11:09:06'),
(16, 11, 9, 1, 899.00, 2, 2, '2025-07-03 11:23:51', '2025-07-03 11:24:07'),
(17, 11, 4, 1, 1299.00, 1, 2, '2025-07-03 15:37:53', '2025-07-03 15:37:53'),
(18, 3, 1, 1, 7999.00, 2, 2, '2025-07-04 22:02:40', '2025-07-04 22:03:18'),
(19, 3, 14, 1, 168.00, 2, 1, '2025-07-04 22:03:38', '2025-07-04 22:03:46');
/*!40000 ALTER TABLE `orders`
ENABLE KEYS */;
--
-- Table structure for table `products`
--
DROP TABLE IF EXISTS `products`;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `products`
(
`id` bigint NOT NULL AUTO_INCREMENT COMMENT '商品ID',
`name` varchar(200) COLLATE utf8mb4_unicode_ci NOT NULL COMMENT '商品名称',
`description` text COLLATE utf8mb4_unicode_ci COMMENT '商品描述',
`price` decimal(10, 2) NOT NULL COMMENT '商品价格',
`stock` int NOT NULL DEFAULT '0' COMMENT '库存数量',
`image_url` varchar(500) COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT '商品图片URL',
`status` tinyint DEFAULT '1' COMMENT '状态1-上架0-下架',
`created_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
`updated_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
PRIMARY KEY (`id`),
KEY `idx_name` (`name`),
KEY `idx_price` (`price`),
KEY `idx_stock` (`stock`),
KEY `idx_status` (`status`),
KEY `idx_created_at` (`created_at`)
) ENGINE = InnoDB
AUTO_INCREMENT = 17
DEFAULT CHARSET = utf8mb4
COLLATE = utf8mb4_unicode_ci COMMENT ='商品表';
/*!40101 SET character_set_client = @saved_cs_client */;
--
-- Dumping data for table `products`
--
/*!40000 ALTER TABLE `products`
DISABLE KEYS */;
INSERT INTO `products`
VALUES (1, 'iPhone 15 Pro Max', '苹果最新旗舰手机A17 Pro芯片钛金属设计', 9999.00, 100, '/images/iphone15.jpg', 1,
'2025-06-29 02:07:16', '2025-06-29 02:07:16'),
(2, 'MacBook Pro 16英寸', 'M3 Max芯片36GB内存1TB存储', 25999.00, 50, '/images/macbook.jpg', 1,
'2025-06-29 02:07:16', '2025-06-29 02:07:16'),
(3, 'iPad Air', '10.9英寸液晶显示屏M1芯片', 4399.00, 80, '/images/ipad.jpg', 1, '2025-06-29 02:07:16',
'2025-06-29 02:07:16'),
(4, 'AirPods Pro 2', '主动降噪无线耳机,空间音频', 1899.00, 200, '/images/airpods.jpg', 1, '2025-06-29 02:07:16',
'2025-06-29 02:07:16'),
(5, 'Apple Watch Series 9', '健康监测GPS+蜂窝网络', 3199.00, 150, '/images/watch.jpg', 1, '2025-06-29 02:07:16',
'2025-06-29 02:07:16'),
(6, '小米电视 65英寸', '4K超高清120Hz刷新率', 2999.00, 60, '/images/tv.jpg', 1, '2025-06-29 02:07:16',
'2025-06-29 02:07:16'),
(7, '戴森吸尘器 V15', '激光显微尘,强劲吸力', 4690.00, 40, '/images/dyson.jpg', 1, '2025-06-29 02:07:16',
'2025-06-29 02:07:16'),
(8, '美的空调 1.5匹', '变频节能,静音运行', 2599.00, 80, '/images/airconditioner.jpg', 1, '2025-06-29 02:07:16',
'2025-06-29 02:07:16'),
(9, 'Nike Air Jordan 1', '经典篮球鞋限量版配色1', 1299.00, 119, '/images/jordan.jpg', 1, '2025-06-29 02:07:16',
'2025-07-02 16:11:39'),
(10, 'Adidas Ultra Boost', '缓震跑鞋Boost中底', 1599.00, 100, '/images/ultraboost.jpg', 1,
'2025-06-29 02:07:16', '2025-06-29 02:07:16'),
(11, '深入理解Java虚拟机', 'JVM原理与实践第3版', 89.00, 500, '/images/jvm-book.jpg', 1, '2025-06-29 02:07:16',
'2025-06-29 02:07:16'),
(12, 'Redis设计与实现', 'Redis内部机制详解', 79.00, 300, '/images/redis-book.jpg', 1, '2025-06-29 02:07:16',
'2025-06-29 02:07:16'),
(13, '茅台酒 53度 500ml', '国酒茅台,收藏佳品', 2680.00, 28, '/images/maotai.jpg', 1, '2025-06-29 02:07:16',
'2025-07-03 00:56:50'),
(14, '五常大米 10kg', '东北优质大米香甜可口1111', 168.00, 196, '/images/rice.jpg', 1, '2025-06-29 02:07:16',
'2025-07-04 14:03:38');
/*!40000 ALTER TABLE `products`
ENABLE KEYS */;
--
-- Table structure for table `users`
--
DROP TABLE IF EXISTS `users`;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `users`
(
`id` bigint NOT NULL AUTO_INCREMENT COMMENT '用户ID',
`username` varchar(50) COLLATE utf8mb4_unicode_ci NOT NULL COMMENT '用户名',
`password` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL COMMENT '密码(加密)',
`email` varchar(100) COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT '邮箱',
`phone` varchar(20) COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT '手机号',
`status` tinyint(1) NOT NULL DEFAULT '1' COMMENT '用户状态1-正常0-禁用',
`created_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
`updated_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
`last_login` datetime DEFAULT NULL COMMENT '最后登录时间',
PRIMARY KEY (`id`),
UNIQUE KEY `username` (`username`),
KEY `idx_username` (`username`),
KEY `idx_email` (`email`),
KEY `idx_phone` (`phone`),
KEY `idx_status` (`status`),
KEY `idx_created_at` (`created_at`),
KEY `idx_users_status` (`status`),
KEY `idx_users_last_login` (`last_login`),
KEY `idx_users_created_at` (`created_at`)
) ENGINE = InnoDB
AUTO_INCREMENT = 13
DEFAULT CHARSET = utf8mb4
COLLATE = utf8mb4_unicode_ci COMMENT ='用户表';
/*!40101 SET character_set_client = @saved_cs_client */;
--
-- Dumping data for table `users`
--
/*!40000 ALTER TABLE `users`
DISABLE KEYS */;
INSERT INTO `users`
VALUES (1, 'demo1', '$2a$10$UD7rr9R.hQJko9Nf.Yz9ku461It2c7RygHDDFD/cbBqJiTtBNL0pW', 'admin_updated@example.com',
'13888888888', 1, '2025-06-29 02:07:16', '2025-07-04 14:00:34', NULL),
(2, 'demo2', '$2a$10$UD7rr9R.hQJko9Nf.Yz9ku461It2c7RygHDDFD/cbBqJiTtBNL0pW', 'demo2@example.com', '13800138002',
1, '2025-06-29 02:07:16', '2025-07-04 14:00:34', NULL),
(3, 'admin', '$2a$10$UD7rr9R.hQJko9Nf.Yz9ku461It2c7RygHDDFD/cbBqJiTtBNL0pW', 'admin@example.com', '13800138000',
1, '2025-06-29 02:07:16', '2025-07-04 14:00:34', NULL),
(4, 'testuser1', '$2a$10$UD7rr9R.hQJko9Nf.Yz9ku461It2c7RygHDDFD/cbBqJiTtBNL0pW', 'test1@example.com',
'13800138003', 1, '2025-06-29 02:07:16', '2025-07-04 14:00:34', NULL),
(5, 'testuser2', '$2a$10$UD7rr9R.hQJko9Nf.Yz9ku461It2c7RygHDDFD/cbBqJiTtBNL0pW', 'test2@example.com',
'13800138004', 1, '2025-06-29 02:07:16', '2025-07-04 14:00:34', NULL),
(6, 'testuser3', '$2a$10$UD7rr9R.hQJko9Nf.Yz9ku461It2c7RygHDDFD/cbBqJiTtBNL0pW', 'test3@example.com',
'13800138005', 1, '2025-06-29 02:07:16', '2025-07-04 14:00:34', NULL),
(7, 'testuser4', '$2a$10$UD7rr9R.hQJko9Nf.Yz9ku461It2c7RygHDDFD/cbBqJiTtBNL0pW', 'test4@example.com',
'13800138006', 1, '2025-06-29 02:07:16', '2025-07-04 14:00:34', NULL),
(8, 'testuser5', '$2a$10$UD7rr9R.hQJko9Nf.Yz9ku461It2c7RygHDDFD/cbBqJiTtBNL0pW', 'test5@example.com',
'13800138007', 1, '2025-06-29 02:07:16', '2025-07-04 14:00:34', NULL),
(11, 'student', '$2a$10$UD7rr9R.hQJko9Nf.Yz9ku461It2c7RygHDDFD/cbBqJiTtBNL0pW', '1231231@gmail.com',
'19889899898', 1, '2025-06-30 14:34:57', '2025-07-04 14:00:34', NULL),
(12, 'student1', '$2a$10$UD7rr9R.hQJko9Nf.Yz9ku461It2c7RygHDDFD/cbBqJiTtBNL0pW', 'gz1@gmail.com', '19566111010',
1, '2025-07-04 22:00:18', '2025-07-04 22:00:18', NULL);
/*!40000 ALTER TABLE `users`
ENABLE KEYS */;
--
-- Dumping routines for database 'flash_sale_db'
--
--
-- Final view structure for view `active_flash_sales`
--
/*!50001 DROP VIEW IF EXISTS `active_flash_sales`*/;
/*!50001 SET @saved_cs_client = @@character_set_client */;
/*!50001 SET @saved_cs_results = @@character_set_results */;
/*!50001 SET @saved_col_connection = @@collation_connection */;
/*!50001 SET character_set_client = utf8mb4 */;
/*!50001 SET character_set_results = utf8mb4 */;
/*!50001 SET collation_connection = utf8mb4_0900_ai_ci */;
/*!50001 CREATE ALGORITHM = UNDEFINED */ /*!50013 DEFINER =`root`@`%` SQL SECURITY DEFINER */ /*!50001 VIEW `active_flash_sales` AS
select `fs`.`id` AS `id`,
`fs`.`product_id` AS `product_id`,
`p`.`name` AS `product_name`,
`p`.`price` AS `original_price`,
`fs`.`flash_price` AS `flash_price`,
`fs`.`flash_stock` AS `flash_stock`,
`fs`.`start_time` AS `start_time`,
`fs`.`end_time` AS `end_time`,
`fs`.`status` AS `status`,
`p`.`image_url` AS `image_url`
from (`flash_sales` `fs` join `products` `p` on ((`fs`.`product_id` = `p`.`id`)))
where ((`fs`.`status` = 2) and (`fs`.`start_time` <= now()) and (`fs`.`end_time` > now()) and (`p`.`status` = 1))
*/;
/*!50001 SET character_set_client = @saved_cs_client */;
/*!50001 SET character_set_results = @saved_cs_results */;
/*!50001 SET collation_connection = @saved_col_connection */;
--
-- Final view structure for view `order_statistics`
--
/*!50001 DROP VIEW IF EXISTS `order_statistics`*/;
/*!50001 SET @saved_cs_client = @@character_set_client */;
/*!50001 SET @saved_cs_results = @@character_set_results */;
/*!50001 SET @saved_col_connection = @@collation_connection */;
/*!50001 SET character_set_client = utf8mb4 */;
/*!50001 SET character_set_results = utf8mb4 */;
/*!50001 SET collation_connection = utf8mb4_0900_ai_ci */;
/*!50001 CREATE ALGORITHM = UNDEFINED */ /*!50013 DEFINER =`root`@`%` SQL SECURITY DEFINER */ /*!50001 VIEW `order_statistics` AS
select cast(`orders`.`created_at` as date) AS `order_date`,
count(0) AS `total_orders`,
sum((case when (`orders`.`status` = 1) then 1 else 0 end)) AS `pending_orders`,
sum((case when (`orders`.`status` = 2) then 1 else 0 end)) AS `paid_orders`,
sum((case when (`orders`.`status` = 4) then 1 else 0 end)) AS `completed_orders`,
sum((case when (`orders`.`order_type` = 2) then 1 else 0 end)) AS `flash_sale_orders`,
sum(`orders`.`total_price`) AS `total_amount`
from `orders`
group by cast(`orders`.`created_at` as date)
order by `order_date` desc
*/;
/*!50001 SET character_set_client = @saved_cs_client */;
/*!50001 SET character_set_results = @saved_cs_results */;
/*!50001 SET collation_connection = @saved_col_connection */;
/*!40103 SET TIME_ZONE = @OLD_TIME_ZONE */;
/*!40101 SET SQL_MODE = @OLD_SQL_MODE */;
/*!40014 SET FOREIGN_KEY_CHECKS = @OLD_FOREIGN_KEY_CHECKS */;
/*!40014 SET UNIQUE_CHECKS = @OLD_UNIQUE_CHECKS */;
/*!40101 SET CHARACTER_SET_CLIENT = @OLD_CHARACTER_SET_CLIENT */;
/*!40101 SET CHARACTER_SET_RESULTS = @OLD_CHARACTER_SET_RESULTS */;
/*!40101 SET COLLATION_CONNECTION = @OLD_COLLATION_CONNECTION */;
/*!40111 SET SQL_NOTES = @OLD_SQL_NOTES */;
-- Dump completed on 2025-07-04 23:11:23