每日生鲜app全栈化开发
一、功能图
二、UI效果图
三、数据库设计
-
用户表user_info
列名 默认值 是否为空 类型 索引 其他信息 注释 id NO int PRI 自增 account NO varchar(50) 账号 password NO varchar(50) 密码 role_type NO varchar(50) 账号角色 create_at datetime 创建时间 update_at datetime 修改时间 is_del 0 NO tinyint 逻辑删除 -
权限表permission_info
列名 默认值 是否为空 类型 索引 其他信息 注释 id NO int PRI 自增 permission_name NO varchar(50) 权限名称 icon varchar(50) 图标 parent_id NO int 父级id order_num 0 NO int 排序 front_path varchar(50) 前端路由路径 component varchar(50) 组件 permission_type NO int 权限类型。0代表目录,1代表页面,2代表按钮 permission_key NO varchar(50) 权限标识 remark varchar(255) 备注说明 create_at datetime update_at datetime is_del 0 tinyint 逻辑删除 -
用户权限表user_permission_info
列名 默认值 是否为空 类型 索引 其他信息 注释 id NO int PRI 自增 user_id NO int 用户表外键 permission_id NO int 权限表外键 create_at datetime update_at datetime is_del 0 NO tinyint 逻辑删除 -
管理员信息manager_info
列名 默认值 是否为空 类型 索引 其他信息 注释 id NO int PRI 自增 manager_name NO varchar(50) 管理员名称 manager_phone_num NO varchar(50) 管理员手机号 manager_sex NO varchar(4) 管理员性别 manager_email NO varchar(50) 管理员邮箱 manager_avatar NO varchar(50) 管理员头像 user_id NO int user_info表外键 create_at datetime update_at datetime is_del 0 NO tinyint 逻辑删除 -
客户信息custom_info
列名 默认值 是否为空 类型 索引 其他信息 注释 id NO int PRI 自增 custom_name NO varchar(50) 客户名称 custom_sex NO varchar(4) 客户性别 custom_email NO varchar(50) 客户邮箱 custom_avatar NO varchar(50) 客户头像 user_id NO int user_info表外键 create_at datetime update_at datetime is_del 0 NO tinyint 逻辑删除 -
地址信息address_info
列名 默认值 是否为空 类型 索引 其他信息 注释 id NO int PRI 自增 custom_id NO int custom_info表外键 province NO varchar(50) 省 city NO varchar(50) 市 area NO varchar(50) 区 street NO varchar(255) 街道 tag varchar(50) 标签 create_at datetime update_at datetime is_del 0 NO tinyint 逻辑删除 -
category_info商品分类
列名 默认值 是否为空 类型 索引 其他信息 注释 id NO int PRI 自增 category_name NO varchar(50) 分类名称 category_img NO varchar(255) 分类图片 parent_id NO int 父级分类 create_at datetime update_agt datetime is_del 0 NO tinyint 逻辑删除 -
goods_info商品信息
列名 默认值 是否为空 类型 索引 其他信息 注释 id NO int PRI 自增 goods_name NO varchar(50) 商品名称 goods_price NO decimal 商品原价格 goods_sale_price NO decimal 商品销售价格 goods_master_img NO varchar(255) 商品封面图片 goods_status 0 NO int 商品状态,0正常,1售罄,2下线 goods_desc NO text 商品简介 goods_tag varchar(255) 商品标签 goods_weight 0 NO int 商品权重 category_id NO it 分类id,外键 create_at datetime update_at datetime is_del 0 NO tinyint 逻辑删除 -
goods_img_info商品图片信息
列名 默认值 是否为空 类型 索引 其他信息 注释 id NO int PRI 自增 goods_id NO int 外键 goods_pic_url NO varechar(255) 商品图片地址 create_at datetime update_at datetime is_del 0 NO tinyint 逻辑删除 -
goods_property_info商品规格
列名 默认值 是否为空 类型 索引 其他信息 注释 id NO int PRI 自增 goods_id NO int 外键 goods_property_name NO varchar(255) 商品规格名称 goods_property_value varchar(255) 商品规则值 create_at datetime update_at datetime is_del 0 NO tinyint 逻辑删除 -
shopping_cart_info购物车
列名 默认值 是否为空 类型 索引 其他信息 注释 id NO int PRI 自增 custom_id NO int 用户id,外键 goods_id NO int 商品id,外键 goods_count NO int 商品数量 create_at datetime update_at datetime is_del 0 NO tinyint 逻辑删除 -
order_info订单信息
列名 默认值 是否为空 类型 索引 其他信息 注释 id NO int PRI 自增 submit_time NO datetime 订单提交时间 pay_time datetime 订单付款时间 pay_type int 付款方式,0代表微信,1代表支付宝,2代表储蓄卡 pay_money decimal 付款金额 address_id NO int 订单收货地址,外键 custom_id NO int 客户ID,外键 order_status NO int 订单状态,0代表未付款,1代表已付款 create_at datetime update_at datetime is_del 0 NO tinyint 逻辑删除 -
coupon_info优惠卷
列名 默认值 是否为空 类型 索引 其他信息 注释 id NO int PRI 自增 coupon_name NO varchar(50) 优惠卷名称 coupon_money NO decimal 优惠卷金额 min_use_money NO decimal 最低使用金额 custom_id NO int 客户ID,外键 start_time NO datetime 优惠卷开始使用时间 end_time NO datetime 优惠卷过期时间 coupon_status NO int 优惠卷状态,0代表正常,1代表已使用,2代表已过期 create_at datetime update_at datetime is_del 0 NO tinyint 逻辑删除 -
panic_buy_info抢购计划
列名 默认值 是否为空 类型 索引 其他信息 注释 id NO int PRI 自增 start_time NO datetime 抢购开始时间 end_time NO datetime 抢购结束时间 manager_id NO int 外键 ,管理员id create_at datetime update_at datetime is_del 0 NO tinyint 逻辑删除 -
panic_buy_detail_info抢购计划明细
列名 默认值 是否为空 类型 索引 其他信息 注释 id NO int PRI 自增 goods_id NO int 商品外键 panic_buy_price NO decimal 商品抢购时的价格 panic_buy_id NO int 抢购计划外键 create_at datetime update_at datetime is_del 0 NO tinyint 逻辑删除 -
banner_info设置app轮播
列名 默认值 是否为空 类型 索引 其他信息 注释 id NO int PRI 自增 banner_img NO varchar(255) 图片地址 banner_desc NO varchar(255) 图片说明 banner_link varchar(255) 图片链接 create_at datetime update_at datetime is_del 0 NO tinyint 逻辑删除
四、编写数据库脚本
项目名称中文为每日生鲜,英文为everyday fresh
先新建一个数据库
/*
Navicat Premium Data Transfer
Source Server : 127.0.0.1
Source Server Type : MySQL
Source Server Version : 50540
Source Host : 127.0.0.1:3306
Source Schema : everyday_fresh
Target Server Type : MySQL
Target Server Version : 50540
File Encoding : 65001
Date: 13/06/2023 21:10:06
*/
SET NAMES utf8mb4;
SET FOREIGN_KEY_CHECKS = 0;
-- ----------------------------
-- Table structure for address_info
-- ----------------------------
DROP TABLE IF EXISTS `address_info`;
CREATE TABLE `address_info` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`custom_id` int(11) NOT NULL COMMENT 'custom_info外键',
`province` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL COMMENT '省',
`city` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL COMMENT '市',
`area` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL COMMENT '区',
`street` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL COMMENT '街道',
`tag` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '标签',
`create_at` datetime NULL DEFAULT NULL,
`update_at` datetime NULL DEFAULT NULL,
`is_del` tinyint(1) NOT NULL DEFAULT 0 COMMENT '逻辑删除',
PRIMARY KEY (`id`) USING BTREE,
INDEX `custom_id`(`custom_id`) USING BTREE,
CONSTRAINT `address_info_ibfk_1` FOREIGN KEY (`custom_id`) REFERENCES `custom_info` (`id`) ON DELETE RESTRICT ON UPDATE RESTRICT
) ENGINE = InnoDB AUTO_INCREMENT = 1 CHARACTER SET = utf8mb4 COLLATE = utf8mb4_general_ci ROW_FORMAT = Compact;
-- ----------------------------
-- Records of address_info
-- ----------------------------
-- ----------------------------
-- Table structure for banner_info
-- ----------------------------
DROP TABLE IF EXISTS `banner_info`;
CREATE TABLE `banner_info` (
`id` int(11) NOT NULL,
`banner_img` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL COMMENT '图片地址',
`banner_desc` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL COMMENT '图片说明',
`banner_link` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '图片链接',
`create_at` datetime NULL DEFAULT NULL,
`update_at` datetime NULL DEFAULT NULL,
`is_del` tinyint(1) NULL DEFAULT 0 COMMENT '逻辑删除',
PRIMARY KEY (`id`) USING BTREE
) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_general_ci ROW_FORMAT = Compact;
-- ----------------------------
-- Records of banner_info
-- ----------------------------
-- ----------------------------
-- Table structure for category_info
-- ----------------------------
DROP TABLE IF EXISTS `category_info`;
CREATE TABLE `category_info` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`category_name` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL COMMENT '分类名称',
`category_img` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL COMMENT '分类图片',
`parent_id` int(11) NOT NULL COMMENT '父级分类',
`create_at` datetime NULL DEFAULT NULL,
`update_at` datetime NULL DEFAULT NULL,
`is_del` tinyint(1) NOT NULL DEFAULT 0,
PRIMARY KEY (`id`) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 1 CHARACTER SET = utf8mb4 COLLATE = utf8mb4_general_ci ROW_FORMAT = Compact;
-- ----------------------------
-- Records of category_info
-- ----------------------------
-- ----------------------------
-- Table structure for coupon_info
-- ----------------------------
DROP TABLE IF EXISTS `coupon_info`;
CREATE TABLE `coupon_info` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`coupon_name` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL COMMENT '优惠卷名称',
`coupon_money` decimal(10, 2) NOT NULL COMMENT '优惠卷金额',
`min_use_money` decimal(10, 2) NOT NULL COMMENT '最低使用金额',
`custom_id` int(11) NOT NULL COMMENT '客户ID,外键',
`start_time` datetime NOT NULL COMMENT '优惠卷开始使用时间',
`end_time` datetime NOT NULL COMMENT '优惠卷过期时间',
`coupon_status` int(11) NOT NULL DEFAULT 0 COMMENT '优惠卷状态,0代表正常,1代表已使用,2代表已过期',
`create_at` datetime NULL DEFAULT NULL,
`update_at` datetime NULL DEFAULT NULL,
`is_del` tinyint(1) NOT NULL DEFAULT 0,
PRIMARY KEY (`id`) USING BTREE,
INDEX `custom_id`(`custom_id`) USING BTREE,
CONSTRAINT `coupon_info_ibfk_1` FOREIGN KEY (`custom_id`) REFERENCES `custom_info` (`id`) ON DELETE RESTRICT ON UPDATE RESTRICT
) ENGINE = InnoDB AUTO_INCREMENT = 1 CHARACTER SET = utf8mb4 COLLATE = utf8mb4_general_ci ROW_FORMAT = Compact;
-- ----------------------------
-- Records of coupon_info
-- ----------------------------
-- ----------------------------
-- Table structure for custom_info
-- ----------------------------
DROP TABLE IF EXISTS `custom_info`;
CREATE TABLE `custom_info` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`custom_name` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL COMMENT '客户名称',
`custom_sex` varchar(4) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL COMMENT '客户性别',
`custom_email` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL COMMENT '客户邮箱',
`custom_avatar` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL COMMENT '客户头像',
`user_id` int(11) NOT NULL COMMENT 'user_info外键',
`create_at` datetime NULL DEFAULT NULL,
`update_at` datetime NULL DEFAULT NULL,
`is_del` tinyint(1) NOT NULL DEFAULT 0 COMMENT '逻辑删除',
PRIMARY KEY (`id`) USING BTREE,
INDEX `user_id`(`user_id`) USING BTREE,
CONSTRAINT `custom_info_ibfk_1` FOREIGN KEY (`user_id`) REFERENCES `user_info` (`id`) ON DELETE RESTRICT ON UPDATE RESTRICT
) ENGINE = InnoDB AUTO_INCREMENT = 1 CHARACTER SET = utf8mb4 COLLATE = utf8mb4_general_ci ROW_FORMAT = Compact;
-- ----------------------------
-- Records of custom_info
-- ----------------------------
-- ----------------------------
-- Table structure for goods_img_info
-- ----------------------------
DROP TABLE IF EXISTS `goods_img_info`;
CREATE TABLE `goods_img_info` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`goods_id` int(11) NOT NULL COMMENT '外键',
`goods_pic_url` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '商品图片地址',
`create_at` datetime NULL DEFAULT NULL,
`update_at` datetime NULL DEFAULT NULL,
`is_del` tinyint(1) NOT NULL DEFAULT 0,
PRIMARY KEY (`id`) USING BTREE,
INDEX `goods_id`(`goods_id`) USING BTREE,
CONSTRAINT `goods_img_info_ibfk_1` FOREIGN KEY (`goods_id`) REFERENCES `goods_info` (`id`) ON DELETE RESTRICT ON UPDATE RESTRICT
) ENGINE = InnoDB AUTO_INCREMENT = 1 CHARACTER SET = utf8mb4 COLLATE = utf8mb4_general_ci ROW_FORMAT = Compact;
-- ----------------------------
-- Records of goods_img_info
-- ----------------------------
-- ----------------------------
-- Table structure for goods_info
-- ----------------------------
DROP TABLE IF EXISTS `goods_info`;
CREATE TABLE `goods_info` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`goods_name` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL COMMENT '商品名称',
`goods_price` decimal(10, 2) NOT NULL COMMENT '商品价格',
`goods_sale_price` decimal(10, 2) NOT NULL COMMENT '商品销售价格',
`goods_master_img` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL COMMENT '商品封面图片',
`goods_status` int(11) NOT NULL DEFAULT 0 COMMENT '商品状态,0正常,1售罄,2下线',
`goods_desc` longtext CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL COMMENT '商品简介',
`goods_tag` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '商品标签',
`goods_weight` int(11) NOT NULL DEFAULT 0 COMMENT '商品权重',
`category_id` int(11) NOT NULL COMMENT '分类id,外键',
`create_at` datetime NULL DEFAULT NULL,
`update_at` datetime NULL DEFAULT NULL,
`is_del` tinyint(1) NOT NULL DEFAULT 0,
PRIMARY KEY (`id`) USING BTREE,
INDEX `category_id`(`category_id`) USING BTREE,
CONSTRAINT `goods_info_ibfk_1` FOREIGN KEY (`category_id`) REFERENCES `category_info` (`id`) ON DELETE RESTRICT ON UPDATE RESTRICT
) ENGINE = InnoDB AUTO_INCREMENT = 1 CHARACTER SET = utf8mb4 COLLATE = utf8mb4_general_ci ROW_FORMAT = Compact;
-- ----------------------------
-- Records of goods_info
-- ----------------------------
-- ----------------------------
-- Table structure for goods_property_info
-- ----------------------------
DROP TABLE IF EXISTS `goods_property_info`;
CREATE TABLE `goods_property_info` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`goods_id` int(11) NOT NULL COMMENT '外键',
`goods_property_name` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '商品规格名称',
`goods_property_value` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '商品规则值',
`create_at` datetime NULL DEFAULT NULL,
`update_at` datetime NULL DEFAULT NULL,
`is_del` tinyint(4) NOT NULL DEFAULT 0,
PRIMARY KEY (`id`) USING BTREE,
INDEX `goods_id`(`goods_id`) USING BTREE,
CONSTRAINT `goods_property_info_ibfk_1` FOREIGN KEY (`goods_id`) REFERENCES `goods_info` (`id`) ON DELETE RESTRICT ON UPDATE RESTRICT
) ENGINE = InnoDB AUTO_INCREMENT = 1 CHARACTER SET = utf8mb4 COLLATE = utf8mb4_general_ci ROW_FORMAT = Compact;
-- ----------------------------
-- Records of goods_property_info
-- ----------------------------
-- ----------------------------
-- Table structure for manager_info
-- ----------------------------
DROP TABLE IF EXISTS `manager_info`;
CREATE TABLE `manager_info` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`manager_name` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL COMMENT '管理员名称',
`manager_phone_num` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL COMMENT '管理员手机号',
`manager_sex` varchar(4) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL COMMENT '管理员性别',
`manager_avatar` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL COMMENT '管理员头像',
`user_id` int(11) NOT NULL COMMENT 'user_info表外键',
`create_at` datetime NULL DEFAULT NULL,
`update_at` datetime NULL DEFAULT NULL,
`is_del` tinyint(4) NOT NULL DEFAULT 0 COMMENT '逻辑删除',
PRIMARY KEY (`id`) USING BTREE,
INDEX `user_id`(`user_id`) USING BTREE,
CONSTRAINT `manager_info_ibfk_1` FOREIGN KEY (`user_id`) REFERENCES `user_info` (`id`) ON DELETE RESTRICT ON UPDATE RESTRICT
) ENGINE = InnoDB AUTO_INCREMENT = 1 CHARACTER SET = utf8mb4 COLLATE = utf8mb4_general_ci ROW_FORMAT = Compact;
-- ----------------------------
-- Records of manager_info
-- ----------------------------
-- ----------------------------
-- Table structure for order_info
-- ----------------------------
DROP TABLE IF EXISTS `order_info`;
CREATE TABLE `order_info` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`submit_time` datetime NOT NULL COMMENT '订单提交时间',
`pay_time` datetime NULL DEFAULT NULL COMMENT '订单付款时间',
`pay_type` int(11) NULL DEFAULT NULL COMMENT '付款方式,0代表微信,1代表支付宝,2代表储蓄卡',
`pay_money` decimal(10, 2) NULL DEFAULT NULL COMMENT '付款金额',
`address_id` int(11) NOT NULL COMMENT '订单收货地址,外键',
`custom_id` int(11) NOT NULL COMMENT '客户ID,外键',
`order_status` int(11) NOT NULL COMMENT '订单状态,0代表未付款,1代表已付款',
`create_at` datetime NULL DEFAULT NULL,
`update_at` datetime NULL DEFAULT NULL,
`is_del` tinyint(1) NOT NULL DEFAULT 0,
PRIMARY KEY (`id`) USING BTREE,
INDEX `custom_id`(`custom_id`) USING BTREE,
INDEX `address_id`(`address_id`) USING BTREE,
CONSTRAINT `order_info_ibfk_1` FOREIGN KEY (`custom_id`) REFERENCES `custom_info` (`id`) ON DELETE RESTRICT ON UPDATE RESTRICT,
CONSTRAINT `order_info_ibfk_2` FOREIGN KEY (`address_id`) REFERENCES `address_info` (`id`) ON DELETE RESTRICT ON UPDATE RESTRICT
) ENGINE = InnoDB AUTO_INCREMENT = 1 CHARACTER SET = utf8mb4 COLLATE = utf8mb4_general_ci ROW_FORMAT = Compact;
-- ----------------------------
-- Records of order_info
-- ----------------------------
-- ----------------------------
-- Table structure for panic_buy_detail_info
-- ----------------------------
DROP TABLE IF EXISTS `panic_buy_detail_info`;
CREATE TABLE `panic_buy_detail_info` (
`id` int(11) NOT NULL,
`goods_id` int(11) NOT NULL COMMENT '商品外键',
`panic_buy_price` decimal(10, 2) NOT NULL COMMENT '商品抢购时的价格',
`panic_buy_id` int(11) NOT NULL COMMENT '抢购计划外键',
`create_at` datetime NULL DEFAULT NULL,
`update_at` datetime NULL DEFAULT NULL,
`is_del` tinyint(1) NOT NULL COMMENT '逻辑删除',
PRIMARY KEY (`id`) USING BTREE,
INDEX `goods_id`(`goods_id`) USING BTREE,
INDEX `panic_buy_id`(`panic_buy_id`) USING BTREE,
CONSTRAINT `panic_buy_detail_info_ibfk_1` FOREIGN KEY (`goods_id`) REFERENCES `goods_info` (`id`) ON DELETE RESTRICT ON UPDATE RESTRICT,
CONSTRAINT `panic_buy_detail_info_ibfk_2` FOREIGN KEY (`panic_buy_id`) REFERENCES `panic_buy_info` (`id`) ON DELETE RESTRICT ON UPDATE RESTRICT
) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_general_ci ROW_FORMAT = Compact;
-- ----------------------------
-- Records of panic_buy_detail_info
-- ----------------------------
-- ----------------------------
-- Table structure for panic_buy_info
-- ----------------------------
DROP TABLE IF EXISTS `panic_buy_info`;
CREATE TABLE `panic_buy_info` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`start_time` datetime NOT NULL COMMENT '抢购开始时间',
`end_time` datetime NOT NULL COMMENT '抢购结束时间',
`manager_id` int(11) NOT NULL COMMENT '外键 ,管理员id',
`create_at` datetime NULL DEFAULT NULL,
`update_at` datetime NULL DEFAULT NULL,
`is_del` tinyint(1) NOT NULL DEFAULT 0,
PRIMARY KEY (`id`) USING BTREE,
INDEX `manager_id`(`manager_id`) USING BTREE,
CONSTRAINT `panic_buy_info_ibfk_1` FOREIGN KEY (`manager_id`) REFERENCES `manager_info` (`id`) ON DELETE RESTRICT ON UPDATE RESTRICT
) ENGINE = InnoDB AUTO_INCREMENT = 1 CHARACTER SET = utf8mb4 COLLATE = utf8mb4_general_ci ROW_FORMAT = Compact;
-- ----------------------------
-- Records of panic_buy_info
-- ----------------------------
-- ----------------------------
-- Table structure for permission_info
-- ----------------------------
DROP TABLE IF EXISTS `permission_info`;
CREATE TABLE `permission_info` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`permission_name` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL COMMENT '权限名称',
`icon` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '图片',
`parent_id` int(11) NOT NULL COMMENT '父级id',
`order_num` int(11) NULL DEFAULT 0 COMMENT '排序',
`front_path` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '前端路由路径',
`component` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '组件',
`permission_type` int(11) NOT NULL COMMENT '权限类型,0代表目录,1代表页面,2代表按钮',
`permission_key` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL COMMENT '权限标识',
`remark` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '备注说明',
`create_at` datetime NULL DEFAULT NULL,
`update_at` datetime NULL DEFAULT NULL,
`is_del` tinyint(1) NOT NULL DEFAULT 0 COMMENT '逻辑删除',
PRIMARY KEY (`id`) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 1 CHARACTER SET = utf8mb4 COLLATE = utf8mb4_general_ci ROW_FORMAT = Compact;
-- ----------------------------
-- Records of permission_info
-- ----------------------------
-- ----------------------------
-- Table structure for shopping_cart_info
-- ----------------------------
DROP TABLE IF EXISTS `shopping_cart_info`;
CREATE TABLE `shopping_cart_info` (
`id` int(11) NOT NULL,
`custom_id` int(11) NOT NULL COMMENT '用户id,外键',
`goods_id` int(11) NOT NULL COMMENT '商品id,外键',
`goods_count` int(11) NOT NULL,
`create_at` datetime NULL DEFAULT NULL,
`update_at` datetime NULL DEFAULT NULL,
`is_del` tinyint(1) NOT NULL DEFAULT 0,
PRIMARY KEY (`id`) USING BTREE,
INDEX `goods_id`(`goods_id`) USING BTREE,
INDEX `custom_id`(`custom_id`) USING BTREE,
CONSTRAINT `shopping_cart_info_ibfk_1` FOREIGN KEY (`goods_id`) REFERENCES `goods_info` (`id`) ON DELETE RESTRICT ON UPDATE RESTRICT,
CONSTRAINT `shopping_cart_info_ibfk_2` FOREIGN KEY (`custom_id`) REFERENCES `custom_info` (`id`) ON DELETE RESTRICT ON UPDATE RESTRICT
) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_general_ci ROW_FORMAT = Compact;
-- ----------------------------
-- Records of shopping_cart_info
-- ----------------------------
-- ----------------------------
-- Table structure for user_info
-- ----------------------------
DROP TABLE IF EXISTS `user_info`;
CREATE TABLE `user_info` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`account` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL COMMENT '账号',
`password` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL COMMENT '密码',
`role_type` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL COMMENT '账号角色',
`create_at` datetime NULL DEFAULT NULL,
`update_at` datetime NULL DEFAULT NULL,
`is_del` tinyint(1) NOT NULL DEFAULT 0 COMMENT '逻辑删除',
PRIMARY KEY (`id`) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 1 CHARACTER SET = utf8mb4 COLLATE = utf8mb4_general_ci ROW_FORMAT = Compact;
-- ----------------------------
-- Records of user_info
-- ----------------------------
-- ----------------------------
-- Table structure for user_permission_info
-- ----------------------------
DROP TABLE IF EXISTS `user_permission_info`;
CREATE TABLE `user_permission_info` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`user_id` int(11) NOT NULL COMMENT '用户表外键',
`permission_id` int(11) NOT NULL COMMENT '权限表外键',
`create_at` datetime NULL DEFAULT NULL,
`update_at` datetime NULL DEFAULT NULL,
`is_del` tinyint(4) NOT NULL DEFAULT 0 COMMENT '逻辑删除',
PRIMARY KEY (`id`) USING BTREE,
INDEX `permission_id`(`permission_id`) USING BTREE,
INDEX `user_id`(`user_id`) USING BTREE,
CONSTRAINT `user_permission_info_ibfk_1` FOREIGN KEY (`permission_id`) REFERENCES `permission_info` (`id`) ON DELETE RESTRICT ON UPDATE RESTRICT,
CONSTRAINT `user_permission_info_ibfk_2` FOREIGN KEY (`user_id`) REFERENCES `user_info` (`id`) ON DELETE RESTRICT ON UPDATE RESTRICT
) ENGINE = InnoDB AUTO_INCREMENT = 1 CHARACTER SET = utf8mb4 COLLATE = utf8mb4_general_ci ROW_FORMAT = Compact;
-- ----------------------------
-- Records of user_permission_info
-- ----------------------------
SET FOREIGN_KEY_CHECKS = 1;
五、使用typeorm-model-generator
来生成typeorm数据模型
可以参考这篇笔记
http://www.softeem.xin:8090/archives/nestjs中使用typeorm-model-generator将数据库生成数据模型
创建一个空的文件夹取名everyday_fresh_api
,通过开发工具打开这个文件夹以后,调出控制台,初始化项目
$ npm init --yes
然后再项目的根目录下面创建entities
文件夹
最后编辑package.json里面的scripts
命令
{
"name": "everyday_fresh_api",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"db": "npx typeorm-model-generator -h 127.0.0.1 -d everyday_fresh -p 3306 -u dev -x 123456 -e mysql -o entities --noConfig true --ce pascal --cp none"
},
"keywords": [],
"author": "",
"license": "ISC",
"devDependencies": {
"typeorm-model-generator": "^0.4.6"
}
}
里面的db命令就是根据数据库模型来构建的
最后执行npm run db
即可生成文件
这个时候我们可以看到,文件已经创建好了
六、安装typeorm
我们在之前已经在《通用权限控制系统》开发的时候,已经讲过了怎么样构建项目,项目使用的是express+typeorm+ts来完成的
$ npm install typeorm mysql2 reflect-metadata --save
上面是安装了typeorm
的的所需依赖,具体的可以看官方文档
TypeORM - 一个 ORM 框架 | TypeORM 中文文档 | TypeORM 中文网 (bootcss.com)
七、安装 typescript
项目使用typescript来开发的,需要安装依赖包
$ npm install typescript ts-node nodemon --save-dev
八、配置tsconfig.json文件
{
"compilerOptions": {
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"target": "ES2015",
"module": "CommonJS",
"outDir": "./dist",
"lib": [
"DOM",
"ES2015",
"ESNext"
],
},
"include": [
"./src/**/*"
],
"exclude": [
"node_modules"
]
}