Files
JayuCloud/YumiNail-Core/src/main/resources/files/YumiNail.sql
T

579 lines
32 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.
-- 用户余额信息表
create table t_balance
(
id bigint unsigned auto_increment comment '余额记录唯一主键ID(雪花ID)'
primary key comment '余额表主键索引',
user_id bigint unsigned not null comment '关联用户表主键',
amount decimal(10, 2) default 0.00 not null comment '当前余额',
create_time datetime default CURRENT_TIMESTAMP not null comment '余额账户创建时间',
last_update_time datetime default CURRENT_TIMESTAMP not null on update CURRENT_TIMESTAMP comment '最近一次更新时间',
constraint uk_user_id
unique (user_id) comment '用户余额唯一索引(一个用户对应一条余额记录)'
)
comment '用户余额信息表';
-- 用户余额变动明细表
create table t_balance_change_detail
(
id bigint unsigned auto_increment comment '变动记录唯一主键ID(雪花ID)'
primary key comment '余额变动明细主键索引',
user_id bigint unsigned not null comment '关联用户表主键',
amount decimal(10, 2) not null comment '本次变动金额(正数为增加,负数为减少)',
type varchar(20) not null comment '变动类型(如充值、消费、退款)',
current_balance decimal(10, 2) not null comment '变动后的当前余额',
change_time datetime default CURRENT_TIMESTAMP not null comment '变动时间'
)
comment '用户余额变动明细表';
create index idx_change_time
on t_balance_change_detail (change_time)
comment '按时间查询余额变动的索引';
create index idx_user_id
on t_balance_change_detail (user_id)
comment '按用户查询余额变动的索引';
-- 用户评论信息表
create table t_comment
(
id bigint unsigned auto_increment comment '评论唯一主键ID(雪花ID)'
primary key comment '评论主键索引',
user_id bigint unsigned not null comment '评论用户ID,关联用户表主键',
shop_id bigint unsigned default 0 null comment '关联店铺表主键(0表示非店铺评论)',
product_id bigint unsigned default 0 null comment '关联商品表主键(0表示非商品评论)',
comment_content text not null comment '评论内容',
parent_comment_id bigint unsigned default 0 null comment '父级评论ID(0表示为根评论)',
like_count int unsigned default 0 null comment '评论点赞数',
create_time datetime default CURRENT_TIMESTAMP not null comment '评论创建时间',
update_time datetime default CURRENT_TIMESTAMP not null on update CURRENT_TIMESTAMP comment '评论更新时间',
is_delete tinyint unsigned default 0 null comment '逻辑删除标识:0-未删除,1-已删除'
)
comment '用户评论信息表';
create index idx_parent_comment_id
on t_comment (parent_comment_id)
comment '按父级评论查询回复的索引';
create index idx_product_id
on t_comment (product_id)
comment '按商品查询评论的索引';
create index idx_shop_id
on t_comment (shop_id)
comment '按店铺查询评论的索引';
create index idx_user_id
on t_comment (user_id)
comment '按用户查询评论的索引';
-- 商品效果图信息表
create table t_effect_diagram
(
id bigint unsigned auto_increment comment '效果图唯一主键ID(雪花id)'
primary key comment '效果图主键索引',
product_id bigint unsigned not null comment '所属商品ID,关联商品表主键',
category varchar(50) default '' null comment '效果图类别',
image_file_ids text null comment '图片文件ID集合,多ID以逗号分隔',
description text null comment '效果图描述',
price decimal(10, 2) default 0.00 null comment '效果图对应服务价格',
duration varchar(50) default '' null comment '效果图对应服务耗时',
tag varchar(50) default '' null comment '效果图标签',
like_count int unsigned default 0 null comment '效果图点赞数',
create_time datetime default CURRENT_TIMESTAMP not null comment '创建时间',
update_time datetime default CURRENT_TIMESTAMP not null on update CURRENT_TIMESTAMP comment '更新时间',
is_delete tinyint unsigned default 0 null comment '逻辑删除:0-未删,1-已删'
)
comment '商品效果图信息表';
create index idx_product_id
on t_effect_diagram (product_id)
comment '按商品查询效果图的索引';
-- 用户登录标识信息表
create table t_login_identity
(
id bigint unsigned auto_increment comment '登录标识唯一主键ID(雪花id)'
primary key comment '登录标识主键索引',
user_id bigint unsigned not null comment '关联用户表主键',
login_method varchar(50) not null comment '登录方式(0-手机号、1-账号、2-邮箱)',
input_value varchar(100) not null comment '前端输入的具体值(如手机号、账号、邮箱)',
input_time datetime not null comment '输入时间',
update_time datetime default CURRENT_TIMESTAMP not null on update CURRENT_TIMESTAMP comment '更新时间',
status tinyint unsigned default 1 null comment '状态:1-有效,0-无效'
)
comment '用户登录标识信息表';
create index idx_login_method
on t_login_identity (login_method)
comment '按登录方式查询的索引';
create index idx_user_id
on t_login_identity (user_id)
comment '按用户查询登录标识的索引';
-- 对象存储文件信息表
create table t_object_storage_file
(
id bigint unsigned auto_increment comment '文件记录唯一主键ID(雪花ID)'
primary key comment '对象存储文件主键索引',
file_name varchar(100) not null comment '文件名称',
file_url text not null comment '文件访问链接',
create_time datetime default CURRENT_TIMESTAMP not null comment '文件上传时间',
update_time datetime default CURRENT_TIMESTAMP not null on update CURRENT_TIMESTAMP comment '文件更新时间',
status tinyint unsigned default 1 null comment '文件状态:1-可用,0-不可用,2-回收站',
delete_time datetime null comment '文件删除时间(NULL表示未删除)',
recycle_time datetime null comment '文件移入回收站时间(NULL表示未移入)'
)
comment '对象存储文件信息表';
create index idx_status
on t_object_storage_file (status)
comment '按文件状态查询的索引';
-- 系统权限表
create table t_permission
(
id bigint unsigned auto_increment comment '权限唯一主键ID'
primary key,
permission_code varchar(100) not null comment '权限编码(唯一标识)',
permission_name varchar(100) not null comment '权限名称',
permission_group varchar(50) not null comment '权限分组(商品管理、用户管理等)',
description varchar(255) null comment '权限描述',
create_time datetime default CURRENT_TIMESTAMP not null comment '创建时间',
update_time datetime default CURRENT_TIMESTAMP not null on update CURRENT_TIMESTAMP comment '更新时间',
is_delete tinyint unsigned default 0 null comment '逻辑删除:0-未删,1-已删',
constraint uk_permission_code
unique (permission_code) comment '权限编码唯一索引'
)
comment '系统权限表';
-- 商品信息表
create table t_product
(
id bigint unsigned auto_increment comment '商品唯一主键ID(雪花id)'
primary key comment '商品主键索引',
shop_id bigint unsigned not null comment '所属店铺ID,关联店铺表主键',
title varchar(100) not null comment '商品标题',
description text null comment '商品描述',
image_file_ids text null comment '图片文件ID集合,多个ID以逗号分隔',
price decimal(10, 2) not null comment '商品价格,保留2位小数',
tags varchar(512) default '' null comment '标签集合,多个标签以逗号分隔,最多5个',
like_count int unsigned default 0 null comment '商品点赞数',
collect_count int unsigned default 0 null comment '商品收藏数',
approximate_duration varchar(50) default '' null comment '商品对应的服务大约耗时(如“30分钟”)',
bookable_artists varchar(200) default '' null comment '可预约的美甲师ID集合,多个ID以逗号分隔',
available_coupons text null comment '可用的优惠券ID集合,多个ID以逗号分隔',
create_time datetime default CURRENT_TIMESTAMP not null comment '商品创建时间',
update_time datetime default CURRENT_TIMESTAMP not null on update CURRENT_TIMESTAMP comment '商品信息最后更新时间',
is_delete tinyint unsigned default 0 null comment '逻辑删除标识:0-未删除,1-已删除'
)
comment '商品信息表';
create index idx_price
on t_product (price)
comment '按价格筛选商品的索引';
create index idx_shop_id
on t_product (shop_id)
comment '按所属店铺查询商品的索引';
create index idx_tags
on t_product (tags)
comment '按标签筛选商品的索引';
create index idx_title
on t_product (title)
comment '商品标题搜索的索引';
-- 店铺信息表
create table t_shop
(
id bigint unsigned auto_increment comment '店铺唯一主键ID'
primary key comment '店铺主键索引',
shop_name varchar(100) not null comment '店铺名称',
description text null comment '店铺描述',
address varchar(200) not null comment '店铺地址',
business_hours varchar(100) default '' null comment '店铺营业时间',
cover_image_file_id varchar(50) default '' null comment '店铺封面图文件ID',
create_time datetime default CURRENT_TIMESTAMP not null comment '创建时间',
update_time datetime default CURRENT_TIMESTAMP not null on update CURRENT_TIMESTAMP comment '更新时间',
is_delete tinyint unsigned default 0 null comment '逻辑删除:0-未删,1-已删',
image_file_ids text null comment '图片文件ID集合,多个ID以逗号分隔'
)
comment '店铺信息表';
create index idx_shop_name
on t_shop (shop_name)
comment '按店铺名称查询的索引';
-- 系统标签信息表
create table t_tag
(
id bigint unsigned auto_increment comment '标签唯一主键ID'
primary key comment '标签主键索引',
tag_name varchar(50) not null comment '标签名称',
text_color varchar(20) default '#333333' null comment '标签文字颜色(16进制)',
bg_color varchar(20) default '#FFFFFF' null comment '标签背景颜色(16进制)',
border_color varchar(20) default '#E5E5E5' null comment '标签边框颜色(16进制)',
create_time datetime default CURRENT_TIMESTAMP not null comment '创建时间',
update_time datetime default CURRENT_TIMESTAMP not null on update CURRENT_TIMESTAMP comment '更新时间',
is_delete tinyint unsigned default 0 null comment '逻辑删除:0-未删,1-已删',
shop_id bigint null comment '店铺ID',
constraint uk_tag_name
unique (tag_name) comment '标签名称唯一索引'
)
comment '系统标签信息表';
-- 系统用户信息表
create table t_user
(
id bigint unsigned auto_increment comment '用户唯一主键ID(雪花ID)'
primary key comment '用户主键索引',
shop_id bigint unsigned default 0 null comment '所属店铺ID,关联店铺表主键(0表示无所属店铺)',
nickname varchar(50) not null comment '用户昵称',
account varchar(50) not null comment '用户账号(登录用)',
phone varchar(20) null comment '手机号',
email varchar(100) null comment '邮箱',
phone_verified tinyint unsigned default 0 null comment '手机号是否已验证:0-未验证,1-已验证',
email_verified tinyint unsigned default 0 null comment '邮箱是否已验证:0-未验证,1-已验证',
password varchar(100) not null comment '用户密码(加密存储)',
signature varchar(200) default '' null comment '用户签名',
level varchar(20) default '普通' null comment '用户等级',
type tinyint not null comment '用户类型,(0-用户,2-店长,3-美甲师,4-管理员)',
vip_id bigint unsigned default 0 null comment '关联VIP信息表主键(0表示非VIP)',
create_time datetime default CURRENT_TIMESTAMP not null comment '创建时间',
update_time datetime default CURRENT_TIMESTAMP not null on update CURRENT_TIMESTAMP comment '更新时间',
is_delete tinyint unsigned default 0 null comment '逻辑删除:0-未删,1-已删',
status tinyint unsigned default 1 null comment '用户状态:1-正常,0-禁用',
avatar varchar(512) null comment '头像链接',
constraint uk_account
unique (account) comment '用户账号唯一索引'
)
comment '系统用户信息表';
create index idx_email
on t_user (email)
comment '按邮箱查询的索引';
create index idx_phone
on t_user (phone)
comment '按手机号查询的索引';
create index idx_shop_id
on t_user (shop_id)
comment '按店铺查询用户的索引';
create index idx_type
on t_user (type)
comment '按用户类型查询的索引';
-- 用户权限关联表
create table t_user_permission
(
id bigint unsigned auto_increment comment '关联ID'
primary key,
user_id bigint unsigned not null comment '用户ID',
permission_id bigint unsigned not null comment '权限ID',
create_time datetime default CURRENT_TIMESTAMP not null comment '创建时间',
update_time datetime default CURRENT_TIMESTAMP not null on update CURRENT_TIMESTAMP comment '更新时间',
create_by bigint unsigned null comment '创建人ID',
update_by bigint unsigned null comment '更新人ID',
is_delete tinyint unsigned default 0 null comment '逻辑删除:0-未删,1-已删',
constraint uk_user_permission
unique (user_id, permission_id) comment '用户-权限唯一索引'
)
comment '用户权限关联表';
create index idx_permission_id
on t_user_permission (permission_id)
comment '权限ID索引';
create index idx_user_id
on t_user_permission (user_id)
comment '用户ID索引';
-- VIP权益信息表
create table t_vip_benefit
(
id bigint unsigned auto_increment comment 'VIP权益唯一主键ID(雪花ID)'
primary key comment 'VIP权益主键索引',
benefit_info text not null comment '权益详情(如折扣、专属服务)',
required_vip_level varchar(20) not null comment '所需VIP等级',
create_time datetime default CURRENT_TIMESTAMP not null comment '创建时间',
update_time datetime default CURRENT_TIMESTAMP not null on update CURRENT_TIMESTAMP comment '更新时间'
)
comment 'VIP权益信息表';
create index idx_required_vip_level
on t_vip_benefit (required_vip_level)
comment '按VIP等级查询权益的索引';
-- 用户VIP信息表
create table t_vip_info
(
id bigint unsigned auto_increment comment 'VIP信息唯一主键ID(雪花ID)'
primary key comment 'VIP信息主键索引',
vip_level varchar(20) not null comment 'VIP等级(如青铜、白银)',
start_time datetime not null comment 'VIP开通时间',
expire_time datetime not null comment 'VIP到期时间',
activation_method varchar(50) not null comment 'VIP开通方式(如购买、赠送)',
benefit_id bigint unsigned not null comment '关联VIP权益信息表主键',
create_time datetime default CURRENT_TIMESTAMP not null comment '创建时间',
update_time datetime default CURRENT_TIMESTAMP not null on update CURRENT_TIMESTAMP comment '更新时间'
)
comment '用户VIP信息表';
create index idx_vip_level
on t_vip_info (vip_level)
comment '按VIP等级查询的索引';
-- 清空现有数据
DELETE FROM t_user_permission WHERE 1=1;
DELETE FROM t_permission WHERE 1=1;
DELETE FROM t_user WHERE 1=1;
-- 插入完整的系统权限
INSERT INTO t_permission (permission_code, permission_name, permission_group, description, create_time, update_time, is_delete) VALUES
-- 首页权限
('home:view', '查看首页', '首页', '查看系统首页', NOW(), NOW(), 0),
-- 仪表盘权限
('dashboard:view', '查看仪表盘', '仪表盘', '查看系统仪表盘', NOW(), NOW(), 0),
-- 用户管理权限
('user:view', '查看用户', '用户管理', '查看用户列表和详情', NOW(), NOW(), 0),
('user:create', '新增用户', '用户管理', '新增用户', NOW(), NOW(), 0),
('user:edit', '编辑用户', '用户管理', '编辑用户信息', NOW(), NOW(), 0),
('user:reset_password', '重置密码', '用户管理', '重置用户密码', NOW(), NOW(), 0),
('user:delete', '删除用户', '用户管理', '删除用户', NOW(), NOW(), 0),
-- 商品管理权限
('product:view', '查看商品', '商品管理', '查看商品列表和详情', NOW(), NOW(), 0),
('product:create', '新增商品', '商品管理', '新增商品', NOW(), NOW(), 0),
('product:edit', '编辑商品', '商品管理', '编辑商品信息', NOW(), NOW(), 0),
('product:delete', '删除商品', '商品管理', '删除商品', NOW(), NOW(), 0),
('product:category:manage', '管理商品分类', '商品管理', '管理商品分类', NOW(), NOW(), 0),
-- 店铺管理权限
('shop:view', '查看店铺', '店铺管理', '查看店铺列表和详情', NOW(), NOW(), 0),
('shop:create', '新增店铺', '店铺管理', '新增店铺', NOW(), NOW(), 0),
('shop:edit', '编辑店铺', '店铺管理', '编辑店铺信息', NOW(), NOW(), 0),
('shop:delete', '删除店铺', '店铺管理', '删除店铺', NOW(), NOW(), 0),
('shop:staff:manage', '管理店铺员工', '店铺管理', '管理店铺员工', NOW(), NOW(), 0),
-- 权限管理权限
('permission:view', '查看权限', '权限管理', '查看权限列表', NOW(), NOW(), 0),
('permission:create', '新增权限', '权限管理', '新增系统权限', NOW(), NOW(), 0),
('permission:edit', '编辑权限', '权限管理', '编辑系统权限', NOW(), NOW(), 0),
('permission:delete', '删除权限', '权限管理', '删除系统权限', NOW(), NOW(), 0),
('permission:assign', '分配权限', '权限管理', '为用户分配权限', NOW(), NOW(), 0),
-- 标签管理权限
('tag:view', '查看标签', '标签管理', '查看标签列表和详情', NOW(), NOW(), 0),
('tag:create', '新增标签', '标签管理', '新增标签', NOW(), NOW(), 0),
('tag:edit', '编辑标签', '标签管理', '编辑标签信息', NOW(), NOW(), 0),
('tag:delete', '删除标签', '标签管理', '删除标签', NOW(), NOW(), 0),
('tag:assign', '分配标签', '标签管理', '为商品分配标签', NOW(), NOW(), 0),
-- 优惠券管理权限
('coupon:view', '查看优惠券', '优惠券管理', '查看优惠券列表和详情', NOW(), NOW(), 0),
('coupon:create', '新增优惠券', '优惠券管理', '新增优惠券', NOW(), NOW(), 0),
('coupon:edit', '编辑优惠券', '优惠券管理', '编辑优惠券信息', NOW(), NOW(), 0),
('coupon:delete', '删除优惠券', '优惠券管理', '删除优惠券', NOW(), NOW(), 0),
('coupon:assign', '分配优惠券', '优惠券管理', '为用户分配优惠券', NOW(), NOW(), 0),
-- 订单管理权限
('order:view', '查看订单', '订单管理', '查看订单列表和详情', NOW(), NOW(), 0),
('order:edit', '编辑订单', '订单管理', '编辑订单信息', NOW(), NOW(), 0),
('order:delete', '删除订单', '订单管理', '删除订单', NOW(), NOW(), 0),
('order:process', '处理订单', '订单管理', '处理订单状态', NOW(), NOW(), 0);
-- 初始化admin用户,密码为123456
-- 密码使用BCrypt加密,123456的加密值为:$2a$10$EixZaYVK1fsbw1ZfbX3OXePaWxn96p36WQoeG6Lruj3vjPGga31lW
INSERT INTO t_user (id, shop_id, nickname, account, password, type, status, create_time, update_time, is_delete) VALUES
(1, 0, '管理员', 'admin', '$2a$10$EixZaYVK1fsbw1ZfbX3OXePaWxn96p36WQoeG6Lruj3vjPGga31lW', 4, 1, NOW(), NOW(), 0);
-- 为管理员分配权限
-- 首页的全部权限
-- 仪表盘的全部权限
-- 所有店铺的用户管理的全部权限
-- 所有店铺的商品管理的查看权限,无新增编辑删除管理商品分类权限
-- 所有店铺的店铺管理的全部权限
-- 所有店铺的权限管理的全部权限
-- 所有店铺的标签管理的查看权限无新增编辑删除权限
-- 所有店铺的优惠券管理的查看权限
-- 所有店铺的订单管理的查看权限
INSERT INTO t_user_permission (user_id, permission_id, create_time, update_time, create_by)
SELECT
1 as user_id,
p.id as permission_id,
NOW() as create_time,
NOW() as update_time,
1 as create_by
FROM t_permission p
WHERE p.is_delete = 0
AND p.permission_code IN (
'home:view',
'dashboard:view',
'user:view',
'user:create',
'user:edit',
'user:reset_password',
'user:delete',
'product:view',
'shop:view',
'shop:create',
'shop:edit',
'shop:delete',
'shop:staff:manage',
'permission:view',
'permission:create',
'permission:edit',
'permission:delete',
'permission:assign',
'tag:view',
'coupon:view',
'order:view'
);
-- 注意:店长和美甲师的权限需要在系统中手动分配,因为需要关联具体的店铺
-- 这里只初始化管理员的权限
-- 优惠券信息表
create table t_coupon
(
id bigint unsigned auto_increment comment '优惠券唯一主键ID'
primary key comment '优惠券主键索引',
coupon_code varchar(50) not null comment '优惠券编码',
coupon_name varchar(100) not null comment '优惠券名称',
coupon_type tinyint not null comment '优惠券类型:1-折扣券,2-满减券',
discount_value decimal(10, 2) default 0.00 null comment '折扣值(如9.5表示95折)',
min_amount decimal(10, 2) default 0.00 null comment '满减券最低消费金额',
reduce_amount decimal(10, 2) default 0.00 null comment '满减券减免金额',
total_count int unsigned default 100 not null comment '优惠券总数量',
used_count int unsigned default 0 not null comment '已使用数量',
start_time datetime not null comment '开始时间',
end_time datetime not null comment '结束时间',
status tinyint unsigned default 1 not null comment '状态:1-可用,2-已过期,3-已用完',
shop_id bigint unsigned not null comment '所属店铺ID',
create_time datetime default CURRENT_TIMESTAMP not null comment '创建时间',
update_time datetime default CURRENT_TIMESTAMP not null on update CURRENT_TIMESTAMP comment '更新时间',
is_delete tinyint unsigned default 0 null comment '逻辑删除:0-未删,1-已删',
constraint uk_coupon_code
unique (coupon_code) comment '优惠券编码唯一索引'
) comment '优惠券信息表';
create index idx_status
on t_coupon (status) comment '按状态查询优惠券的索引';
create index idx_shop_id
on t_coupon (shop_id) comment '按店铺查询优惠券的索引';
-- 用户优惠券关联表
create table t_user_coupon
(
id bigint unsigned auto_increment comment '用户优惠券关联唯一主键ID'
primary key comment '用户优惠券关联主键索引',
user_id bigint unsigned not null comment '关联用户表主键',
coupon_id bigint unsigned not null comment '关联优惠券表主键',
status tinyint unsigned default 1 not null comment '状态:1-未使用,2-已使用,3-已过期',
obtain_time datetime default CURRENT_TIMESTAMP not null comment '获取时间',
use_time datetime null comment '使用时间',
create_time datetime default CURRENT_TIMESTAMP not null comment '创建时间',
update_time datetime default CURRENT_TIMESTAMP not null on update CURRENT_TIMESTAMP comment '更新时间',
is_delete tinyint unsigned default 0 null comment '逻辑删除:0-未删,1-已删',
constraint uk_user_coupon
unique (user_id, coupon_id) comment '用户-优惠券唯一索引'
) comment '用户优惠券关联表';
create index idx_status
on t_user_coupon (status) comment '按状态查询用户优惠券的索引';
create index idx_user_id
on t_user_coupon (user_id) comment '按用户查询优惠券的索引';
-- 优惠券标签关联表
create table t_coupon_tag
(
id bigint unsigned auto_increment comment '优惠券标签关联唯一主键ID'
primary key comment '优惠券标签关联主键索引',
coupon_id bigint unsigned not null comment '关联优惠券表主键',
tag_id bigint unsigned not null comment '关联标签表主键',
is_available tinyint unsigned default 1 not null comment '是否可用:1-可用,0-不可用',
create_time datetime default CURRENT_TIMESTAMP not null comment '创建时间',
update_time datetime default CURRENT_TIMESTAMP not null on update CURRENT_TIMESTAMP comment '更新时间',
is_delete tinyint unsigned default 0 null comment '逻辑删除:0-未删,1-已删',
constraint uk_coupon_tag
unique (coupon_id, tag_id) comment '优惠券-标签唯一索引'
) comment '优惠券标签关联表';
create index idx_coupon_id
on t_coupon_tag (coupon_id) comment '按优惠券查询标签的索引';
create index idx_tag_id
on t_coupon_tag (tag_id) comment '按标签查询优惠券的索引';
-- 购物车表
create table t_cart
(
id bigint unsigned auto_increment comment '购物车唯一主键ID'
primary key comment '购物车主键索引',
user_id bigint unsigned not null comment '关联用户表主键',
product_id bigint unsigned not null comment '关联商品表主键',
quantity int unsigned default 1 not null comment '商品数量',
create_time datetime default CURRENT_TIMESTAMP not null comment '创建时间',
update_time datetime default CURRENT_TIMESTAMP not null on update CURRENT_TIMESTAMP comment '更新时间',
is_delete tinyint unsigned default 0 null comment '逻辑删除:0-未删,1-已删',
constraint uk_user_product
unique (user_id, product_id) comment '用户-商品唯一索引'
) comment '购物车表';
create index idx_user_id
on t_cart (user_id) comment '按用户查询购物车的索引';
-- 订单表
create table t_order
(
id bigint unsigned auto_increment comment '订单唯一主键ID'
primary key comment '订单主键索引',
order_no varchar(50) not null comment '订单编号',
user_id bigint unsigned not null comment '关联用户表主键',
total_amount decimal(10, 2) not null comment '订单总金额',
actual_amount decimal(10, 2) not null comment '实际支付金额',
coupon_id bigint unsigned default 0 null comment '使用的优惠券ID',
status tinyint unsigned default 1 not null comment '订单状态:1-待使用,2-已完成,3-已取消',
create_time datetime default CURRENT_TIMESTAMP not null comment '创建时间',
update_time datetime default CURRENT_TIMESTAMP not null on update CURRENT_TIMESTAMP comment '更新时间',
is_delete tinyint unsigned default 0 null comment '逻辑删除:0-未删,1-已删',
constraint uk_order_no
unique (order_no) comment '订单编号唯一索引'
) comment '订单表';
create index idx_status
on t_order (status) comment '按状态查询订单的索引';
create index idx_user_id
on t_order (user_id) comment '按用户查询订单的索引';
-- 订单商品表
create table t_order_item
(
id bigint unsigned auto_increment comment '订单商品唯一主键ID'
primary key comment '订单商品主键索引',
order_id bigint unsigned not null comment '关联订单表主键',
product_id bigint unsigned not null comment '关联商品表主键',
quantity int unsigned not null comment '商品数量',
price decimal(10, 2) not null comment '商品单价',
create_time datetime default CURRENT_TIMESTAMP not null comment '创建时间',
update_time datetime default CURRENT_TIMESTAMP not null on update CURRENT_TIMESTAMP comment '更新时间',
is_delete tinyint unsigned default 0 null comment '逻辑删除:0-未删,1-已删'
) comment '订单商品表';
create index idx_order_id
on t_order_item (order_id) comment '按订单查询商品的索引';