2026-08-25 10:56:55 +08:00
-- jayucloud_salon 唯一初始化 SQL
-- 本文件用于开发、测试、上线空库初始化,后续环境基线均以本文件为准。
-- 执行范围:建库、建表、索引、约束、平台管理员、基础权限、系统参数、协议、MessageHub 与 VIP 基础配置。
-- 种子数据原则:只保留运行必需配置;不写入门店、商品、订单、客户、库存流水、测试消息等业务样例数据。
-- 默认平台管理员账号:xiaowang,默认密码沿用当前 bcrypt 值。
-- Linux MySQL 环境库名大小写敏感,数据源必须指向 jayucloud_salon。
CREATE DATABASE IF NOT EXISTS jayucloud_salon DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci ;
use jayucloud_salon ;
-- auto-generated definition
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 '当前余额' ,
total_recharge_amount decimal ( 10 , 2 ) default 0 . 00 not null comment '累计充值金额' ,
last_recharge_time datetime 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 '最近一次更新时间' ,
update_time datetime default CURRENT_TIMESTAMP not null on update CURRENT_TIMESTAMP comment '更新时间' ,
constraint uk_user_id
unique ( user_id ) comment '用户余额唯一索引(一个用户对应一条余额记录)'
)
comment '用户余额信息表' ;
-- auto-generated definition
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 '变动后的当前余额' ,
before_balance decimal ( 10 , 2 ) null comment '变动前余额' ,
after_balance decimal ( 10 , 2 ) null comment '变动后余额' ,
change_scene varchar ( 32 ) null comment '余额变动场景' ,
related_order_id bigint unsigned null comment '关联系统订单ID' ,
related_order_no varchar ( 64 ) null comment '关联系统订单号' ,
external_order_no varchar ( 64 ) null comment '手工录入的外部订单号' ,
operator_id bigint unsigned null comment '操作人ID' ,
remark varchar ( 255 ) 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 '按用户查询余额变动的索引' ;
-- auto-generated definition
create table t_cart
(
id bigint unsigned auto_increment comment '购物车主键索引'
primary key ,
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 '按用户查询购物车的索引' ;
-- auto-generated definition
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表示为根评论)' ,
rating_score tinyint unsigned default 5 null comment '评论评分:1-5星' ,
image_file_ids text null comment '评论图片文件ID集合,多个ID以逗号分隔' ,
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 '按用户查询评论的索引' ; s
-- auto-generated definition
create table t_coupon
(
id bigint unsigned auto_increment comment '优惠券主键索引'
primary key ,
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-已删' ,
shop_id bigint null comment '所属店铺ID' ,
coupon_scene varchar ( 32 ) default 'NORMAL' not null comment '优惠券场景' ,
required_vip_level varchar ( 20 ) null comment '要求的VIP等级' ,
auto_match tinyint unsigned default 0 not null comment '是否自动匹配' ,
constraint uk_coupon_code
unique ( coupon_code ) comment '优惠券编码唯一索引'
)
comment '优惠券信息表' ;
create index idx_status
on t_coupon ( status )
comment '按状态查询优惠券的索引' ;
-- auto-generated definition
create table t_coupon_tag
(
id bigint unsigned auto_increment comment '优惠券标签关联主键索引'
primary key ,
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 '按标签查询优惠券的索引' ;
-- auto-generated definition
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 '按商品查询效果图的索引' ;
-- auto-generated definition
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 '输入时间' ,
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-无效'
)
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 '按用户查询登录标识的索引' ;
-- auto-generated definition
create table t_wechat_mini_binding
(
id bigint unsigned auto_increment comment '微信小程序绑定主键ID(雪花ID)'
primary key ,
user_id bigint unsigned not null comment '关联用户ID' ,
app_id varchar ( 64 ) not null comment '微信小程序appId' ,
openid varchar ( 100 ) not null comment '微信小程序openid' ,
unionid varchar ( 100 ) null comment '微信开放平台unionid' ,
status tinyint unsigned default 1 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 '更新时间' ,
constraint uk_wechat_mini_app_openid
unique ( app_id , openid ),
constraint uk_wechat_mini_app_user
unique ( app_id , user_id )
)
comment '微信小程序账号绑定表' ;
create index idx_wechat_mini_unionid
on t_wechat_mini_binding ( unionid )
comment '按unionid查询的索引' ;
-- auto-generated definition
create table t_nail_artist_info
(
id bigint unsigned auto_increment comment '美甲师信息主键索引'
primary key ,
user_id bigint unsigned not null comment '关联用户表主键(美甲师用户)' ,
identity varchar ( 50 ) default '' null comment '身份' ,
experience int unsigned default 0 null comment '从业年限' ,
skills text null comment '技能标签ID集合,多个ID以逗号分隔' ,
rating decimal ( 3 , 1 ) default 4 . 5 null comment '评分' ,
status tinyint unsigned default 1 null comment '状态:1-营业中,0-休息中' ,
participate_production tinyint unsigned default 1 not null comment '是否参与美甲制作:1-参与,0-不参与' ,
work_start_time time null comment '工作开始时间' ,
work_end_time time null comment '工作结束时间' ,
portfolio 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-已删' ,
constraint uk_user_id
unique ( user_id ) comment '用户ID唯一索引(一个美甲师对应一条信息记录)'
)
comment '美甲师信息表' ;
create index idx_status
on t_nail_artist_info ( status )
comment '按状态查询美甲师的索引' ;
create index idx_user_id
on t_nail_artist_info ( user_id )
comment '按用户查询美甲师信息的索引' ;
create index idx_t_nail_artist_info_participate
on t_nail_artist_info ( participate_production , status );
-- auto-generated definition
create table t_object_storage_file
(
id bigint unsigned auto_increment comment '????ID'
primary key comment '????????' ,
file_name varchar ( 100 ) not null comment '????' ,
file_url text not null comment '??????' ,
object_name varchar ( 512 ) null comment '????Key' ,
primary_provider varchar ( 64 ) null comment '??????' ,
primary_url text null comment '???????' ,
backup_provider varchar ( 64 ) null comment '???????' ,
backup_url text null comment '????????' ,
content_type varchar ( 128 ) null comment '??Content-Type' ,
file_size bigint unsigned null comment '?????????' ,
primary_upload_status tinyint unsigned default 0 not null comment '????????0????1???2??' ,
backup_upload_status tinyint unsigned default 0 not null comment '?????????0????1???2??' ,
backup_retry_count int unsigned default 0 not null comment '??????' ,
backup_last_error varchar ( 500 ) null comment '??????????' ,
backup_uploaded_at datetime null comment '??????' ,
backup_last_retry_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 '??????' ,
status tinyint unsigned default 1 null comment '?????1???0????2???' ,
delete_time datetime null comment '??????' ,
recycle_time datetime null comment '?????????'
)
comment '?????????' ;
create index idx_status
on t_object_storage_file ( status )
comment '??????' ;
create index idx_object_storage_file_backup_retry
on t_object_storage_file ( backup_upload_status , primary_upload_status , status )
comment '????????' ;
-- auto-generated definition
CREATE TABLE IF NOT EXISTS ` t_object_storage_file_replica `
(
` id ` bigint unsigned NOT NULL COMMENT '副本ID' ,
` file_id ` bigint unsigned NOT NULL COMMENT '文件ID' ,
` provider ` varchar ( 64 ) NOT NULL COMMENT '对象存储提供方' ,
` object_name ` varchar ( 512 ) NOT NULL COMMENT '对象Key' ,
` object_url ` text NULL COMMENT '对象访问地址' ,
` upload_status ` tinyint unsigned NOT NULL DEFAULT 0 COMMENT '上传状态:0-待上传,1-成功,2-失败' ,
` retry_count ` int unsigned NOT NULL DEFAULT 0 COMMENT '重试次数' ,
` last_error ` varchar ( 500 ) NULL COMMENT '最近一次错误' ,
` uploaded_at ` datetime NULL COMMENT '上传成功时间' ,
` last_retry_time ` datetime NULL COMMENT '最近一次重试时间' ,
` create_time ` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间' ,
` update_time ` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间' ,
PRIMARY KEY ( ` id ` ),
UNIQUE KEY ` uk_object_storage_file_replica_file_provider ` ( ` file_id ` , ` provider ` ),
KEY ` idx_object_storage_file_replica_retry ` ( ` upload_status ` , ` provider ` , ` file_id ` ),
KEY ` idx_object_storage_file_replica_file_status ` ( ` file_id ` , ` upload_status ` )
) ENGINE = InnoDB
DEFAULT CHARSET = utf8mb4
COLLATE = utf8mb4_unicode_ci
COMMENT = '对象存储文件副本表' ;
-- auto-generated definition
create table t_order
(
id bigint unsigned auto_increment comment '订单主键索引'
primary key ,
order_no varchar ( 50 ) not null comment '订单编号' ,
user_id bigint unsigned not null comment '关联用户表主键' ,
shop_id bigint unsigned null comment '所属店铺ID' ,
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' ,
user_coupon_id bigint unsigned null comment '用户券ID' ,
coupon_source_type varchar ( 32 ) 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_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 '按用户查询订单的索引' ;
-- auto-generated definition
create table t_order_item
(
id bigint unsigned auto_increment comment '订单商品主键索引'
primary key ,
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 '商品单价' ,
artist_id bigint unsigned null comment '关联美甲师ID' ,
appointment_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-已删'
)
comment '订单商品表' ;
create index idx_order_id
on t_order_item ( order_id )
comment '按订单查询商品的索引' ;
CREATE TABLE IF NOT EXISTS t_order_artist_review
(
id bigint unsigned auto_increment comment '评价任务ID'
primary key ,
order_id bigint unsigned not null comment '订单ID' ,
order_item_id bigint unsigned not null comment '订单项ID' ,
customer_id bigint unsigned not null comment '下单客户ID' ,
shop_id bigint unsigned null comment '店铺ID' ,
artist_id bigint unsigned not null comment '被评价美甲师ID' ,
product_id bigint unsigned null comment '商品ID' ,
rating_score decimal ( 2 , 1 ) null comment '评分,提交后必填0.5-5' ,
content varchar ( 1000 ) null comment '评价文字' ,
image_file_ids text null comment '评价图片文件ID集合' ,
status tinyint unsigned default 0 not null comment '状态:0-待评价,1-已评价' ,
reminder_message_id bigint unsigned null comment '提醒消息ID' ,
submitted_at 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-已删'
)
comment '订单美甲师评价任务表' ;
create unique index uk_order_artist_review_item
on t_order_artist_review ( order_item_id , is_delete );
create index idx_order_artist_review_customer
on t_order_artist_review ( customer_id , status , create_time );
create index idx_order_artist_review_artist
on t_order_artist_review ( artist_id , status );
CREATE TABLE IF NOT EXISTS t_order_artist_change_request
(
id bigint unsigned auto_increment comment '改派申请ID'
primary key ,
order_id bigint unsigned not null comment '订单ID' ,
order_item_id bigint unsigned not null comment '订单项ID' ,
customer_id bigint unsigned not null comment '下单客户ID' ,
shop_id bigint unsigned null comment '店铺ID' ,
product_id bigint unsigned null comment '商品ID' ,
from_artist_id bigint unsigned not null comment '原美甲师ID' ,
to_artist_id bigint unsigned not null comment '新美甲师ID' ,
requester_id bigint unsigned not null comment '申请人ID' ,
status varchar ( 20 ) default 'PENDING' not null comment '状态:PENDING/APPROVED/REJECTED' ,
reason varchar ( 500 ) null comment '申请原因' ,
reject_reason varchar ( 500 ) null comment '拒绝原因' ,
message_id bigint unsigned null comment '提醒消息ID' ,
pending_key varchar ( 80 ) null comment '待处理唯一键,PENDING时为订单项维度' ,
approved_time datetime null comment '同意时间' ,
rejected_time datetime null comment '拒绝时间' ,
expire_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-已删'
)
comment '订单美甲师改派申请表' ;
create index idx_order_artist_change_customer
on t_order_artist_change_request ( customer_id , status , create_time );
create index idx_order_artist_change_artist
on t_order_artist_change_request ( from_artist_id , to_artist_id , status );
create index idx_order_artist_change_shop
on t_order_artist_change_request ( shop_id , status , create_time );
create unique index uk_order_artist_change_pending_key
on t_order_artist_change_request ( pending_key );
-- auto-generated definition
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 '系统权限表' ;
-- auto-generated definition
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 '商品描述' ,
target_audience text null comment '适合人群说明' ,
precautions 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以逗号分隔' ,
front_visible tinyint unsigned default 1 not null comment '前台是否展示:0-隐藏,1-展示' ,
source_type varchar ( 64 ) default 'BACKEND' not null comment '来源类型:BACKEND-后台维护,MANAGER_APPOINTMENT-管理师端手动预约' ,
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 index idx_t_product_front_visible
on t_product ( shop_id , front_visible , source_type )
comment '按门店、前台展示和来源筛选商品' ;
-- auto-generated definition
create table t_product_like
(
id bigint unsigned auto_increment comment '商品点赞主键索引'
primary key ,
user_id bigint unsigned not null comment '关联用户表主键' ,
product_id bigint unsigned 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_like
unique ( user_id , product_id ) comment '用户-商品唯一索引'
)
comment '商品点赞记录表' ;
create index idx_product_id_like
on t_product_like ( product_id )
comment '按商品查询点赞的索引' ;
create index idx_user_id_like
on t_product_like ( user_id )
comment '按用户查询点赞的索引' ;
-- auto-generated definition
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 '店铺地址' ,
map_provider varchar ( 20 ) default 'TENCENT' not null comment '地图服务商:TENCENT/AMAP' ,
longitude decimal ( 12 , 8 ) null comment '店铺经度' ,
latitude decimal ( 12 , 8 ) null comment '店铺纬度' ,
business_hours varchar ( 100 ) default '' null comment '店铺营业时间' ,
cover_image_file_id varchar ( 50 ) default '' null comment '店铺封面图文件ID' ,
theme_primary_color varchar ( 20 ) null comment '前台主题主色' ,
theme_secondary_color varchar ( 20 ) null comment '前台主题辅色' ,
theme_accent_color varchar ( 20 ) null comment '前台主题强调色' ,
theme_page_bg_color varchar ( 20 ) null comment '前台主题页面背景色' ,
theme_card_bg_color varchar ( 20 ) null comment '前台主题卡片背景色' ,
theme_background_image_file_id varchar ( 50 ) null comment '前台主题背景图文件ID' ,
status tinyint unsigned default 1 not null comment '店铺状态:1-启用,0-停用' ,
authorization_start_date date null comment '店铺授权起始日' ,
authorization_days int null comment '店铺授权有效天数' ,
authorization_expire_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-已删' ,
image_file_ids text null comment '图片文件ID集合,多个ID以逗号分隔'
)
comment '店铺信息表' ;
create index idx_shop_name
on t_shop ( shop_name )
comment '按店铺名称查询的索引' ;
-- auto-generated definition
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进制)' ,
scene_group varchar ( 50 ) null comment '前台场景筛选分组' ,
display_name varchar ( 80 ) null comment '前台展示名称' ,
sort_order int default 100 null comment '前台筛选排序' ,
front_visible tinyint unsigned default 1 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-已删' ,
shop_id bigint null comment '店铺ID' ,
constraint uk_tag_shop_name
unique ( shop_id , tag_name ) comment '店铺内标签名称唯一索引'
)
comment '系统标签信息表' ;
-- auto-generated definition
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 ( 50 ) null comment '手机号' ,
contact_phone varchar ( 50 ) null comment '联系电话' ,
birthday date null comment '生日' ,
wechat_id varchar ( 100 ) null comment '微信号' ,
wechat_qr_code varchar ( 512 ) 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 '按用户类型查询的索引' ;
-- auto-generated definition
create table t_user_coupon
(
id bigint unsigned auto_increment comment '用户优惠券关联主键索引'
primary key ,
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 '按用户查询优惠券的索引' ;
-- auto-generated definition
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索引' ;
create table if not exists t_system_message
(
id bigint unsigned auto_increment comment '站内消息主键'
primary key ,
title varchar ( 100 ) not null comment '消息标题' ,
content text not null comment '消息内容' ,
image_file_id bigint unsigned null comment '消息图片文件ID' ,
publisher_id bigint unsigned not null comment '发布人ID' ,
publisher_name varchar ( 100 ) default '' null comment '发布人名称' ,
publisher_type tinyint not null comment '发布人类型:2-店长,4-管理员' ,
target_type varchar ( 30 ) not null comment '目标范围:PLATFORM_ALL/CURRENT_SHOP_ALL/SHOP_ALL/SELECTED_SHOPS/SELECTED_USERS' ,
target_ids text null comment '目标ID集合,多个ID以逗号分隔' ,
business_type varchar ( 64 ) null comment '业务类型' ,
business_id bigint unsigned null comment '业务ID' ,
action_path varchar ( 255 ) null comment '业务跳转路径' ,
idempotency_key varchar ( 160 ) null comment '业务消息幂等键' ,
popup_enabled tinyint unsigned default 1 not null comment '是否弹窗:1-弹窗,0-不弹窗' ,
status tinyint unsigned default 1 not null comment '状态:1-已发布,0-已撤回' ,
publish_time datetime default CURRENT_TIMESTAMP 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_t_system_message_publish_time
on t_system_message ( publish_time );
create index idx_t_system_message_target
on t_system_message ( target_type , status );
create unique index uk_t_system_message_idempotency
on t_system_message ( idempotency_key );
create table if not exists t_system_message_user_state
(
id bigint unsigned auto_increment comment '用户消息状态主键'
primary key ,
message_id bigint unsigned not null comment '消息ID' ,
user_id bigint unsigned not null comment '用户ID' ,
popup_shown tinyint unsigned default 0 not null comment '是否已弹窗:1-是,0-否' ,
read_status tinyint unsigned default 0 not null comment '是否已读:1-是,0-否' ,
popup_time datetime null comment '首次弹窗时间' ,
read_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_t_system_message_user
unique ( message_id , user_id )
)
comment '用户站内消息状态表' ;
create index idx_t_system_message_user_state_user
on t_system_message_user_state ( user_id , read_status , popup_shown );
create table if not exists t_announcement
(
id bigint unsigned auto_increment comment '公告主键'
primary key ,
title varchar ( 100 ) not null comment '公告标题' ,
content text not null comment '公告内容' ,
publisher_id bigint unsigned not null comment '发布人ID' ,
publisher_name varchar ( 100 ) default '' null comment '发布人名称' ,
publisher_type tinyint not null comment '发布人类型:2-店长,4-管理员' ,
target_type varchar ( 30 ) not null comment '目标范围' ,
target_ids text null comment '目标ID集合,多个ID以逗号分隔' ,
status tinyint unsigned default 1 not null comment '状态:1-已发布,0-已撤回' ,
sort_order int default 0 not null comment '排序值' ,
publish_time datetime default CURRENT_TIMESTAMP 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_t_announcement_target
on t_announcement ( target_type , status );
create index idx_t_announcement_sort_time
on t_announcement ( sort_order , publish_time );
create table if not exists t_vip_recharge_plan
(
id bigint unsigned auto_increment comment 'VIP充值档位主键'
primary key ,
shop_id bigint unsigned not null comment '所属店铺ID' ,
title varchar ( 100 ) not null comment '档位标题' ,
recharge_amount decimal ( 10 , 2 ) not null comment '充值金额' ,
gift_amount decimal ( 10 , 2 ) default 0 . 00 not null comment '赠送金额' ,
vip_level varchar ( 20 ) not null comment '对应VIP等级' ,
description varchar ( 255 ) null comment '展示说明' ,
sort_order int default 0 not null comment '排序值' ,
status 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-已删'
)
comment 'VIP充值展示档位表' ;
create index idx_t_vip_recharge_plan_shop_status
on t_vip_recharge_plan ( shop_id , status , sort_order );
-- auto-generated definition
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等级' ,
level_rank int default 0 not null comment '等级序号' ,
recharge_threshold decimal ( 10 , 2 ) default 0 . 00 not null comment '累计充值门槛' ,
status tinyint 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 '更新时间'
)
comment 'VIP权益信息表' ;
create index idx_required_vip_level
on t_vip_benefit ( required_vip_level )
comment '按VIP等级查询权益的索引' ;
-- auto-generated definition
create table t_vip_info
(
id bigint unsigned auto_increment comment 'VIP信息唯一主键ID(雪花ID) '
primary key comment 'VIP信息主键索引' ,
user_id bigint unsigned null comment '所属用户ID' ,
vip_level varchar ( 20 ) not null comment 'VIP等级(如青铜、白银)' ,
start_time datetime not null comment 'VIP开通时间' ,
expire_time datetime null comment 'VIP到期时间' ,
activation_method varchar ( 50 ) not null comment 'VIP开通方式(如购买、赠送)' ,
benefit_id bigint unsigned null comment '关联VIP权益信息表主键' ,
manual_override tinyint unsigned default 0 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等级查询的索引' ;
-- auto-generated definition
create table t_wishlist_group
(
id bigint unsigned auto_increment comment '收藏分组主键'
primary key ,
user_id bigint unsigned not null comment '关联用户表主键' ,
name varchar ( 50 ) not null comment '分组名称,默认预设:最近想做、婚礼款、夏天款' ,
sort_order int default 100 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_t_wishlist_group_sort
on t_wishlist_group ( user_id , sort_order , create_time )
comment '按用户和排序查询收藏分组的索引' ;
create index idx_t_wishlist_group_user
on t_wishlist_group ( user_id )
comment '按用户查询收藏分组的索引' ;
-- auto-generated definition
create table t_wishlist
(
id bigint unsigned auto_increment comment '商品收藏主键索引'
primary key ,
user_id bigint unsigned not null comment '关联用户表主键' ,
product_id bigint unsigned not null comment '关联商品表主键' ,
group_id bigint unsigned null comment '收藏分组ID' ,
note varchar ( 500 ) null comment '收藏灵感备注' ,
sort_order int default 100 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_product_id
on t_wishlist ( product_id )
comment '按商品查询收藏的索引' ;
create index idx_user_id
on t_wishlist ( user_id )
comment '按用户查询收藏的索引' ;
create index idx_t_wishlist_user_group_sort
on t_wishlist ( user_id , group_id , sort_order , create_time )
comment '按用户分组查询收藏灵感的索引' ;
-- ========================================
-- 首次部署整合区:用户资产 / VIP / 优惠券补丁
-- 来源:2026-03-20_user_asset_vip_coupon_permission_patch.sql
-- ========================================
SET NAMES utf8mb4 ;
DROP PROCEDURE IF EXISTS sp_add_column_if_not_exists ;
DROP PROCEDURE IF EXISTS sp_add_index_if_not_exists ;
DROP PROCEDURE IF EXISTS sp_add_unique_index_if_not_exists ;
DELIMITER $$
CREATE PROCEDURE sp_add_column_if_not_exists (
IN p_table_name VARCHAR ( 64 ),
IN p_column_name VARCHAR ( 64 ),
IN p_definition TEXT
)
BEGIN
IF NOT EXISTS (
SELECT 1
FROM information_schema . COLUMNS
WHERE TABLE_SCHEMA = DATABASE ()
AND TABLE_NAME = p_table_name
AND COLUMN_NAME = p_column_name
) THEN
SET @ sql = CONCAT (
'ALTER TABLE `' , p_table_name , '` ADD COLUMN `' , p_column_name , '` ' ,
p_definition
);
PREPARE stmt FROM @ sql ;
EXECUTE stmt ;
DEALLOCATE PREPARE stmt ;
END IF ;
END $$
CREATE PROCEDURE sp_add_index_if_not_exists (
IN p_table_name VARCHAR ( 64 ),
IN p_index_name VARCHAR ( 64 ),
IN p_columns TEXT
)
BEGIN
IF NOT EXISTS (
SELECT 1
FROM information_schema . STATISTICS
WHERE TABLE_SCHEMA = DATABASE ()
AND TABLE_NAME = p_table_name
AND INDEX_NAME = p_index_name
) THEN
SET @ sql = CONCAT (
'ALTER TABLE `' , p_table_name , '` ADD INDEX `' , p_index_name , '` ' ,
p_columns
);
PREPARE stmt FROM @ sql ;
EXECUTE stmt ;
DEALLOCATE PREPARE stmt ;
END IF ;
END $$
CREATE PROCEDURE sp_add_unique_index_if_not_exists (
IN p_table_name VARCHAR ( 64 ),
IN p_index_name VARCHAR ( 64 ),
IN p_columns TEXT
)
BEGIN
IF NOT EXISTS (
SELECT 1
FROM information_schema . STATISTICS
WHERE TABLE_SCHEMA = DATABASE ()
AND TABLE_NAME = p_table_name
AND INDEX_NAME = p_index_name
) THEN
SET @ sql = CONCAT (
'ALTER TABLE `' , p_table_name , '` ADD UNIQUE INDEX `' , p_index_name , '` ' ,
p_columns
);
PREPARE stmt FROM @ sql ;
EXECUTE stmt ;
DEALLOCATE PREPARE stmt ;
END IF ;
END $$
DELIMITER ;
CALL sp_add_column_if_not_exists ( 't_balance' , 'total_recharge_amount' , 'decimal(10,2) NOT NULL DEFAULT 0.00 COMMENT ''累计充值金额''' );
CALL sp_add_column_if_not_exists ( 't_balance' , 'last_recharge_time' , 'datetime NULL COMMENT ''最近一次充值时间''' );
CALL sp_add_column_if_not_exists ( 't_balance' , 'update_time' , 'datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT ''更新时间''' );
CALL sp_add_column_if_not_exists ( 't_object_storage_file' , 'object_name' , 'varchar(512) NULL COMMENT ''????Key''' );
CALL sp_add_column_if_not_exists ( 't_object_storage_file' , 'primary_provider' , 'varchar(64) NULL COMMENT ''??????''' );
CALL sp_add_column_if_not_exists ( 't_object_storage_file' , 'primary_url' , 'text NULL COMMENT ''???????''' );
CALL sp_add_column_if_not_exists ( 't_object_storage_file' , 'backup_provider' , 'varchar(64) NULL COMMENT ''???????''' );
CALL sp_add_column_if_not_exists ( 't_object_storage_file' , 'backup_url' , 'text NULL COMMENT ''????????''' );
CALL sp_add_column_if_not_exists ( 't_object_storage_file' , 'content_type' , 'varchar(128) NULL COMMENT ''??Content-Type''' );
CALL sp_add_column_if_not_exists ( 't_object_storage_file' , 'file_size' , 'bigint unsigned NULL COMMENT ''?????????''' );
CALL sp_add_column_if_not_exists ( 't_object_storage_file' , 'primary_upload_status' , 'tinyint unsigned NOT NULL DEFAULT 0 COMMENT ''????????0????1???2??''' );
CALL sp_add_column_if_not_exists ( 't_object_storage_file' , 'backup_upload_status' , 'tinyint unsigned NOT NULL DEFAULT 0 COMMENT ''?????????0????1???2??''' );
CALL sp_add_column_if_not_exists ( 't_object_storage_file' , 'backup_retry_count' , 'int unsigned NOT NULL DEFAULT 0 COMMENT ''??????''' );
CALL sp_add_column_if_not_exists ( 't_object_storage_file' , 'backup_last_error' , 'varchar(500) NULL COMMENT ''??????????''' );
CALL sp_add_column_if_not_exists ( 't_object_storage_file' , 'backup_uploaded_at' , 'datetime NULL COMMENT ''??????''' );
CALL sp_add_column_if_not_exists ( 't_object_storage_file' , 'backup_last_retry_time' , 'datetime NULL COMMENT ''??????????''' );
UPDATE t_object_storage_file
SET primary_provider = COALESCE ( primary_provider , 'QINIU_KODO' ),
primary_url = COALESCE ( primary_url , file_url ),
backup_provider = COALESCE ( backup_provider , 'ALIYUN_OSS' ),
primary_upload_status = CASE WHEN primary_upload_status IS NULL OR primary_upload_status = 0 THEN 1 ELSE primary_upload_status END ,
backup_upload_status = COALESCE ( backup_upload_status , 0 ),
backup_retry_count = COALESCE ( backup_retry_count , 0 )
WHERE status = 1 ;
CALL sp_add_index_if_not_exists ( 't_object_storage_file' , 'idx_object_storage_file_backup_retry' , '(`backup_upload_status`, `primary_upload_status`, `status`)' );
UPDATE t_balance
SET total_recharge_amount = COALESCE ( total_recharge_amount , 0 . 00 )
WHERE total_recharge_amount IS NULL ;
CALL sp_add_column_if_not_exists ( 't_balance_change_detail' , 'before_balance' , 'decimal(10,2) NULL COMMENT ''变动前余额''' );
CALL sp_add_column_if_not_exists ( 't_balance_change_detail' , 'after_balance' , 'decimal(10,2) NULL COMMENT ''变动后余额''' );
CALL sp_add_column_if_not_exists ( 't_balance_change_detail' , 'change_scene' , 'varchar(32) NULL COMMENT ''余额变动场景''' );
CALL sp_add_column_if_not_exists ( 't_balance_change_detail' , 'related_order_id' , 'bigint unsigned NULL COMMENT ''关联系统订单ID''' );
CALL sp_add_column_if_not_exists ( 't_balance_change_detail' , 'related_order_no' , 'varchar(64) NULL COMMENT ''关联系统订单号''' );
CALL sp_add_column_if_not_exists ( 't_balance_change_detail' , 'external_order_no' , 'varchar(64) NULL COMMENT ''手工录入的外部订单号''' );
CALL sp_add_column_if_not_exists ( 't_balance_change_detail' , 'operator_id' , 'bigint unsigned NULL COMMENT ''操作人ID''' );
CALL sp_add_column_if_not_exists ( 't_balance_change_detail' , 'remark' , 'varchar(255) NULL COMMENT ''备注''' );
CALL sp_add_column_if_not_exists ( 't_login_identity' , 'create_time' , 'datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT ''创建时间''' );
CALL sp_add_column_if_not_exists ( 't_user' , 'contact_phone' , 'varchar(50) NULL COMMENT ''联系电话''' );
CALL sp_add_column_if_not_exists ( 't_user' , 'birthday' , 'date NULL COMMENT ''生日''' );
CALL sp_add_column_if_not_exists ( 't_user' , 'wechat_id' , 'varchar(100) NULL COMMENT ''微信号''' );
CALL sp_add_column_if_not_exists ( 't_user' , 'wechat_qr_code' , 'varchar(512) NULL COMMENT ''微信二维码''' );
UPDATE t_balance_change_detail
SET before_balance = COALESCE ( before_balance , current_balance - amount ),
after_balance = COALESCE ( after_balance , current_balance ),
change_scene = COALESCE ( NULLIF ( change_scene , '' ), type )
WHERE before_balance IS NULL
OR after_balance IS NULL
OR change_scene IS NULL
OR change_scene = '' ;
CALL sp_add_index_if_not_exists ( 't_balance_change_detail' , 'idx_balance_detail_related_order_id' , '(`related_order_id`)' );
CALL sp_add_index_if_not_exists ( 't_balance_change_detail' , 'idx_balance_detail_operator_id' , '(`operator_id`)' );
CALL sp_add_column_if_not_exists ( 't_order' , 'shop_id' , 'bigint unsigned NULL COMMENT ''所属店铺ID''' );
CALL sp_add_column_if_not_exists ( 't_order' , 'user_coupon_id' , 'bigint unsigned NULL COMMENT ''用户券ID''' );
CALL sp_add_column_if_not_exists ( 't_order_item' , 'appointment_time' , 'datetime NULL COMMENT ''预约开始时间''' );
CALL sp_add_index_if_not_exists ( 't_order_item' , 'idx_t_order_item_artist_appointment_time' , '(`artist_id`, `appointment_time`)' );
SET @ drop_old_tag_unique_sql = (
SELECT IF (
EXISTS (
SELECT 1
FROM information_schema . STATISTICS
WHERE TABLE_SCHEMA = DATABASE ()
AND TABLE_NAME = 't_tag'
AND INDEX_NAME = 'uk_tag_name'
),
'ALTER TABLE `t_tag` DROP INDEX `uk_tag_name`' ,
'SELECT 1'
)
);
PREPARE stmt FROM @ drop_old_tag_unique_sql ;
EXECUTE stmt ;
DEALLOCATE PREPARE stmt ;
CALL sp_add_unique_index_if_not_exists ( 't_tag' , 'uk_tag_shop_name' , '(`shop_id`, `tag_name`)' );
CALL sp_add_column_if_not_exists ( 't_tag' , 'scene_group' , 'varchar(50) NULL COMMENT ''前台场景筛选分组''' );
CALL sp_add_column_if_not_exists ( 't_tag' , 'display_name' , 'varchar(80) NULL COMMENT ''前台展示名称''' );
CALL sp_add_column_if_not_exists ( 't_tag' , 'sort_order' , 'int NULL DEFAULT 100 COMMENT ''前台筛选排序''' );
CALL sp_add_column_if_not_exists ( 't_tag' , 'front_visible' , 'tinyint unsigned NOT NULL DEFAULT 1 COMMENT ''前台筛选是否可见:1-可见,0-隐藏''' );
UPDATE t_tag
SET front_visible = 1
WHERE front_visible IS NULL ;
CALL sp_add_index_if_not_exists ( 't_tag' , 'idx_t_tag_front_filter' , '(`shop_id`, `front_visible`, `scene_group`, `sort_order`, `is_delete`)' );
CALL sp_add_column_if_not_exists ( 't_coupon' , 'coupon_scene' , 'varchar(32) NOT NULL DEFAULT ''NORMAL'' COMMENT ''优惠券场景''' );
CALL sp_add_column_if_not_exists ( 't_coupon' , 'required_vip_level' , 'varchar(20) NULL COMMENT ''要求的VIP等级''' );
CALL sp_add_column_if_not_exists ( 't_coupon' , 'auto_match' , 'tinyint unsigned NOT NULL DEFAULT 0 COMMENT ''是否自动匹配''' );
UPDATE t_coupon
SET coupon_scene = COALESCE ( NULLIF ( coupon_scene , '' ), 'NORMAL' ),
auto_match = COALESCE ( auto_match , 0 )
WHERE coupon_scene IS NULL
OR coupon_scene = ''
OR auto_match IS NULL ;
CALL sp_add_index_if_not_exists ( 't_coupon' , 'idx_t_coupon_scene_auto_match' , '(`coupon_scene`, `auto_match`)' );
CALL sp_add_index_if_not_exists ( 't_coupon' , 'idx_t_coupon_required_vip_level' , '(`required_vip_level`)' );
CALL sp_add_column_if_not_exists ( 't_vip_benefit' , 'level_rank' , 'int NOT NULL DEFAULT 0 COMMENT ''等级序号''' );
CALL sp_add_column_if_not_exists ( 't_vip_benefit' , 'recharge_threshold' , 'decimal(10,2) NOT NULL DEFAULT 0.00 COMMENT ''累计充值门槛''' );
CALL sp_add_column_if_not_exists ( 't_vip_benefit' , 'status' , 'tinyint unsigned NOT NULL DEFAULT 1 COMMENT ''状态''' );
UPDATE t_vip_benefit
SET level_rank = CASE required_vip_level
WHEN '普通' THEN 0
WHEN '青铜' THEN 1
WHEN '白银' THEN 2
WHEN '黄金' THEN 3
ELSE level_rank
END ,
recharge_threshold = CASE required_vip_level
WHEN '普通' THEN 0 . 00
WHEN '青铜' THEN 500 . 00
WHEN '白银' THEN 1000 . 00
WHEN '黄金' THEN 2000 . 00
ELSE recharge_threshold
END ,
status = COALESCE ( status , 1 )
WHERE required_vip_level IN ( '普通' , '青铜' , '白银' , '黄金' );
CALL sp_add_index_if_not_exists ( 't_vip_benefit' , 'idx_t_vip_benefit_status_rank' , '(`status`, `level_rank`)' );
CALL sp_add_column_if_not_exists ( 't_vip_info' , 'user_id' , 'bigint unsigned NULL COMMENT ''所属用户ID''' );
CALL sp_add_column_if_not_exists ( 't_vip_info' , 'manual_override' , 'tinyint unsigned NOT NULL DEFAULT 0 COMMENT ''是否手工覆盖VIP等级''' );
ALTER TABLE t_vip_info
MODIFY COLUMN expire_time datetime NULL COMMENT 'VIP到期时间' ,
MODIFY COLUMN benefit_id bigint unsigned NULL COMMENT '关联VIP权益信息表主键' ;
UPDATE t_vip_info vi
INNER JOIN t_user u ON u . vip_id = vi . id
SET vi . user_id = u . id
WHERE ( vi . user_id IS NULL OR vi . user_id = 0 )
AND u . vip_id IS NOT NULL
AND u . vip_id <> 0 ;
UPDATE t_vip_info
SET start_time = COALESCE ( start_time , create_time , NOW ()),
activation_method = COALESCE ( NULLIF ( activation_method , '' ), 'INIT' ),
manual_override = COALESCE ( manual_override , 0 );
CALL sp_add_unique_index_if_not_exists ( 't_vip_info' , 'uk_t_vip_info_user_id' , '(`user_id`)' );
CALL sp_add_index_if_not_exists ( 't_vip_info' , 'idx_t_vip_info_manual_override' , '(`manual_override`)' );
UPDATE t_user u
LEFT JOIN t_vip_info vi ON vi . id = u . vip_id
SET u . level = CASE
WHEN u . type = 0 AND u . vip_id IS NOT NULL AND u . vip_id <> 0 AND vi . vip_level IS NOT NULL THEN vi . vip_level
WHEN u . type = 0 THEN '普通'
ELSE u . level
END ,
u . vip_id = CASE
WHEN u . type = 0 AND u . vip_id IS NULL THEN 0
ELSE u . vip_id
END ,
u . update_time = NOW ()
WHERE u . is_delete = 0
AND u . type = 0
AND ( u . level IS NULL OR u . level = '' OR u . vip_id IS NULL );
UPDATE t_vip_benefit
SET benefit_info = '普通用户,无额外VIP折扣' ,
level_rank = 0 ,
recharge_threshold = 0 . 00 ,
status = 1 ,
update_time = NOW ()
WHERE required_vip_level = '普通' ;
INSERT INTO t_vip_benefit ( benefit_info , required_vip_level , level_rank , recharge_threshold , status , create_time , update_time )
SELECT '普通用户,无额外VIP折扣' , '普通' , 0 , 0 . 00 , 1 , NOW (), NOW ()
WHERE NOT EXISTS (
SELECT 1
FROM t_vip_benefit
WHERE required_vip_level = '普通'
);
UPDATE t_vip_benefit
SET benefit_info = '青铜VIP,系统自动匹配9.5折券' ,
level_rank = 1 ,
recharge_threshold = 500 . 00 ,
status = 1 ,
update_time = NOW ()
WHERE required_vip_level = '青铜' ;
INSERT INTO t_vip_benefit ( benefit_info , required_vip_level , level_rank , recharge_threshold , status , create_time , update_time )
SELECT '青铜VIP,系统自动匹配9.5折券' , '青铜' , 1 , 500 . 00 , 1 , NOW (), NOW ()
WHERE NOT EXISTS (
SELECT 1
FROM t_vip_benefit
WHERE required_vip_level = '青铜'
);
UPDATE t_vip_benefit
SET benefit_info = '白银VIP,系统自动匹配9.2折券' ,
level_rank = 2 ,
recharge_threshold = 1000 . 00 ,
status = 1 ,
update_time = NOW ()
WHERE required_vip_level = '白银' ;
INSERT INTO t_vip_benefit ( benefit_info , required_vip_level , level_rank , recharge_threshold , status , create_time , update_time )
SELECT '白银VIP,系统自动匹配9.2折券' , '白银' , 2 , 1000 . 00 , 1 , NOW (), NOW ()
WHERE NOT EXISTS (
SELECT 1
FROM t_vip_benefit
WHERE required_vip_level = '白银'
);
UPDATE t_vip_benefit
SET benefit_info = '黄金VIP,系统自动匹配9.0折券' ,
level_rank = 3 ,
recharge_threshold = 2000 . 00 ,
status = 1 ,
update_time = NOW ()
WHERE required_vip_level = '黄金' ;
INSERT INTO t_vip_benefit ( benefit_info , required_vip_level , level_rank , recharge_threshold , status , create_time , update_time )
SELECT '黄金VIP,系统自动匹配9.0折券' , '黄金' , 3 , 2000 . 00 , 1 , NOW (), NOW ()
WHERE NOT EXISTS (
SELECT 1
FROM t_vip_benefit
WHERE required_vip_level = '黄金'
);
DROP PROCEDURE IF EXISTS sp_add_column_if_not_exists ;
DROP PROCEDURE IF EXISTS sp_add_index_if_not_exists ;
DROP PROCEDURE IF EXISTS sp_add_unique_index_if_not_exists ;
-- ========================================
-- 首次部署整合区:多店铺登录 / 店铺状态 / 用户店铺绑定补丁
-- 来源:2026-03-25_user_shop_binding_and_shop_status_patch.sql
-- ========================================
SET NAMES utf8mb4 ;
DROP PROCEDURE IF EXISTS sp_add_column_if_not_exists ;
DROP PROCEDURE IF EXISTS sp_add_index_if_not_exists ;
DROP PROCEDURE IF EXISTS sp_add_unique_index_if_not_exists ;
DELIMITER $$
CREATE PROCEDURE sp_add_column_if_not_exists (
IN p_table_name VARCHAR ( 64 ),
IN p_column_name VARCHAR ( 64 ),
IN p_definition TEXT
)
BEGIN
IF NOT EXISTS (
SELECT 1
FROM information_schema . COLUMNS
WHERE TABLE_SCHEMA = DATABASE ()
AND TABLE_NAME = p_table_name
AND COLUMN_NAME = p_column_name
) THEN
SET @ sql = CONCAT (
'ALTER TABLE `' , p_table_name , '` ADD COLUMN `' , p_column_name , '` ' ,
p_definition
);
PREPARE stmt FROM @ sql ;
EXECUTE stmt ;
DEALLOCATE PREPARE stmt ;
END IF ;
END $$
CREATE PROCEDURE sp_add_index_if_not_exists (
IN p_table_name VARCHAR ( 64 ),
IN p_index_name VARCHAR ( 64 ),
IN p_columns TEXT
)
BEGIN
IF NOT EXISTS (
SELECT 1
FROM information_schema . STATISTICS
WHERE TABLE_SCHEMA = DATABASE ()
AND TABLE_NAME = p_table_name
AND INDEX_NAME = p_index_name
) THEN
SET @ sql = CONCAT (
'ALTER TABLE `' , p_table_name , '` ADD INDEX `' , p_index_name , '` ' ,
p_columns
);
PREPARE stmt FROM @ sql ;
EXECUTE stmt ;
DEALLOCATE PREPARE stmt ;
END IF ;
END $$
CREATE PROCEDURE sp_add_unique_index_if_not_exists (
IN p_table_name VARCHAR ( 64 ),
IN p_index_name VARCHAR ( 64 ),
IN p_columns TEXT
)
BEGIN
IF NOT EXISTS (
SELECT 1
FROM information_schema . STATISTICS
WHERE TABLE_SCHEMA = DATABASE ()
AND TABLE_NAME = p_table_name
AND INDEX_NAME = p_index_name
) THEN
SET @ sql = CONCAT (
'ALTER TABLE `' , p_table_name , '` ADD UNIQUE INDEX `' , p_index_name , '` ' ,
p_columns
);
PREPARE stmt FROM @ sql ;
EXECUTE stmt ;
DEALLOCATE PREPARE stmt ;
END IF ;
END $$
DELIMITER ;
CALL sp_add_column_if_not_exists ( 't_shop' , 'status' , 'tinyint unsigned NOT NULL DEFAULT 1 COMMENT ''店铺状态:1-启用,0-停用''' );
CALL sp_add_column_if_not_exists ( 't_shop' , 'authorization_start_date' , 'date NULL COMMENT ''店铺授权起始日''' );
CALL sp_add_column_if_not_exists ( 't_shop' , 'authorization_days' , 'int NULL COMMENT ''店铺授权有效天数''' );
CALL sp_add_column_if_not_exists ( 't_shop' , 'authorization_expire_time' , 'datetime NULL COMMENT ''店铺授权有效期,空表示长期有效''' );
CALL sp_add_column_if_not_exists ( 't_shop' , 'map_provider' , 'varchar(20) NOT NULL DEFAULT ''TENCENT'' COMMENT ''地图服务商:TENCENT/AMAP''' );
CALL sp_add_column_if_not_exists ( 't_shop' , 'longitude' , 'decimal(12,8) NULL COMMENT ''店铺经度''' );
CALL sp_add_column_if_not_exists ( 't_shop' , 'latitude' , 'decimal(12,8) NULL COMMENT ''店铺纬度''' );
CALL sp_add_column_if_not_exists ( 't_shop' , 'theme_primary_color' , 'varchar(20) NULL COMMENT ''前台主题主色''' );
CALL sp_add_column_if_not_exists ( 't_shop' , 'theme_secondary_color' , 'varchar(20) NULL COMMENT ''前台主题辅色''' );
CALL sp_add_column_if_not_exists ( 't_shop' , 'theme_accent_color' , 'varchar(20) NULL COMMENT ''前台主题强调色''' );
CALL sp_add_column_if_not_exists ( 't_shop' , 'theme_page_bg_color' , 'varchar(20) NULL COMMENT ''前台主题页面背景色''' );
CALL sp_add_column_if_not_exists ( 't_shop' , 'theme_card_bg_color' , 'varchar(20) NULL COMMENT ''前台主题卡片背景色''' );
CALL sp_add_column_if_not_exists ( 't_shop' , 'theme_background_image_file_id' , 'varchar(50) NULL COMMENT ''前台主题背景图文件ID''' );
UPDATE t_shop
SET status = 1
WHERE status IS NULL ;
CALL sp_add_index_if_not_exists ( 't_shop' , 'idx_t_shop_status' , '(`status`)' );
CREATE TABLE IF NOT EXISTS ` t_user_shop_binding ` (
` id ` bigint unsigned NOT NULL AUTO_INCREMENT COMMENT '用户店铺绑定主键ID' ,
` user_id ` bigint unsigned NOT NULL COMMENT '用户ID' ,
` shop_id ` bigint unsigned NOT NULL COMMENT '店铺ID' ,
` status ` tinyint unsigned NOT NULL DEFAULT 1 COMMENT '绑定状态:1-正常,0-禁用' ,
` create_time ` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间' ,
` update_time ` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间' ,
` is_delete ` tinyint unsigned DEFAULT 0 COMMENT '逻辑删除:0-未删,1-已删' ,
PRIMARY KEY ( ` id ` )
) COMMENT = '用户与店铺绑定关系表' ;
CALL sp_add_column_if_not_exists ( 't_user_shop_binding' , 'status' , 'tinyint unsigned NOT NULL DEFAULT 1 COMMENT ''绑定状态:1-正常,0-禁用''' );
CALL sp_add_column_if_not_exists ( 't_user_shop_binding' , 'create_time' , 'datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT ''创建时间''' );
CALL sp_add_column_if_not_exists ( 't_user_shop_binding' , 'update_time' , 'datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT ''更新时间''' );
CALL sp_add_column_if_not_exists ( 't_user_shop_binding' , 'is_delete' , 'tinyint unsigned DEFAULT 0 COMMENT ''逻辑删除:0-未删,1-已删''' );
CALL sp_add_index_if_not_exists ( 't_user_shop_binding' , 'idx_t_user_shop_binding_user_id' , '(`user_id`)' );
CALL sp_add_index_if_not_exists ( 't_user_shop_binding' , 'idx_t_user_shop_binding_shop_id' , '(`shop_id`)' );
CALL sp_add_index_if_not_exists ( 't_user_shop_binding' , 'idx_t_user_shop_binding_status' , '(`status`)' );
CALL sp_add_unique_index_if_not_exists ( 't_user_shop_binding' , 'uk_t_user_shop_binding_user_shop' , '(`user_id`, `shop_id`)' );
INSERT INTO t_user_shop_binding (
user_id ,
shop_id ,
status ,
create_time ,
update_time ,
is_delete
)
SELECT
u . id ,
u . shop_id ,
CASE
WHEN COALESCE ( u . status , 1 ) = 1 THEN 1
ELSE 0
END AS binding_status ,
COALESCE ( u . create_time , NOW ()),
COALESCE ( u . update_time , NOW ()),
0
FROM t_user u
INNER JOIN t_shop s ON s . id = u . shop_id AND COALESCE ( s . is_delete , 0 ) = 0
LEFT JOIN t_user_shop_binding b
ON b . user_id = u . id
AND b . shop_id = u . shop_id
AND COALESCE ( b . is_delete , 0 ) = 0
WHERE COALESCE ( u . is_delete , 0 ) = 0
AND u . shop_id IS NOT NULL
AND u . shop_id > 0
AND b . id IS NULL ;
UPDATE t_user_shop_binding b
INNER JOIN t_user u ON u . id = b . user_id
SET b . status = CASE
WHEN b . status IS NULL THEN CASE WHEN COALESCE ( u . status , 1 ) = 1 THEN 1 ELSE 0 END
ELSE b . status
END ,
b . is_delete = COALESCE ( b . is_delete , 0 ),
b . update_time = COALESCE ( b . update_time , NOW ())
WHERE b . status IS NULL
OR b . is_delete IS NULL
OR b . update_time IS NULL ;
CALL sp_add_column_if_not_exists ( 't_nail_artist_info' , 'participate_production' , 'tinyint unsigned NOT NULL DEFAULT 1 COMMENT ''是否参与美甲制作:1-参与,0-不参与''' );
CALL sp_add_column_if_not_exists ( 't_nail_artist_info' , 'work_start_time' , 'time NULL COMMENT ''工作开始时间''' );
CALL sp_add_column_if_not_exists ( 't_nail_artist_info' , 'work_end_time' , 'time NULL COMMENT ''工作结束时间''' );
CALL sp_add_index_if_not_exists ( 't_nail_artist_info' , 'idx_t_nail_artist_info_participate' , '(`participate_production`, `status`)' );
CALL sp_add_column_if_not_exists ( 't_system_message' , 'image_file_id' , 'bigint unsigned NULL COMMENT ''消息图片文件ID''' );
CALL sp_add_column_if_not_exists ( 't_system_message' , 'business_type' , 'varchar(64) NULL COMMENT ''业务类型''' );
CALL sp_add_column_if_not_exists ( 't_system_message' , 'business_id' , 'bigint unsigned NULL COMMENT ''业务ID''' );
CALL sp_add_column_if_not_exists ( 't_system_message' , 'action_path' , 'varchar(255) NULL COMMENT ''业务跳转路径''' );
CALL sp_add_column_if_not_exists ( 't_system_message' , 'idempotency_key' , 'varchar(160) NULL COMMENT ''业务消息幂等键''' );
CREATE TABLE IF NOT EXISTS t_order_artist_review
(
id bigint unsigned auto_increment comment '评价任务ID'
primary key ,
order_id bigint unsigned not null comment '订单ID' ,
order_item_id bigint unsigned not null comment '订单项ID' ,
customer_id bigint unsigned not null comment '下单客户ID' ,
shop_id bigint unsigned null comment '店铺ID' ,
artist_id bigint unsigned not null comment '被评价美甲师ID' ,
product_id bigint unsigned null comment '商品ID' ,
rating_score decimal ( 2 , 1 ) null comment '评分,提交后必填0.5-5' ,
content varchar ( 1000 ) null comment '评价文字' ,
image_file_ids text null comment '评价图片文件ID集合' ,
status tinyint unsigned default 0 not null comment '状态:0-待评价,1-已评价' ,
reminder_message_id bigint unsigned null comment '提醒消息ID' ,
submitted_at 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-已删'
)
comment '订单美甲师评价任务表' ;
CREATE TABLE IF NOT EXISTS t_order_artist_change_request
(
id bigint unsigned auto_increment comment '改派申请ID'
primary key ,
order_id bigint unsigned not null comment '订单ID' ,
order_item_id bigint unsigned not null comment '订单项ID' ,
customer_id bigint unsigned not null comment '下单客户ID' ,
shop_id bigint unsigned null comment '店铺ID' ,
product_id bigint unsigned null comment '商品ID' ,
from_artist_id bigint unsigned not null comment '原美甲师ID' ,
to_artist_id bigint unsigned not null comment '新美甲师ID' ,
requester_id bigint unsigned not null comment '申请人ID' ,
status varchar ( 20 ) default 'PENDING' not null comment '状态:PENDING/APPROVED/REJECTED' ,
reason varchar ( 500 ) null comment '申请原因' ,
reject_reason varchar ( 500 ) null comment '拒绝原因' ,
message_id bigint unsigned null comment '提醒消息ID' ,
pending_key varchar ( 80 ) null comment '待处理唯一键,PENDING时为订单项维度' ,
approved_time datetime null comment '同意时间' ,
rejected_time datetime null comment '拒绝时间' ,
expire_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-已删'
)
comment '订单美甲师改派申请表' ;
CALL sp_add_unique_index_if_not_exists ( 't_order_artist_review' , 'uk_order_artist_review_item' , '(`order_item_id`, `is_delete`)' );
CALL sp_add_index_if_not_exists ( 't_order_artist_review' , 'idx_order_artist_review_customer' , '(`customer_id`, `status`, `create_time`)' );
CALL sp_add_index_if_not_exists ( 't_order_artist_review' , 'idx_order_artist_review_artist' , '(`artist_id`, `status`)' );
CALL sp_add_index_if_not_exists ( 't_order_artist_review' , 'idx_order_artist_review_order' , '(`order_id`)' );
CALL sp_add_unique_index_if_not_exists ( 't_system_message' , 'uk_t_system_message_idempotency' , '(`idempotency_key`)' );
CALL sp_add_column_if_not_exists ( 't_order_artist_change_request' , 'pending_key' , 'varchar(80) NULL COMMENT ''待处理唯一键,PENDING时为订单项维度''' );
CALL sp_add_unique_index_if_not_exists ( 't_order_artist_change_request' , 'uk_order_artist_change_pending_key' , '(`pending_key`)' );
CALL sp_add_index_if_not_exists ( 't_order_artist_change_request' , 'idx_order_artist_change_item_status' , '(`order_item_id`, `status`, `is_delete`)' );
CALL sp_add_index_if_not_exists ( 't_order_artist_change_request' , 'idx_order_artist_change_customer' , '(`customer_id`, `status`, `create_time`)' );
CALL sp_add_index_if_not_exists ( 't_order_artist_change_request' , 'idx_order_artist_change_artist' , '(`from_artist_id`, `to_artist_id`, `status`)' );
CALL sp_add_index_if_not_exists ( 't_order_artist_change_request' , 'idx_order_artist_change_shop' , '(`shop_id`, `status`, `create_time`)' );
CALL sp_add_index_if_not_exists ( 't_order_artist_change_request' , 'idx_order_artist_change_expire' , '(`status`, `expire_time`, `is_delete`)' );
CREATE TABLE IF NOT EXISTS t_business_event_outbox
(
id bigint unsigned auto_increment comment '事件ID'
primary key ,
event_key varchar ( 160 ) not null comment '事件幂等键' ,
event_type varchar ( 64 ) not null comment '事件类型' ,
business_type varchar ( 64 ) not null comment '业务类型' ,
business_id bigint unsigned not null comment '业务ID' ,
payload_json text null comment '事件载荷' ,
status varchar ( 20 ) default 'PENDING' not null comment 'PENDING/PROCESSING/SUCCEEDED/FAILED' ,
retry_count int unsigned default 0 not null comment '重试次数' ,
next_retry_time datetime null comment '下次重试时间' ,
last_error varchar ( 500 ) null comment '最近错误' ,
claimed_at datetime null comment '认领时间' ,
processed_at 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 '逻辑删除'
)
comment '业务事件Outbox表' ;
CALL sp_add_unique_index_if_not_exists ( 't_business_event_outbox' , 'uk_business_event_outbox_event_key' , '(`event_key`)' );
CALL sp_add_index_if_not_exists ( 't_business_event_outbox' , 'idx_business_event_outbox_due' , '(`status`, `next_retry_time`, `create_time`)' );
-- Artist change requests can be expired asynchronously; expired rows release pending_key for a new request.
-- EXPIRED
-- ========================================
-- vNext operations schema: schedule / reservation / payment / after sale / inventory / campaign / growth
-- ========================================
CALL sp_add_column_if_not_exists ( 't_order' , 'payment_status' , 'varchar(20) NOT NULL DEFAULT ''UNPAID'' COMMENT ''支付状态:UNPAID/PAYING/PAID/REFUNDED''' );
CALL sp_add_column_if_not_exists ( 't_order' , 'pay_amount' , 'decimal(10,2) NULL COMMENT ''应支付金额快照''' );
CALL sp_add_column_if_not_exists ( 't_order' , 'paid_amount' , 'decimal(10,2) NULL COMMENT ''实付金额快照''' );
CALL sp_add_column_if_not_exists ( 't_order' , 'pay_time' , 'datetime NULL COMMENT ''支付完成时间''' );
CALL sp_add_column_if_not_exists ( 't_order' , 'payment_method' , 'varchar(32) NULL COMMENT ''支付方式/渠道''' );
CALL sp_add_column_if_not_exists ( 't_order' , 'payment_order_no' , 'varchar(64) NULL COMMENT ''最近一次支付单号''' );
CALL sp_add_column_if_not_exists ( 't_order' , 'refund_status' , 'varchar(20) NOT NULL DEFAULT ''NONE'' COMMENT ''退款状态:NONE/REFUNDED''' );
CALL sp_add_index_if_not_exists ( 't_order' , 'idx_t_order_payment_status' , '(`payment_status`, `is_delete`)' );
CALL sp_add_index_if_not_exists ( 't_order' , 'idx_t_order_payment_order_no' , '(`payment_order_no`)' );
CALL sp_add_index_if_not_exists ( 't_order' , 'idx_t_order_refund_status' , '(`refund_status`, `is_delete`)' );
CREATE TABLE IF NOT EXISTS t_artist_schedule
(
id bigint unsigned NOT NULL COMMENT '排班ID' ,
shop_id bigint unsigned NOT NULL COMMENT '店铺ID' ,
artist_id bigint unsigned NOT NULL COMMENT '美甲师用户ID' ,
work_date date NOT NULL COMMENT '工作日期' ,
start_time time NOT NULL COMMENT '班次开始时间' ,
end_time time NOT NULL COMMENT '班次结束时间' ,
slot_minutes int NOT NULL DEFAULT 30 COMMENT '预约粒度分钟数' ,
capacity int NOT NULL DEFAULT 1 COMMENT '同一时段可预约容量' ,
status tinyint NOT NULL DEFAULT 1 COMMENT '状态:1-可预约,0-停用' ,
remark varchar ( 255 ) NULL COMMENT '排班备注' ,
create_time datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间' ,
update_time datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间' ,
is_delete tinyint unsigned DEFAULT 0 NULL COMMENT '逻辑删除:0-未删,1-已删' ,
PRIMARY KEY ( id )
)
COMMENT '美甲师排班表' ;
CREATE TABLE IF NOT EXISTS t_appointment_reservation
(
id bigint unsigned NOT NULL COMMENT '预约占用ID' ,
order_id bigint unsigned NOT NULL COMMENT '订单ID' ,
order_item_id bigint unsigned NOT NULL COMMENT '订单项ID' ,
shop_id bigint unsigned NOT NULL COMMENT '店铺ID' ,
artist_id bigint unsigned NOT NULL COMMENT '美甲师用户ID' ,
product_title varchar ( 200 ) NULL COMMENT '预约作品标题快照' ,
appointment_start_time datetime NOT NULL COMMENT '预约开始时间' ,
appointment_end_time datetime NOT NULL COMMENT '预约结束时间' ,
status varchar ( 20 ) NOT NULL DEFAULT 'LOCKED' COMMENT '状态:LOCKED/PENDING_QUOTE/CONFIRMED/RELEASED/CANCELLED/EXPIRED' ,
client_request_id varchar ( 80 ) NULL COMMENT '客户端幂等请求ID' ,
create_time datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间' ,
update_time datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间' ,
is_delete tinyint unsigned DEFAULT 0 NULL COMMENT '逻辑删除:0-未删,1-已删' ,
PRIMARY KEY ( id )
)
COMMENT '订单预约时段占用表' ;
CREATE TABLE IF NOT EXISTS t_payment_order
(
id bigint unsigned NOT NULL COMMENT '支付单ID' ,
pay_no varchar ( 64 ) NOT NULL COMMENT '支付单号' ,
order_id bigint unsigned NOT NULL COMMENT '订单ID' ,
order_no varchar ( 64 ) NOT NULL COMMENT '订单号快照' ,
user_id bigint unsigned NOT NULL COMMENT '支付用户ID' ,
shop_id bigint unsigned NULL COMMENT '店铺ID' ,
channel varchar ( 32 ) NOT NULL DEFAULT 'MANUAL' COMMENT '支付渠道' ,
status varchar ( 20 ) NOT NULL DEFAULT 'PAYING' COMMENT '状态:PAYING/PAID/CLOSED' ,
pay_amount decimal ( 10 , 2 ) NOT NULL DEFAULT 0 . 00 COMMENT '应支付金额' ,
paid_amount decimal ( 10 , 2 ) NOT NULL DEFAULT 0 . 00 COMMENT '实付金额' ,
pay_time datetime NULL COMMENT '支付完成时间' ,
expire_time datetime NULL COMMENT '支付单过期时间' ,
operator_id bigint unsigned NULL COMMENT '手工确认操作人ID' ,
remark varchar ( 255 ) NULL COMMENT '支付备注' ,
idempotency_key varchar ( 160 ) NULL COMMENT '支付幂等键' ,
raw_payload text NULL COMMENT '支付渠道原始载荷' ,
create_time datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间' ,
update_time datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间' ,
is_delete tinyint unsigned DEFAULT 0 NULL COMMENT '逻辑删除:0-未删,1-已删' ,
PRIMARY KEY ( id )
)
COMMENT '订单支付单表' ;
CREATE TABLE IF NOT EXISTS t_refund_order
(
id bigint unsigned NOT NULL COMMENT '退款单ID' ,
refund_no varchar ( 64 ) NOT NULL COMMENT '退款单号' ,
after_sale_id bigint unsigned NULL COMMENT '售后单ID' ,
payment_order_id bigint unsigned NOT NULL COMMENT '支付单ID' ,
order_id bigint unsigned NOT NULL COMMENT '订单ID' ,
status varchar ( 20 ) NOT NULL DEFAULT 'REFUNDED' COMMENT '状态:PROCESSING/REFUNDED/FAILED' ,
refund_amount decimal ( 10 , 2 ) NOT NULL DEFAULT 0 . 00 COMMENT '退款金额' ,
refund_time datetime NULL COMMENT '退款完成时间' ,
channel varchar ( 32 ) NULL COMMENT '退款渠道' ,
external_refund_no varchar ( 64 ) NULL COMMENT '外部退款单号' ,
fail_reason varchar ( 255 ) NULL COMMENT '失败原因或备注' ,
idempotency_key varchar ( 160 ) NULL COMMENT '退款幂等键' ,
create_time datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间' ,
update_time datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间' ,
is_delete tinyint unsigned DEFAULT 0 NULL COMMENT '逻辑删除:0-未删,1-已删' ,
PRIMARY KEY ( id )
)
COMMENT '订单退款单表' ;
CREATE TABLE IF NOT EXISTS t_after_sale
(
id bigint unsigned NOT NULL COMMENT '售后单ID' ,
after_sale_no varchar ( 64 ) NOT NULL COMMENT '售后单号' ,
order_id bigint unsigned NOT NULL COMMENT '订单ID' ,
order_item_id bigint unsigned NULL COMMENT '订单项ID' ,
user_id bigint unsigned NOT NULL COMMENT '申请用户ID' ,
shop_id bigint unsigned NULL COMMENT '店铺ID' ,
type varchar ( 32 ) NOT NULL COMMENT '售后类型' ,
reason varchar ( 1000 ) NULL COMMENT '申请原因' ,
refund_amount decimal ( 10 , 2 ) NULL COMMENT '申请退款金额' ,
status varchar ( 20 ) NOT NULL DEFAULT 'PENDING' COMMENT '状态:PENDING/APPROVED/REJECTED' ,
audit_user_id bigint unsigned NULL COMMENT '审核人ID' ,
audit_reason varchar ( 500 ) NULL COMMENT '审核说明' ,
audit_time datetime NULL COMMENT '审核时间' ,
refund_order_id bigint unsigned NULL COMMENT '关联退款单ID' ,
create_time datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间' ,
update_time datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间' ,
is_delete tinyint unsigned DEFAULT 0 NULL COMMENT '逻辑删除:0-未删,1-已删' ,
PRIMARY KEY ( id )
)
COMMENT '订单售后申请表' ;
CREATE TABLE IF NOT EXISTS t_after_sale_log
(
id bigint unsigned NOT NULL COMMENT '售后日志ID' ,
after_sale_id bigint unsigned NOT NULL COMMENT '售后单ID' ,
action varchar ( 32 ) NOT NULL COMMENT '动作:CREATE/APPROVE/REJECT' ,
from_status varchar ( 20 ) NULL COMMENT '变更前状态' ,
to_status varchar ( 20 ) NULL COMMENT '变更后状态' ,
operator_id bigint unsigned NULL COMMENT '操作人ID' ,
operator_type varchar ( 20 ) NULL COMMENT '操作人类型:USER/ADMIN' ,
remark varchar ( 500 ) NULL COMMENT '备注' ,
create_time datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间' ,
update_time datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间' ,
PRIMARY KEY ( id )
)
COMMENT '订单售后流转日志表' ;
CREATE TABLE IF NOT EXISTS t_inventory_item
(
id bigint unsigned NOT NULL COMMENT '库存物料ID' ,
shop_id bigint unsigned NOT NULL COMMENT '店铺ID' ,
category varchar ( 50 ) NULL COMMENT '物料分类' ,
item_name varchar ( 100 ) NOT NULL COMMENT '物料名称' ,
unit varchar ( 20 ) NOT NULL DEFAULT '件' COMMENT '计量单位' ,
stock_quantity decimal ( 12 , 3 ) NOT NULL DEFAULT 0 . 000 COMMENT '当前库存数量' ,
warning_threshold decimal ( 12 , 3 ) NOT NULL DEFAULT 0 . 000 COMMENT '库存预警阈值' ,
status tinyint NOT NULL DEFAULT 1 COMMENT '状态:1-启用,0-停用' ,
create_time datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间' ,
update_time datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间' ,
is_delete tinyint unsigned DEFAULT 0 NULL COMMENT '逻辑删除:0-未删,1-已删' ,
PRIMARY KEY ( id )
)
COMMENT '门店库存物料表' ;
CREATE TABLE IF NOT EXISTS t_inventory_record
(
id bigint unsigned NOT NULL COMMENT '库存流水ID' ,
inventory_item_id bigint unsigned NOT NULL COMMENT '库存物料ID' ,
shop_id bigint unsigned NOT NULL COMMENT '店铺ID' ,
change_type varchar ( 32 ) NOT NULL COMMENT '变动类型:IN/OUT/ADJUST' ,
change_quantity decimal ( 12 , 3 ) NOT NULL COMMENT '变动数量' ,
before_quantity decimal ( 12 , 3 ) NOT NULL COMMENT '变动前数量' ,
after_quantity decimal ( 12 , 3 ) NOT NULL COMMENT '变动后数量' ,
operator_id bigint unsigned NULL COMMENT '操作人ID' ,
remark varchar ( 255 ) NULL COMMENT '备注' ,
create_time datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间' ,
update_time datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间' ,
PRIMARY KEY ( id )
)
COMMENT '门店库存变动流水表' ;
CREATE TABLE IF NOT EXISTS t_campaign
(
id bigint unsigned NOT NULL COMMENT '营销活动ID' ,
shop_id bigint unsigned NULL COMMENT '店铺ID,空表示平台活动' ,
title varchar ( 120 ) NOT NULL COMMENT '活动标题' ,
description varchar ( 1000 ) NULL COMMENT '活动说明' ,
scene varchar ( 32 ) NOT NULL DEFAULT 'HOME' COMMENT '活动场景' ,
product_ids text NULL COMMENT '关联作品ID集合' ,
coupon_ids text NULL COMMENT '关联优惠券ID集合' ,
status tinyint NOT NULL DEFAULT 0 COMMENT '状态:0-草稿,1-启用,2-停用' ,
start_time datetime NULL COMMENT '开始时间' ,
end_time datetime NULL COMMENT '结束时间' ,
sort_order int NOT NULL DEFAULT 100 COMMENT '排序' ,
create_time datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间' ,
update_time datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间' ,
is_delete tinyint unsigned DEFAULT 0 NULL COMMENT '逻辑删除:0-未删,1-已删' ,
PRIMARY KEY ( id )
)
COMMENT '营销活动配置表' ;
CREATE TABLE IF NOT EXISTS t_user_growth_record
(
id bigint unsigned NOT NULL COMMENT '成长值记录ID' ,
user_id bigint unsigned NOT NULL COMMENT '用户ID' ,
source_type varchar ( 32 ) NOT NULL COMMENT '成长来源:REVIEW/REBOOK/ORDER' ,
source_id bigint unsigned NULL COMMENT '来源业务ID' ,
growth_value int NOT NULL DEFAULT 0 COMMENT '成长值变化' ,
remark varchar ( 255 ) NULL COMMENT '备注' ,
create_time datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间' ,
update_time datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间' ,
PRIMARY KEY ( id )
)
COMMENT '用户成长值流水表' ;
CALL sp_add_unique_index_if_not_exists ( 't_artist_schedule' , 'uk_t_artist_schedule_slot' , '(`shop_id`, `artist_id`, `work_date`, `start_time`, `is_delete`)' );
CALL sp_add_index_if_not_exists ( 't_artist_schedule' , 'idx_t_artist_schedule_artist_date' , '(`artist_id`, `work_date`, `status`, `is_delete`)' );
CALL sp_add_index_if_not_exists ( 't_artist_schedule' , 'idx_t_artist_schedule_shop_date' , '(`shop_id`, `work_date`, `status`, `is_delete`)' );
CALL sp_add_column_if_not_exists ( 't_appointment_reservation' , 'client_request_id' , 'varchar(80) NULL COMMENT ''客户端幂等请求ID''' );
CALL sp_add_unique_index_if_not_exists ( 't_appointment_reservation' , 'uk_t_appointment_reservation_item' , '(`order_item_id`, `is_delete`)' );
CALL sp_add_unique_index_if_not_exists ( 't_appointment_reservation' , 'uk_t_appointment_reservation_client_request' , '(`shop_id`, `artist_id`, `client_request_id`, `is_delete`)' );
CALL sp_add_index_if_not_exists ( 't_appointment_reservation' , 'idx_t_appointment_reservation_artist_time' , '(`artist_id`, `status`, `appointment_start_time`, `appointment_end_time`, `is_delete`)' );
CALL sp_add_index_if_not_exists ( 't_appointment_reservation' , 'idx_t_appointment_reservation_order' , '(`order_id`, `status`, `is_delete`)' );
CALL sp_add_index_if_not_exists ( 't_appointment_reservation' , 'idx_t_appointment_reservation_shop_time' , '(`shop_id`, `appointment_start_time`, `status`, `is_delete`)' );
CALL sp_add_unique_index_if_not_exists ( 't_payment_order' , 'uk_t_payment_order_pay_no' , '(`pay_no`)' );
CALL sp_add_unique_index_if_not_exists ( 't_payment_order' , 'uk_t_payment_order_idempotency' , '(`idempotency_key`)' );
CALL sp_add_index_if_not_exists ( 't_payment_order' , 'idx_t_payment_order_order_latest' , '(`order_id`, `is_delete`, `create_time`)' );
CALL sp_add_index_if_not_exists ( 't_payment_order' , 'idx_t_payment_order_user_status' , '(`user_id`, `status`, `create_time`)' );
CALL sp_add_index_if_not_exists ( 't_payment_order' , 'idx_t_payment_order_shop_status' , '(`shop_id`, `status`, `create_time`)' );
CALL sp_add_index_if_not_exists ( 't_payment_order' , 'idx_t_payment_order_expire' , '(`status`, `expire_time`, `is_delete`)' );
CALL sp_add_unique_index_if_not_exists ( 't_refund_order' , 'uk_t_refund_order_refund_no' , '(`refund_no`)' );
CALL sp_add_unique_index_if_not_exists ( 't_refund_order' , 'uk_t_refund_order_idempotency' , '(`idempotency_key`)' );
CALL sp_add_index_if_not_exists ( 't_refund_order' , 'idx_t_refund_order_after_sale' , '(`after_sale_id`)' );
CALL sp_add_index_if_not_exists ( 't_refund_order' , 'idx_t_refund_order_order_status' , '(`order_id`, `status`, `create_time`)' );
CALL sp_add_unique_index_if_not_exists ( 't_after_sale' , 'uk_t_after_sale_no' , '(`after_sale_no`)' );
CALL sp_add_index_if_not_exists ( 't_after_sale' , 'idx_t_after_sale_user_status' , '(`user_id`, `status`, `create_time`)' );
CALL sp_add_index_if_not_exists ( 't_after_sale' , 'idx_t_after_sale_shop_status' , '(`shop_id`, `status`, `create_time`)' );
CALL sp_add_index_if_not_exists ( 't_after_sale' , 'idx_t_after_sale_order' , '(`order_id`, `order_item_id`)' );
CALL sp_add_index_if_not_exists ( 't_after_sale_log' , 'idx_t_after_sale_log_after_sale' , '(`after_sale_id`, `create_time`)' );
CALL sp_add_index_if_not_exists ( 't_after_sale_log' , 'idx_t_after_sale_log_operator' , '(`operator_id`, `create_time`)' );
CALL sp_add_unique_index_if_not_exists ( 't_inventory_item' , 'uk_t_inventory_item_shop_name' , '(`shop_id`, `item_name`, `is_delete`)' );
CALL sp_add_index_if_not_exists ( 't_inventory_item' , 'idx_t_inventory_item_shop_status' , '(`shop_id`, `status`, `is_delete`)' );
CALL sp_add_index_if_not_exists ( 't_inventory_item' , 'idx_t_inventory_item_warning' , '(`shop_id`, `stock_quantity`, `warning_threshold`)' );
CALL sp_add_index_if_not_exists ( 't_inventory_record' , 'idx_t_inventory_record_item_time' , '(`inventory_item_id`, `create_time`)' );
CALL sp_add_index_if_not_exists ( 't_inventory_record' , 'idx_t_inventory_record_shop_time' , '(`shop_id`, `create_time`)' );
CALL sp_add_index_if_not_exists ( 't_campaign' , 'idx_t_campaign_shop_status' , '(`shop_id`, `status`, `is_delete`, `sort_order`)' );
CALL sp_add_index_if_not_exists ( 't_campaign' , 'idx_t_campaign_scene_time' , '(`scene`, `status`, `start_time`, `end_time`)' );
CALL sp_add_index_if_not_exists ( 't_user_growth_record' , 'idx_t_user_growth_user_time' , '(`user_id`, `create_time`)' );
CALL sp_add_index_if_not_exists ( 't_user_growth_record' , 'idx_t_user_growth_source' , '(`source_type`, `source_id`)' );
CALL sp_add_unique_index_if_not_exists ( 't_user_growth_record' , 'uk_t_user_growth_source_once' , '(`user_id`, `source_type`, `source_id`)' );
INSERT INTO t_permission ( id , permission_code , permission_name , permission_group , description , create_time , update_time , is_delete )
VALUES
( 313931273555136610 , 'schedule:view' , '查看排班' , '排班管理' , '查看美甲师排班和可约时段' , NOW (), NOW (), 0 ),
( 313931273555136611 , 'schedule:edit' , '编辑排班' , '排班管理' , '维护美甲师班次、休息日和预约容量' , NOW (), NOW (), 0 ),
( 313931273555136612 , 'payment:view' , '查看支付' , '支付退款' , '查看订单支付状态和支付单' , NOW (), NOW (), 0 ),
( 313931273555136613 , 'payment:manage' , '确认支付' , '支付退款' , '手工确认支付或处理支付异常' , NOW (), NOW (), 0 ),
( 313931273555136614 , 'refund:view' , '查看退款' , '支付退款' , '查看退款申请和退款单' , NOW (), NOW (), 0 ),
( 313931273555136615 , 'refund:manage' , '处理退款' , '支付退款' , '手工确认退款或处理退款异常' , NOW (), NOW (), 0 ),
( 313931273555136616 , 'after_sale:view' , '查看售后' , '售后管理' , '查看订单售后和客户反馈' , NOW (), NOW (), 0 ),
( 313931273555136617 , 'after_sale:audit' , '处理售后' , '售后管理' , '审批或驳回售后申请' , NOW (), NOW (), 0 ),
( 313931273555136618 , 'inventory:view' , '查看库存' , '库存管理' , '查看门店耗材库存和预警' , NOW (), NOW (), 0 ),
( 313931273555136619 , 'inventory:manage' , '调整库存' , '库存管理' , '维护耗材、入库和库存调整' , NOW (), NOW (), 0 ),
( 313931273555136620 , 'campaign:view' , '查看活动' , '活动管理' , '查看营销活动和推荐位' , NOW (), NOW (), 0 ),
( 313931273555136621 , 'campaign:manage' , '管理活动' , '活动管理' , '创建、编辑和发布营销活动' , NOW (), NOW (), 0 ),
( 313931273555136622 , 'growth:view' , '查看成长' , '用户成长' , '查看用户成长值和会员权益进度' , NOW (), NOW (), 0 ),
( 313931273555136623 , 'analytics:view' , '查看经营分析' , '经营分析' , '查看订单漏斗和经营指标' , NOW (), NOW (), 0 ),
( 313931273555136624 , 'performance:view' , '查看绩效' , '绩效统计' , '查看门店和美甲师服务绩效' , NOW (), NOW (), 0 ),
( 313931273555136625 , 'workbench:view' , '查看工作台' , '门店工作台' , '查看今日订单、售后待办、排班和绩效摘要' , NOW (), NOW (), 0 )
ON DUPLICATE KEY UPDATE
permission_name = VALUES ( permission_name ),
permission_group = VALUES ( permission_group ),
description = VALUES ( description ),
is_delete = 0 ,
update_time = NOW ();
2026-08-26 19:09:56 +08:00
2026-08-25 10:56:55 +08:00
CALL sp_add_column_if_not_exists ( 't_order' , 'customer_remark' , 'varchar(500) NULL COMMENT ''用户询价预约备注''' );
CALL sp_add_column_if_not_exists ( 't_order' , 'quote_status' , 'varchar(32) NULL COMMENT ''报价状态:CONFIRMING/CONFIRMED/EXPIRED''' );
CALL sp_add_column_if_not_exists ( 't_order' , 'quote_user_confirmed' , 'tinyint unsigned NOT NULL DEFAULT 0 COMMENT ''用户是否确认当前报价''' );
CALL sp_add_column_if_not_exists ( 't_order' , 'quote_shop_confirmed' , 'tinyint unsigned NOT NULL DEFAULT 0 COMMENT ''店长是否确认当前报价''' );
CALL sp_add_column_if_not_exists ( 't_order' , 'quote_expire_time' , 'datetime NULL COMMENT ''询价报价过期时间''' );
CALL sp_add_column_if_not_exists ( 't_order' , 'quote_confirmed_time' , 'datetime NULL COMMENT ''双方确认报价时间''' );
CALL sp_add_index_if_not_exists ( 't_order' , 'idx_t_order_quote_status_expire' , '(`quote_status`, `quote_expire_time`)' );
CALL sp_add_column_if_not_exists ( 't_order_item' , 'reference_price' , 'decimal(10,2) NULL COMMENT ''作品参考价快照''' );
CALL sp_add_column_if_not_exists ( 't_order_item' , 'quoted_price' , 'decimal(10,2) NULL COMMENT ''当前报价''' );
CALL sp_add_column_if_not_exists ( 't_order_item' , 'confirmed_price' , 'decimal(10,2) NULL COMMENT ''最终确认价''' );
CREATE TABLE IF NOT EXISTS t_order_quote_message
(
id bigint unsigned auto_increment comment '报价交互消息主键'
primary key ,
order_id bigint unsigned not null comment '订单ID' ,
actor_id bigint unsigned null comment '操作人ID' ,
actor_type varchar ( 32 ) not null comment '操作人类型:USER/SHOP/SYSTEM' ,
action varchar ( 32 ) not null comment '动作:CREATE/SHOP_QUOTE/USER_REPLY/USER_CONFIRM/SHOP_CONFIRM/SYSTEM_CONFIRM/SYSTEM_EXPIRE' ,
remark varchar ( 500 ) null comment '备注' ,
items_snapshot text null comment '订单项报价快照JSON' ,
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 '订单询价报价交互消息表' ;
CALL sp_add_index_if_not_exists ( 't_order_quote_message' , 'idx_order_quote_message_order_id' , '(`order_id`, `is_delete`, `create_time`)' );
CREATE TABLE IF NOT EXISTS ` t_messagehub_push_config ` (
` id ` bigint unsigned NOT NULL COMMENT '主键ID' ,
` scene_code ` varchar ( 80 ) NOT NULL COMMENT '业务场景编码' ,
` scene_name ` varchar ( 100 ) NOT NULL COMMENT '业务场景名称' ,
` platform ` varchar ( 20 ) NOT NULL DEFAULT 'SMS' COMMENT 'MessageHub 平台类型:SMS/EMAIL/QQ' ,
` msg_type ` varchar ( 30 ) NOT NULL DEFAULT 'VERIFICATION' COMMENT 'MessageHub 消息类型' ,
` queue_name ` varchar ( 100 ) NOT NULL DEFAULT 'smsQueue' COMMENT '投递到 MessageHub 的队列名' ,
` source_system ` varchar ( 80 ) NOT NULL DEFAULT 'jayucloud-salon' COMMENT 'MessageHub 来源系统编码' ,
` template_code ` varchar ( 100 ) NOT NULL COMMENT 'MessageHub 模板编码' ,
` channel_id ` bigint unsigned NULL COMMENT 'MessageHub 通道ID,不填则由 MessageHub 自动选择' ,
` send_method ` varchar ( 30 ) NULL COMMENT '兼容旧短信 DTO 的发送方式,如 SPUG/OTHER' ,
` enabled ` tinyint unsigned NOT NULL DEFAULT 1 COMMENT '是否启用:1-启用,0-停用' ,
` remark ` varchar ( 255 ) NULL COMMENT '备注' ,
` create_time ` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间' ,
` update_time ` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间' ,
` is_delete ` tinyint unsigned NOT NULL DEFAULT 0 COMMENT '逻辑删除:0-未删除,1-已删除' ,
PRIMARY KEY ( ` id ` ),
UNIQUE KEY ` uk_messagehub_push_config_scene ` ( ` scene_code ` ),
KEY ` idx_messagehub_push_config_enabled ` ( ` enabled ` , ` is_delete ` )
) COMMENT = 'Fingertip Designer按业务场景投递MessageHub的配置' ;
DROP PROCEDURE IF EXISTS sp_add_column_if_not_exists ;
DROP PROCEDURE IF EXISTS sp_add_index_if_not_exists ;
DROP PROCEDURE IF EXISTS sp_add_unique_index_if_not_exists ;
-- ========================================
-- 首次部署整合区:权限种子 / xiaowang 初始化 / 默认权限分配
-- 来源:2026-03-20_init_admin_permission_template.sql
-- ========================================
SET NAMES utf8mb4 ;
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:disable' , '启停用户' , '用户管理' , '启用或禁用用户账号' , NOW (), NOW (), 0 ),
( 'user:unbind' , '解绑用户' , '用户管理' , '解绑用户与当前店铺的关系' , NOW (), NOW (), 0 ),
( 'user:reset_password' , '重置密码' , '用户管理' , '重置用户密码' , NOW (), NOW (), 0 ),
( 'user:delete' , '删除用户' , '用户管理' , '删除用户账号' , NOW (), NOW (), 0 ),
( 'user:balance:view' , '查看余额资产' , '用户资产' , '查看用户余额、累计充值与流水' , NOW (), NOW (), 0 ),
( 'user:balance:manage' , '调整余额' , '用户资产' , '充值、手工加减余额与关联订单' , NOW (), NOW (), 0 ),
( 'user:vip:manage' , '管理VIP' , '用户资产' , '手工设置VIP等级或恢复自动判级' , 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 ),
( 'comment:view' , '查看评论' , '评论管理' , '查看作品评论与回复' , NOW (), NOW (), 0 ),
( 'comment:delete' , '删除评论' , '评论管理' , '删除不合规作品评论' , NOW (), NOW (), 0 ),
( 'order:view' , '查看订单' , '订单管理' , '查看订单列表与详情' , NOW (), NOW (), 0 ),
( 'order:process' , '处理订单' , '订单管理' , '处理订单状态或由美甲师完结订单' , NOW (), NOW (), 0 ),
( 'order:edit' , '编辑订单' , '订单管理' , '编辑订单信息的预留权限' , NOW (), NOW (), 0 ),
( 'order:delete' , '删除订单' , '订单管理' , '删除订单的预留权限' , NOW (), NOW (), 0 ),
( 'nail_artist:view' , '查看美甲师' , '美甲师管理' , '查看美甲师信息与排班入口' , NOW (), NOW (), 0 ),
( 'nail_artist:edit' , '编辑美甲师' , '美甲师管理' , '编辑美甲师信息' , NOW (), NOW (), 0 ),
( 'message:view' , '查看消息' , '消息管理' , '查看站内消息发布与通知' , NOW (), NOW (), 0 ),
( 'message:create' , '发布消息' , '消息管理' , '发布站内消息' , NOW (), NOW (), 0 ),
( 'message:delete' , '撤回消息' , '消息管理' , '撤回已发布站内消息' , NOW (), NOW (), 0 )
,
( 'announcement:view' , '查看公告' , '公告管理' , '查看公告列表与详情' , NOW (), NOW (), 0 ),
( 'announcement:create' , '发布公告' , '公告管理' , '发布公告' , NOW (), NOW (), 0 ),
( 'announcement:delete' , '撤回公告' , '公告管理' , '撤回已发布公告' , NOW (), NOW (), 0 )
ON DUPLICATE KEY UPDATE
permission_name = VALUES ( permission_name ),
permission_group = VALUES ( permission_group ),
description = VALUES ( description ),
update_time = NOW (),
is_delete = 0 ;
INSERT INTO t_permission ( id , permission_code , permission_name , permission_group , description , create_time , update_time , is_delete )
VALUES
( 910000000008001 , 'message:view' , '查看消息' , '消息管理' , '查看站内消息发布与通知' , NOW (), NOW (), 0 ),
( 910000000008002 , 'message:create' , '发布消息' , '消息管理' , '发布站内消息' , NOW (), NOW (), 0 ),
( 910000000008003 , 'message:delete' , '撤回消息' , '消息管理' , '撤回已发布站内消息' , NOW (), NOW (), 0 )
ON DUPLICATE KEY UPDATE
permission_name = VALUES ( permission_name ),
permission_group = VALUES ( permission_group ),
description = VALUES ( description ),
update_time = NOW (),
is_delete = 0 ;
INSERT INTO t_permission ( id , permission_code , permission_name , permission_group , description , create_time , update_time , is_delete )
VALUES
( 910000000008011 , 'announcement:view' , '查看公告' , '公告管理' , '查看公告列表与详情' , NOW (), NOW (), 0 ),
( 910000000008012 , 'announcement:create' , '发布公告' , '公告管理' , '发布公告' , NOW (), NOW (), 0 ),
( 910000000008013 , 'announcement:delete' , '撤回公告' , '公告管理' , '撤回已发布公告' , NOW (), NOW (), 0 )
ON DUPLICATE KEY UPDATE
permission_name = VALUES ( permission_name ),
permission_group = VALUES ( permission_group ),
description = VALUES ( description ),
update_time = NOW (),
is_delete = 0 ;
INSERT INTO t_permission ( permission_code , permission_name , permission_group , description , create_time , update_time , is_delete )
VALUES ( 'order:artist-change' , '处理改派申请' , '订单管理' , '处理订单美甲师改派申请' , NOW (), NOW (), 0 )
ON DUPLICATE KEY UPDATE
permission_name = VALUES ( permission_name ),
permission_group = VALUES ( permission_group ),
description = VALUES ( description ),
update_time = NOW (),
is_delete = 0 ;
INSERT INTO t_user (
shop_id ,
nickname ,
account ,
phone_verified ,
email_verified ,
password ,
signature ,
level ,
type ,
vip_id ,
create_time ,
update_time ,
is_delete ,
status
)
SELECT
0 ,
'系统管理员' ,
'xiaowang' ,
0 ,
0 ,
2026-08-26 19:09:56 +08:00
'$2a$10$3ZC5HHVK6EYIfkjcU9IHZulGXwNZhy.6LU85HRJC9A.3LHm0IEdMO' ,
2026-08-25 10:56:55 +08:00
'' ,
'管理员' ,
4 ,
0 ,
NOW (),
NOW (),
0 ,
1
WHERE NOT EXISTS (
SELECT 1
FROM t_user
WHERE account = 'xiaowang'
);
-- ========================================
-- 雪花 ID 口径收口区:去掉运行时主键表的 AUTO_INCREMENT
-- 说明:
-- 1. 前面的建表与基础配置种子继续沿用旧链路,保证空库初始化过程不受影响
-- 2. 本段将运行时已切到应用层雪花 ID 的主键表统一收口
-- 3. 后续基础配置插入均使用显式主键,与 2026-03-30_snowflake_id_alignment_patch.sql 保持同口径
-- ========================================
DROP PROCEDURE IF EXISTS sp_drop_auto_increment_on_id_if_exists ;
DELIMITER $$
CREATE PROCEDURE sp_drop_auto_increment_on_id_if_exists ( IN p_table_name VARCHAR ( 64 ))
BEGIN
DECLARE v_column_type VARCHAR ( 128 ) DEFAULT NULL ;
DECLARE v_column_comment VARCHAR ( 255 ) DEFAULT NULL ;
DECLARE v_extra VARCHAR ( 128 ) DEFAULT NULL ;
SELECT COLUMN_TYPE , COLUMN_COMMENT , EXTRA
INTO v_column_type , v_column_comment , v_extra
FROM information_schema . COLUMNS
WHERE TABLE_SCHEMA = DATABASE ()
AND TABLE_NAME = p_table_name
AND COLUMN_NAME = 'id'
LIMIT 1 ;
IF v_column_type IS NOT NULL AND v_extra LIKE '%auto_increment%' THEN
SET @ alter_sql = CONCAT (
'ALTER TABLE `' , p_table_name , '` MODIFY COLUMN `id` ' ,
v_column_type ,
' NOT NULL'
);
IF v_column_comment IS NOT NULL AND v_column_comment <> '' THEN
SET @ alter_sql = CONCAT ( @ alter_sql , ' COMMENT ' , QUOTE ( v_column_comment ));
END IF ;
PREPARE stmt FROM @ alter_sql ;
EXECUTE stmt ;
DEALLOCATE PREPARE stmt ;
END IF ;
END $$
DELIMITER ;
CALL sp_drop_auto_increment_on_id_if_exists ( 't_balance' );
CALL sp_drop_auto_increment_on_id_if_exists ( 't_balance_change_detail' );
CALL sp_drop_auto_increment_on_id_if_exists ( 't_cart' );
CALL sp_drop_auto_increment_on_id_if_exists ( 't_comment' );
CALL sp_drop_auto_increment_on_id_if_exists ( 't_coupon' );
CALL sp_drop_auto_increment_on_id_if_exists ( 't_coupon_tag' );
CALL sp_drop_auto_increment_on_id_if_exists ( 't_effect_diagram' );
CALL sp_drop_auto_increment_on_id_if_exists ( 't_login_identity' );
CALL sp_drop_auto_increment_on_id_if_exists ( 't_wechat_mini_binding' );
CALL sp_drop_auto_increment_on_id_if_exists ( 't_nail_artist_info' );
CALL sp_drop_auto_increment_on_id_if_exists ( 't_object_storage_file' );
CALL sp_drop_auto_increment_on_id_if_exists ( 't_order' );
CALL sp_drop_auto_increment_on_id_if_exists ( 't_order_item' );
CALL sp_drop_auto_increment_on_id_if_exists ( 't_permission' );
CALL sp_drop_auto_increment_on_id_if_exists ( 't_product' );
CALL sp_drop_auto_increment_on_id_if_exists ( 't_product_like' );
CALL sp_drop_auto_increment_on_id_if_exists ( 't_shop' );
CALL sp_drop_auto_increment_on_id_if_exists ( 't_tag' );
CALL sp_drop_auto_increment_on_id_if_exists ( 't_user' );
CALL sp_drop_auto_increment_on_id_if_exists ( 't_user_coupon' );
CALL sp_drop_auto_increment_on_id_if_exists ( 't_user_permission' );
CALL sp_drop_auto_increment_on_id_if_exists ( 't_vip_benefit' );
CALL sp_drop_auto_increment_on_id_if_exists ( 't_vip_info' );
CALL sp_drop_auto_increment_on_id_if_exists ( 't_wishlist_group' );
CALL sp_drop_auto_increment_on_id_if_exists ( 't_wishlist' );
CALL sp_drop_auto_increment_on_id_if_exists ( 't_user_shop_binding' );
CALL sp_drop_auto_increment_on_id_if_exists ( 't_system_message' );
CALL sp_drop_auto_increment_on_id_if_exists ( 't_system_message_user_state' );
CALL sp_drop_auto_increment_on_id_if_exists ( 't_announcement' );
CALL sp_drop_auto_increment_on_id_if_exists ( 't_vip_recharge_plan' );
CALL sp_drop_auto_increment_on_id_if_exists ( 't_artist_schedule' );
CALL sp_drop_auto_increment_on_id_if_exists ( 't_appointment_reservation' );
CALL sp_drop_auto_increment_on_id_if_exists ( 't_payment_order' );
CALL sp_drop_auto_increment_on_id_if_exists ( 't_refund_order' );
CALL sp_drop_auto_increment_on_id_if_exists ( 't_after_sale' );
CALL sp_drop_auto_increment_on_id_if_exists ( 't_after_sale_log' );
CALL sp_drop_auto_increment_on_id_if_exists ( 't_inventory_item' );
CALL sp_drop_auto_increment_on_id_if_exists ( 't_inventory_record' );
CALL sp_drop_auto_increment_on_id_if_exists ( 't_campaign' );
CALL sp_drop_auto_increment_on_id_if_exists ( 't_user_growth_record' );
DROP PROCEDURE IF EXISTS sp_drop_auto_increment_on_id_if_exists ;
CREATE TABLE IF NOT EXISTS t_shop_role (
id BIGINT UNSIGNED NOT NULL COMMENT '店铺角色ID' PRIMARY KEY ,
shop_id BIGINT UNSIGNED NOT NULL COMMENT '店铺ID' ,
role_name VARCHAR ( 100 ) NOT NULL COMMENT '角色名称' ,
creator_id BIGINT UNSIGNED NULL COMMENT '创建人' ,
status TINYINT UNSIGNED NOT NULL DEFAULT 1 COMMENT '状态' ,
remark VARCHAR ( 255 ) NULL COMMENT '备注' ,
sort_order INT NOT NULL DEFAULT 0 COMMENT '排序' ,
create_time DATETIME DEFAULT CURRENT_TIMESTAMP NOT NULL ,
update_time DATETIME DEFAULT CURRENT_TIMESTAMP NOT NULL ON UPDATE CURRENT_TIMESTAMP ,
is_delete TINYINT UNSIGNED DEFAULT 0 COMMENT '逻辑删除'
) COMMENT = '店铺自定义角色表' ;
CREATE TABLE IF NOT EXISTS t_shop_role_permission (
id BIGINT UNSIGNED NOT NULL COMMENT '主键' PRIMARY KEY ,
role_id BIGINT UNSIGNED NOT NULL COMMENT '角色ID' ,
permission_id BIGINT UNSIGNED NOT NULL COMMENT '权限ID' ,
create_time DATETIME DEFAULT CURRENT_TIMESTAMP NOT NULL ,
update_time DATETIME DEFAULT CURRENT_TIMESTAMP NOT NULL ON UPDATE CURRENT_TIMESTAMP ,
is_delete TINYINT UNSIGNED DEFAULT 0
) COMMENT = '店铺角色权限关联表' ;
CREATE TABLE IF NOT EXISTS t_user_shop_role (
id BIGINT UNSIGNED NOT NULL COMMENT '主键' PRIMARY KEY ,
user_id BIGINT UNSIGNED NOT NULL COMMENT '用户ID' ,
shop_id BIGINT UNSIGNED NOT NULL COMMENT '店铺ID' ,
role_id BIGINT UNSIGNED NOT NULL COMMENT '角色ID' ,
status TINYINT UNSIGNED NOT NULL DEFAULT 1 COMMENT '状态' ,
create_time DATETIME DEFAULT CURRENT_TIMESTAMP NOT NULL ,
update_time DATETIME DEFAULT CURRENT_TIMESTAMP NOT NULL ON UPDATE CURRENT_TIMESTAMP ,
is_delete TINYINT UNSIGNED DEFAULT 0
) COMMENT = '用户店铺角色绑定表' ;
CREATE TABLE IF NOT EXISTS t_user_relation (
id BIGINT UNSIGNED NOT NULL COMMENT '主键' PRIMARY KEY ,
user_id BIGINT UNSIGNED NOT NULL COMMENT '用户ID' ,
shop_id BIGINT UNSIGNED NULL COMMENT '店铺ID' ,
parent_user_id BIGINT UNSIGNED NULL COMMENT '直属上级用户ID' ,
parent_role_type INT NULL COMMENT '上级身份类型' ,
source_type VARCHAR ( 32 ) NULL COMMENT '来源类型' ,
creator_id BIGINT UNSIGNED NULL COMMENT '创建人' ,
create_time DATETIME DEFAULT CURRENT_TIMESTAMP NOT NULL ,
update_time DATETIME DEFAULT CURRENT_TIMESTAMP NOT NULL ON UPDATE CURRENT_TIMESTAMP ,
is_delete TINYINT UNSIGNED DEFAULT 0
) COMMENT = '用户归属关系表' ;
CREATE TABLE IF NOT EXISTS t_user_invite_code (
id BIGINT UNSIGNED NOT NULL COMMENT '主键' PRIMARY KEY ,
invite_code VARCHAR ( 64 ) NOT NULL COMMENT '邀请码' ,
owner_user_id BIGINT UNSIGNED NOT NULL COMMENT '所属人' ,
shop_id BIGINT UNSIGNED NOT NULL COMMENT '店铺ID' ,
status TINYINT UNSIGNED NOT NULL DEFAULT 1 COMMENT '状态' ,
use_count INT NOT NULL DEFAULT 0 COMMENT '使用次数' ,
expire_time DATETIME NULL COMMENT '过期时间' ,
create_time DATETIME DEFAULT CURRENT_TIMESTAMP NOT NULL ,
update_time DATETIME DEFAULT CURRENT_TIMESTAMP NOT NULL ON UPDATE CURRENT_TIMESTAMP ,
is_delete TINYINT UNSIGNED DEFAULT 0 ,
UNIQUE KEY uk_invite_code ( invite_code )
) COMMENT = '邀请码表' ;
INSERT INTO t_permission ( id , permission_code , permission_name , permission_group , description , create_time , update_time , is_delete )
VALUES
( 313931273555136490 , 'messagehub:config:manage' , '管理消息参数' , '参数管理' , '管理地图 Key、短信 MessageHub 等平台参数' , NOW (), NOW (), 0 )
ON DUPLICATE KEY UPDATE
permission_name = VALUES ( permission_name ),
permission_group = VALUES ( permission_group ),
description = VALUES ( description ),
is_delete = 0 ,
update_time = NOW ();
INSERT INTO t_messagehub_push_config (
id ,
scene_code ,
scene_name ,
platform ,
msg_type ,
queue_name ,
source_system ,
template_code ,
channel_id ,
send_method ,
enabled ,
remark ,
create_time ,
update_time ,
is_delete
)
VALUES
( 313931273555137001 , 'USER_REGISTER_SMS_CODE' , '用户注册验证码' , 'SMS' , 'VERIFICATION' , 'smsQueue' , 'jayucloud-salon' , 'SPUG0001' , NULL , 'SPUG' , 1 , '注册功能发送验证码时使用' , NOW (), NOW (), 0 ),
( 313931273555137002 , 'USER_LOGIN_SMS_CODE' , '手机号登录验证码' , 'SMS' , 'VERIFICATION' , 'smsQueue' , 'jayucloud-salon' , 'SPUG0001' , NULL , 'SPUG' , 1 , '手机号验证码登录时使用' , NOW (), NOW (), 0 ),
( 313931273555137003 , 'USER_RESET_PASSWORD_SMS_CODE' , '找回密码验证码' , 'SMS' , 'VERIFICATION' , 'smsQueue' , 'jayucloud-salon' , 'SPUG0001' , NULL , 'SPUG' , 1 , '找回密码时使用' , NOW (), NOW (), 0 ),
( 313931273555137004 , 'USER_BIND_PHONE_SMS_CODE' , '绑定手机号验证码' , 'SMS' , 'VERIFICATION' , 'smsQueue' , 'jayucloud-salon' , 'SPUG0001' , NULL , 'SPUG' , 1 , '绑定手机号时使用' , NOW (), NOW (), 0 ),
( 313931273555137005 , 'USER_CHANGE_PHONE_SMS_CODE' , '修改手机号验证码' , 'SMS' , 'VERIFICATION' , 'smsQueue' , 'jayucloud-salon' , 'SPUG0001' , NULL , 'SPUG' , 1 , '修改手机号时使用' , NOW (), NOW (), 0 ),
( 313931273555137006 , 'USER_CHANGE_PASSWORD_SMS_CODE' , '修改密码验证码' , 'SMS' , 'VERIFICATION' , 'smsQueue' , 'jayucloud-salon' , 'SPUG0001' , NULL , 'SPUG' , 1 , '修改密码时使用' , NOW (), NOW (), 0 )
ON DUPLICATE KEY UPDATE
scene_name = VALUES ( scene_name ),
platform = VALUES ( platform ),
msg_type = VALUES ( msg_type ),
queue_name = VALUES ( queue_name ),
source_system = VALUES ( source_system ),
template_code = VALUES ( template_code ),
channel_id = VALUES ( channel_id ),
send_method = VALUES ( send_method ),
enabled = VALUES ( enabled ),
remark = VALUES ( remark ),
is_delete = 0 ,
update_time = NOW ();
INSERT INTO t_permission ( id , permission_code , permission_name , permission_group , description , create_time , update_time , is_delete )
VALUES
( 313931273555136501 , 'role:view' , '查看店铺角色' , '角色管理' , '查看店铺自定义角色' , NOW (), NOW (), 0 ),
( 313931273555136502 , 'role:create' , '新增店铺角色' , '角色管理' , '创建店铺自定义角色' , NOW (), NOW (), 0 ),
( 313931273555136503 , 'role:edit' , '编辑店铺角色' , '角色管理' , '编辑角色权限和绑定员工' , NOW (), NOW (), 0 ),
( 313931273555136504 , 'role:delete' , '删除店铺角色' , '角色管理' , '删除店铺自定义角色' , NOW (), NOW (), 0 ),
( 313931273555136505 , 'user:relation:view' , '查看用户所属' , '用户管理' , '查看用户归属关系' , NOW (), NOW (), 0 ),
( 313931273555136506 , 'user:relation:edit' , '编辑用户所属' , '用户管理' , '调整用户店铺和直属上级' , NOW (), NOW (), 0 )
ON DUPLICATE KEY UPDATE
id = VALUES ( id ),
permission_name = VALUES ( permission_name ),
permission_group = VALUES ( permission_group ),
description = VALUES ( description ),
is_delete = 0 ,
update_time = NOW ();
-- 2026-05-18 协议管理、用户协议同意记录与安全审计日志
CREATE TABLE IF NOT EXISTS t_legal_agreement (
id bigint NOT NULL COMMENT '协议ID' ,
agreement_type varchar ( 32 ) NOT NULL COMMENT '协议类型:USER_TERMS/PRIVACY_POLICY' ,
title varchar ( 100 ) NOT NULL COMMENT '协议标题' ,
version varchar ( 32 ) NOT NULL COMMENT '协议版本号' ,
content longtext NOT NULL COMMENT '协议正文' ,
status tinyint NOT NULL DEFAULT 0 COMMENT '状态:0草稿/停用,1已发布启用' ,
effective_time datetime NULL COMMENT '生效时间' ,
create_time datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间' ,
update_time datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间' ,
is_delete tinyint NOT NULL DEFAULT 0 COMMENT '逻辑删除:0否,1是' ,
PRIMARY KEY ( id ),
UNIQUE KEY uk_legal_agreement_type_version ( agreement_type , version , is_delete ),
KEY idx_legal_agreement_current ( agreement_type , status , effective_time , is_delete )
) ENGINE = InnoDB DEFAULT CHARSET = utf8mb4 COMMENT = '用户协议与隐私政策' ;
CREATE TABLE IF NOT EXISTS t_user_agreement_consent (
id bigint NOT NULL COMMENT '同意记录ID' ,
user_id bigint NOT NULL COMMENT '用户ID' ,
agreement_type varchar ( 32 ) NOT NULL COMMENT '协议类型' ,
version varchar ( 32 ) NOT NULL COMMENT '同意版本号' ,
entry varchar ( 64 ) NULL COMMENT '同意入口:login/register/phone-login/wechat-mini' ,
client_type varchar ( 32 ) NULL COMMENT '客户端类型:WEB/WECHAT_MINI' ,
ip_address varchar ( 64 ) NULL COMMENT '同意IP' ,
device_id varchar ( 128 ) NULL COMMENT '设备ID' ,
consent_time datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '同意时间' ,
create_time datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间' ,
update_time datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间' ,
PRIMARY KEY ( id ),
UNIQUE KEY uk_user_agreement_consent ( user_id , agreement_type , version ),
KEY idx_user_agreement_user ( user_id , agreement_type )
) ENGINE = InnoDB DEFAULT CHARSET = utf8mb4 COMMENT = '用户协议同意记录' ;
CREATE TABLE IF NOT EXISTS t_security_audit_log (
id bigint NOT NULL COMMENT '审计日志ID' ,
user_id bigint NULL COMMENT '操作用户ID' ,
account varchar ( 100 ) NULL COMMENT '操作账号' ,
action varchar ( 64 ) NOT NULL COMMENT '安全动作' ,
result varchar ( 32 ) NOT NULL COMMENT '结果:SUCCESS/FAIL' ,
reason varchar ( 255 ) NULL COMMENT '失败或补充原因' ,
ip_address varchar ( 64 ) NULL COMMENT '请求IP' ,
device_id varchar ( 128 ) NULL COMMENT '设备ID' ,
operate_time datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '操作时间' ,
create_time datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间' ,
update_time datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间' ,
PRIMARY KEY ( id ),
KEY idx_security_audit_action_time ( action , operate_time ),
KEY idx_security_audit_account_time ( account , operate_time )
) ENGINE = InnoDB DEFAULT CHARSET = utf8mb4 COMMENT = '安全审计日志' ;
CREATE TABLE IF NOT EXISTS t_system_parameter_config (
id bigint NOT NULL COMMENT '配置ID' ,
config_group varchar ( 50 ) NOT NULL COMMENT '配置分组' ,
config_key varchar ( 100 ) NOT NULL COMMENT '配置键' ,
config_name varchar ( 100 ) NOT NULL COMMENT '配置名称' ,
config_value varchar ( 1000 ) NULL COMMENT '配置值' ,
enabled tinyint NOT NULL DEFAULT 1 COMMENT '是否启用:1启用,0停用' ,
remark varchar ( 255 ) NULL COMMENT '备注' ,
create_time datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间' ,
update_time datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间' ,
is_delete tinyint NOT NULL DEFAULT 0 COMMENT '逻辑删除:0否,1是' ,
PRIMARY KEY ( id ),
UNIQUE KEY uk_system_parameter_group_key ( config_group , config_key , is_delete )
) ENGINE = InnoDB DEFAULT CHARSET = utf8mb4 COMMENT = '系统参数配置' ;
SET @ system_parameter_enabled_missing : = (
SELECT COUNT ( 1 ) = 0
FROM information_schema . COLUMNS
WHERE TABLE_SCHEMA = DATABASE ()
AND TABLE_NAME = 't_system_parameter_config'
AND COLUMN_NAME = 'enabled'
);
SET @ system_parameter_enabled_sql : = IF (
@ system_parameter_enabled_missing ,
'ALTER TABLE t_system_parameter_config ADD COLUMN enabled tinyint NOT NULL DEFAULT 1 COMMENT ''是否启用:1启用,0停用'' AFTER config_value' ,
'SELECT 1'
);
PREPARE stmt_system_parameter_enabled FROM @ system_parameter_enabled_sql ;
EXECUTE stmt_system_parameter_enabled ;
DEALLOCATE PREPARE stmt_system_parameter_enabled ;
INSERT INTO t_legal_agreement ( id , agreement_type , title , version , content , status , effective_time , create_time , update_time , is_delete )
VALUES
( 313931273555138001 , 'USER_TERMS' , '用户协议' , '2026.05.18' , '欢迎使用 Fingertip Designer 指尖设计师。请在使用账号、预约、订单、会员、消息等功能前仔细阅读本协议。继续登录或注册即表示你已理解并同意平台基础服务规则、账号安全要求、订单预约规则和依法合规使用要求。' , 1 , NOW (), NOW (), NOW (), 0 ),
( 313931273555138002 , 'PRIVACY_POLICY' , '隐私政策' , '2026.05.18' , 'Fingertip Designer 指尖设计师会在提供登录注册、预约下单、会员余额、消息通知和客户服务时处理必要的手机号、昵称、门店归属、订单与设备信息。我们仅在业务需要和法律允许范围内使用这些信息,并采取访问控制、脱敏展示和审计记录等措施保护数据安全。' , 1 , NOW (), NOW (), NOW (), 0 )
ON DUPLICATE KEY UPDATE
title = VALUES ( title ),
content = VALUES ( content ),
status = VALUES ( status ),
effective_time = VALUES ( effective_time ),
is_delete = 0 ,
update_time = NOW ();
INSERT INTO t_permission ( id , permission_code , permission_name , permission_group , description , create_time , update_time , is_delete )
VALUES
( 313931273555136601 , 'legal_agreement:manage' , '管理协议' , '协议管理' , '管理用户协议和隐私政策版本' , NOW (), NOW (), 0 )
ON DUPLICATE KEY UPDATE
permission_name = VALUES ( permission_name ),
permission_group = VALUES ( permission_group ),
description = VALUES ( description ),
is_delete = 0 ,
update_time = NOW ();
INSERT INTO t_system_parameter_config (
id , config_group , config_key , config_name , config_value , enabled , remark , create_time , update_time , is_delete
)
VALUES
( 313931273555139000 , 'MAP' , 'MAP_PROVIDER' , '当前地图渠道' , 'TENCENT' , 1 , 'TENCENT 或 AMAP;决定后台店铺选点默认使用哪个地图渠道' , NOW (), NOW (), 0 ),
( 313931273555139001 , 'MAP' , 'TENCENT_MAP_KEY' , '腾讯 Web Key' , '' , 0 , '用于后台腾讯地图选点和 Web 展示;请在后台参数管理中填入真实 Key 后启用' , NOW (), NOW (), 0 ),
( 313931273555139002 , 'MAP' , 'AMAP_WEB_KEY' , '高德 Web Key' , '' , 0 , '用于后台高德地图选点和 Web 展示;Web 端 Key 与小程序 Key 分开维护' , NOW (), NOW (), 0 ),
( 313931273555139003 , 'MAP' , 'AMAP_MINI_KEY' , '高德小程序 Key' , '' , 0 , '用于后续小程序端高德 SDK/API 调用;不要与 Web Key 混用' , NOW (), NOW (), 0 ),
( 313931273555139004 , 'USER' , 'DEFAULT_PASSWORD' , '后台新增用户默认密码' , 'Fingertip@123' , 1 , '后台新增用户不填写密码时使用;需满足 8-32 位且至少包含数字、小写字母、大写字母、特殊符号中的 3 类' , NOW (), NOW (), 0 )
ON DUPLICATE KEY UPDATE
config_name = VALUES ( config_name ),
remark = VALUES ( remark ),
config_value = IF ( t_system_parameter_config . config_key = 'MAP_PROVIDER' AND ( t_system_parameter_config . config_value IS NULL OR t_system_parameter_config . config_value = '' ), VALUES ( config_value ), t_system_parameter_config . config_value ),
is_delete = 0 ,
update_time = NOW ();
-- 最小运行初始化:确保 xiaowang 拥有当前权限目录中的全部权限。
INSERT INTO t_user_permission ( id , user_id , permission_id , create_time , update_time , create_by , update_by , is_delete )
SELECT
313931273556000000 + p . id ,
u . id ,
p . id ,
NOW (),
NOW (),
u . id ,
u . id ,
0
FROM t_user u
INNER JOIN t_permission p
ON p . is_delete = 0
WHERE u . account = 'xiaowang'
AND u . is_delete = 0
AND u . type = 4
ON DUPLICATE KEY UPDATE
is_delete = 0 ,
update_by = VALUES ( update_by ),
update_time = NOW ();
INSERT INTO t_permission ( id , permission_code , permission_name , permission_group , description , create_time , update_time , is_delete )
VALUES
( 313931273555136602 , 'security:audit:view' , '查看安全审计' , '安全审计' , '查看高危操作和登录安全审计日志' , NOW (), NOW (), 0 )
ON DUPLICATE KEY UPDATE
permission_name = VALUES ( permission_name ),
permission_group = VALUES ( permission_group ),
description = VALUES ( description ),
is_delete = 0 ,
update_time = NOW ();
-- 最终权限兜底:确保平台管理员拥有当前权限目录中的全部基础权限。
INSERT INTO t_user_permission ( id , user_id , permission_id , create_time , update_time , create_by , update_by , is_delete )
SELECT
( CAST ( u . id AS UNSIGNED ) << 20 ) + ( CAST ( p . id AS UNSIGNED ) & 1048575 ),
u . id ,
p . id ,
NOW (),
NOW (),
0 ,
0 ,
0
FROM t_user u
INNER JOIN t_permission p
ON p . is_delete = 0
WHERE u . account = 'xiaowang'
AND u . is_delete = 0
AND u . type = 4
ON DUPLICATE KEY UPDATE
is_delete = 0 ,
update_by = VALUES ( update_by ),
update_time = NOW ();
2026-08-26 19:09:56 +08:00
-- 排班规则与例外
CREATE TABLE IF NOT EXISTS t_artist_schedule_rule (
id bigint unsigned NOT NULL COMMENT '排班规则ID' , shop_id bigint unsigned NOT NULL COMMENT '店铺ID' , artist_id bigint unsigned NOT NULL COMMENT '美甲师用户ID' , preset_type varchar ( 32 ) NOT NULL COMMENT '预设类型' , work_days varchar ( 32 ) NOT NULL COMMENT '工作星期,1-7逗号分隔' , start_time time NOT NULL COMMENT '常规开始时间' , end_time time NOT NULL COMMENT '常规结束时间' , slot_minutes int NOT NULL DEFAULT 60 COMMENT '预约间隔分钟' , capacity int NOT NULL DEFAULT 1 COMMENT '同一时间段容量' , status tinyint NOT NULL DEFAULT 1 COMMENT '状态:1启用,0停用' , remark varchar ( 255 ) NULL COMMENT '备注' , create_time datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间' , update_time datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间' , is_delete tinyint NOT NULL DEFAULT 0 COMMENT '逻辑删除' , PRIMARY KEY ( id ), UNIQUE KEY uk_artist_schedule_rule_artist ( shop_id , artist_id , is_delete ), KEY idx_artist_schedule_rule_shop_status ( shop_id , status , is_delete )
) ENGINE = InnoDB DEFAULT CHARSET = utf8mb4 COMMENT = '美甲师常规排班规则表' ;
CREATE TABLE IF NOT EXISTS t_artist_schedule_exception (
id bigint unsigned NOT NULL COMMENT '排班例外ID' , shop_id bigint unsigned NOT NULL COMMENT '店铺ID' , artist_id bigint unsigned NOT NULL COMMENT '美甲师用户ID' , work_date date NOT NULL COMMENT '例外日期' , exception_type varchar ( 32 ) NOT NULL COMMENT '例外类型:REST/EXTRA_WORK/CHANGE_SHIFT' , start_time time NULL COMMENT '例外开始时间' , end_time time NULL COMMENT '例外结束时间' , slot_minutes int NOT NULL DEFAULT 60 COMMENT '预约间隔分钟' , capacity int NOT NULL DEFAULT 1 COMMENT '同一时间段容量' , remark varchar ( 255 ) NULL COMMENT '备注' , create_time datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间' , update_time datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间' , is_delete tinyint NOT NULL DEFAULT 0 COMMENT '逻辑删除' , PRIMARY KEY ( id ), UNIQUE KEY uk_artist_schedule_exception_date ( shop_id , artist_id , work_date , is_delete ), KEY idx_artist_schedule_exception_artist_date ( artist_id , work_date , is_delete )
) ENGINE = InnoDB DEFAULT CHARSET = utf8mb4 COMMENT = '美甲师排班例外表' ;
SET FOREIGN_KEY_CHECKS = 0 ;
DROP TABLE IF EXISTS t_wishlist ; DROP TABLE IF EXISTS t_wishlist_group ; DROP TABLE IF EXISTS t_product_like ; DROP TABLE IF EXISTS t_cart ; DROP TABLE IF EXISTS t_vip_info ; DROP TABLE IF EXISTS t_vip_benefit ; DROP TABLE IF EXISTS t_user_growth_record ; DROP TABLE IF EXISTS t_user_coupon ; DROP TABLE IF EXISTS t_coupon_tag ; DROP TABLE IF EXISTS t_coupon ;
SET FOREIGN_KEY_CHECKS = 1 ;