优惠券相关管理功能实现
This commit is contained in:
@@ -0,0 +1,115 @@
|
||||
-- 优惠券信息表
|
||||
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-已用完',
|
||||
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 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 '按标签查询优惠券的索引';
|
||||
|
||||
-- 插入优惠券管理相关权限
|
||||
INSERT INTO t_permission (permission_code, permission_name, permission_group, description, create_time, update_time, is_delete) VALUES
|
||||
('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);
|
||||
|
||||
-- 为管理员(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 (
|
||||
'coupon:view',
|
||||
'coupon:create',
|
||||
'coupon:edit',
|
||||
'coupon:delete',
|
||||
'coupon:assign'
|
||||
);
|
||||
|
||||
-- 为店长(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 (
|
||||
'coupon:view',
|
||||
'coupon:create',
|
||||
'coupon:edit',
|
||||
'coupon:delete',
|
||||
'coupon:assign'
|
||||
);
|
||||
Reference in New Issue
Block a user