/*
 Navicat Premium Data Transfer

 Source Server         : shixun
 Source Server Type    : MySQL
 Source Server Version : 80400
 Source Host           : localhost:3306
 Source Schema         : campus_book_trade

 Target Server Type    : MySQL
 Target Server Version : 80400
 File Encoding         : 65001

 Date: 16/06/2026 21:47:37
*/

SET NAMES utf8mb4;
SET FOREIGN_KEY_CHECKS = 0;

-- ----------------------------
-- Table structure for book
-- ----------------------------
DROP TABLE IF EXISTS `book`;
CREATE TABLE `book`  (
  `book_id` int(0) NOT NULL AUTO_INCREMENT,
  `seller_id` int(0) NULL DEFAULT NULL,
  `title` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT NULL,
  `author` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT NULL,
  `category` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT NULL,
  `original_price` decimal(10, 2) NULL DEFAULT NULL,
  `selling_price` decimal(10, 2) NULL DEFAULT NULL,
  `image_url` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT NULL,
  `created_at` datetime(0) NULL DEFAULT NULL,
  `stock` int(0) NULL DEFAULT NULL,
  `status` int(0) NULL DEFAULT 0 COMMENT '0=待审核, 1=已上架, 2=已下架',
  PRIMARY KEY (`book_id`) USING BTREE
) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_unicode_ci ROW_FORMAT = Dynamic;

-- ----------------------------
-- Records of book
-- ----------------------------
INSERT INTO `book` VALUES (1, 3, 'Java程序设计', '刘晓明', '教材', 49.90, 48.00, NULL, '2026-06-15 12:07:36', 90, 1);
INSERT INTO `book` VALUES (2, 5, 'photoshop图形图像处理', '王艳梅', '教材', 59.80, 56.00, NULL, '2026-06-15 12:08:47', 50, 1);
INSERT INTO `book` VALUES (3, 2, '影视栏目包装', '李大山', '教材', 46.80, 42.00, NULL, '2026-06-16 21:32:13', 50, 1);
INSERT INTO `book` VALUES (4, 6, '数据库原理与应用', '肖时光', '教材', 55.20, 55.00, NULL, '2026-06-16 21:34:29', 4, 1);

-- ----------------------------
-- Table structure for transaction_record
-- ----------------------------
DROP TABLE IF EXISTS `transaction_record`;
CREATE TABLE `transaction_record`  (
  `trans_id` int(0) NOT NULL AUTO_INCREMENT,
  `book_id` int(0) NULL DEFAULT NULL,
  `buyer_id` int(0) NULL DEFAULT NULL,
  `transaction_num` int(0) NULL DEFAULT NULL,
  `transaction_price` decimal(10, 2) NULL DEFAULT NULL,
  `transaction_time` datetime(0) NULL DEFAULT NULL,
  PRIMARY KEY (`trans_id`) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 6 CHARACTER SET = utf8mb4 COLLATE = utf8mb4_unicode_ci ROW_FORMAT = Dynamic;

-- ----------------------------
-- Records of transaction_record
-- ----------------------------
INSERT INTO `transaction_record` VALUES (1, 1, 1, 5, 48.00, '2026-06-15 12:17:08');
INSERT INTO `transaction_record` VALUES (2, 2, 1, 2, 56.00, '2026-06-15 21:46:13');
INSERT INTO `transaction_record` VALUES (3, 2, 3, 3, 56.00, '2026-06-15 21:51:48');
INSERT INTO `transaction_record` VALUES (4, 2, 5, 3, 56.00, '2026-06-16 16:02:07');
INSERT INTO `transaction_record` VALUES (5, 1, 2, 10, 48.00, '2026-06-16 20:00:12');

-- ----------------------------
-- Table structure for user
-- ----------------------------
DROP TABLE IF EXISTS `user`;
CREATE TABLE `user`  (
  `userid` int(0) NOT NULL AUTO_INCREMENT,
  `username` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT NULL,
  `password` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT NULL,
  `nickname` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT NULL,
  `email` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT NULL,
  `phone` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT NULL,
  `dept` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT NULL,
  `credit` int(0) NULL DEFAULT 100,
  `role` int(0) NULL DEFAULT NULL,
  `is_seller` int(0) NULL DEFAULT NULL,
  `created_at` datetime(0) NULL DEFAULT NULL,
  PRIMARY KEY (`userid`) USING BTREE,
  UNIQUE INDEX `uk_username`(`username`) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 6 CHARACTER SET = utf8mb4 COLLATE = utf8mb4_unicode_ci ROW_FORMAT = Dynamic;

-- ----------------------------
-- Records of user
-- ----------------------------
INSERT INTO `user` VALUES (1, '张大民', '123456', '大民', '123@qq.com', '12345678901', '计算机学院', 100, 0, 0, '2026-06-15 11:02:18');
INSERT INTO `user` VALUES (2, '李心妍', '123456', '心妍', '123@qq.com', '12345678901', '计算机学院', 100, 1, 0, '2026-06-15 11:04:43');
INSERT INTO `user` VALUES (3, '吴胜利', '123456', '胜利', '123@qq.com', '12345678901', '东语学院', 100, 0, 1, '2026-06-15 11:07:41');
INSERT INTO `user` VALUES (4, '谢小花', '123456', '小花', '1232qq.com', '12345678901', '计算机学院', 100, 0, 0, '2026-06-15 21:55:28');
INSERT INTO `user` VALUES (5, '谢东格', '123456', '东格', '123@qq.com', '12345678901', '经济学院', 100, 0, 1, '2026-06-15 22:11:04');
INSERT INTO `user` VALUES (6, '李大海', '123456', '大海', '123@qq.com', '1234567890', '计算机学院', 100, 0, 1, '2026-06-16 21:33:46');

SET FOREIGN_KEY_CHECKS = 1;

-- Migration for existing databases:
-- ALTER TABLE `book` ADD COLUMN `status` int DEFAULT 0 COMMENT '0=待审核, 1=已上架, 2=已下架';
-- UPDATE `book` SET `status` = 1;
-- ALTER TABLE `user` ADD UNIQUE INDEX `uk_username`(`username`) COMMENT '用户名唯一索引';
