购物车和订单中心以及优惠券相关功能初版
This commit is contained in:
@@ -552,4 +552,108 @@ WHERE u.type = 2
|
||||
'coupon:edit',
|
||||
'coupon:delete',
|
||||
'coupon:assign'
|
||||
);
|
||||
|
||||
|
||||
|
||||
-- 购物车表
|
||||
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 '按订单查询商品的索引';
|
||||
|
||||
-- 插入订单管理相关权限
|
||||
INSERT INTO t_permission (permission_code, permission_name, permission_group, description, create_time, update_time, is_delete) VALUES
|
||||
('order:view', '查看订单', '订单管理', '查看订单列表和详情', NOW(), NOW(), 0),
|
||||
('order:edit', '编辑订单', '订单管理', '编辑订单信息', NOW(), NOW(), 0),
|
||||
('order:delete', '删除订单', '订单管理', '删除订单', NOW(), NOW(), 0),
|
||||
('order:process', '处理订单', '订单管理', '处理订单状态', NOW(), NOW(), 0);
|
||||
|
||||
-- 为管理员(type=4)分配订单管理权限
|
||||
INSERT INTO t_user_permission (user_id, permission_id, create_time, update_time)
|
||||
SELECT
|
||||
u.id as user_id,
|
||||
p.id as permission_id,
|
||||
NOW() as create_time,
|
||||
NOW() as update_time
|
||||
FROM t_user u
|
||||
CROSS JOIN t_permission p
|
||||
WHERE u.type = 4
|
||||
AND p.is_delete = 0
|
||||
AND p.permission_code IN (
|
||||
'order:view',
|
||||
'order:edit',
|
||||
'order:delete',
|
||||
'order:process'
|
||||
);
|
||||
|
||||
-- 为店长(type=2)分配订单管理权限
|
||||
INSERT INTO t_user_permission (user_id, permission_id, create_time, update_time)
|
||||
SELECT
|
||||
u.id as user_id,
|
||||
p.id as permission_id,
|
||||
NOW() as create_time,
|
||||
NOW() as update_time
|
||||
FROM t_user u
|
||||
CROSS JOIN t_permission p
|
||||
WHERE u.type = 2
|
||||
AND p.is_delete = 0
|
||||
AND p.permission_code IN (
|
||||
'order:view',
|
||||
'order:edit',
|
||||
'order:delete',
|
||||
'order:process'
|
||||
);
|
||||
Reference in New Issue
Block a user