功能:完善门店能力与用户安全配置
This commit is contained in:
@@ -1,228 +0,0 @@
|
||||
-- 2026-03-20 空库初始化模板:admin01 / 权限种子 / 最终权限分配
|
||||
-- 执行前置:
|
||||
-- 1. 已执行 YumiNail.sql
|
||||
-- 2. 已执行 2026-03-20_user_asset_vip_coupon_permission_patch.sql
|
||||
-- 说明:
|
||||
-- 1. 本文件负责空库初始化模板,不覆盖原始 YumiNail.sql
|
||||
-- 2. admin01 会显式写入后台默认权限,不再依赖 type=4 的运行时全权限兜底
|
||||
-- 3. 本文件的 t_user_permission 只负责“按用户类型初始化默认权限”,不会删除已有的自定义分配;如果要严格重置已有数据库,请先手工清理旧的 t_user_permission 数据
|
||||
use nailart;
|
||||
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),
|
||||
('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)
|
||||
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,
|
||||
'系统管理员',
|
||||
'admin01',
|
||||
0,
|
||||
0,
|
||||
'$2a$10$9v.6PztWy3.vmJiVMaOyKuWeVqAnpuHB3hQ3Dgiuz6L8IwBe7Cn9W',
|
||||
'',
|
||||
'管理员',
|
||||
4,
|
||||
0,
|
||||
NOW(),
|
||||
NOW(),
|
||||
0,
|
||||
1
|
||||
WHERE NOT EXISTS (
|
||||
SELECT 1
|
||||
FROM t_user
|
||||
WHERE account = 'admin01'
|
||||
);
|
||||
|
||||
-- 如需严格按当前默认矩阵重置已有后台用户的权限,请先手工执行类似清理 SQL:
|
||||
-- DELETE up
|
||||
-- FROM t_user_permission up
|
||||
-- INNER JOIN t_user u ON u.id = up.user_id
|
||||
-- WHERE u.type IN (2, 3, 4);
|
||||
|
||||
INSERT INTO t_user_permission (user_id, permission_id, create_time, update_time, create_by, update_by, is_delete)
|
||||
SELECT 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
|
||||
AND p.permission_code IN (
|
||||
'home:view',
|
||||
'dashboard:view',
|
||||
'user:view',
|
||||
'user:create',
|
||||
'user:edit',
|
||||
'user:disable',
|
||||
'user:unbind',
|
||||
'user:reset_password',
|
||||
'user:delete',
|
||||
'user:balance:view',
|
||||
'product:view',
|
||||
'shop:view',
|
||||
'shop:create',
|
||||
'shop:edit',
|
||||
'shop:delete',
|
||||
'shop:staff:manage',
|
||||
'permission:view',
|
||||
'permission:create',
|
||||
'permission:edit',
|
||||
'permission:delete',
|
||||
'permission:assign',
|
||||
'tag:view',
|
||||
'coupon:view',
|
||||
'order:view',
|
||||
'nail_artist:view'
|
||||
)
|
||||
WHERE u.is_delete = 0
|
||||
AND u.type = 4
|
||||
AND NOT EXISTS (
|
||||
SELECT 1
|
||||
FROM t_user_permission up
|
||||
WHERE up.user_id = u.id
|
||||
AND up.permission_id = p.id
|
||||
);
|
||||
|
||||
INSERT INTO t_user_permission (user_id, permission_id, create_time, update_time, create_by, update_by, is_delete)
|
||||
SELECT 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
|
||||
AND p.permission_code IN (
|
||||
'home:view',
|
||||
'dashboard:view',
|
||||
'user:view',
|
||||
'user:create',
|
||||
'user:edit',
|
||||
'user:unbind',
|
||||
'user:reset_password',
|
||||
'user:balance:view',
|
||||
'user:balance:manage',
|
||||
'user:vip:manage',
|
||||
'product:view',
|
||||
'product:create',
|
||||
'product:edit',
|
||||
'product:delete',
|
||||
'product:category:manage',
|
||||
'shop:view',
|
||||
'shop:edit',
|
||||
'shop:staff:manage',
|
||||
'permission:view',
|
||||
'permission:assign',
|
||||
'tag:view',
|
||||
'tag:create',
|
||||
'tag:edit',
|
||||
'tag:delete',
|
||||
'tag:assign',
|
||||
'coupon:view',
|
||||
'coupon:create',
|
||||
'coupon:edit',
|
||||
'coupon:delete',
|
||||
'coupon:assign',
|
||||
'order:view',
|
||||
'order:process',
|
||||
'order:edit',
|
||||
'order:delete',
|
||||
'nail_artist:view',
|
||||
'nail_artist:edit'
|
||||
)
|
||||
WHERE u.is_delete = 0
|
||||
AND u.type = 2
|
||||
AND NOT EXISTS (
|
||||
SELECT 1
|
||||
FROM t_user_permission up
|
||||
WHERE up.user_id = u.id
|
||||
AND up.permission_id = p.id
|
||||
);
|
||||
|
||||
INSERT INTO t_user_permission (user_id, permission_id, create_time, update_time, create_by, update_by, is_delete)
|
||||
SELECT 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
|
||||
AND p.permission_code IN (
|
||||
'home:view',
|
||||
'user:view',
|
||||
'user:create',
|
||||
'user:balance:view',
|
||||
'product:view',
|
||||
'product:create',
|
||||
'shop:view',
|
||||
'tag:view',
|
||||
'tag:create',
|
||||
'coupon:view',
|
||||
'order:view',
|
||||
'order:process'
|
||||
)
|
||||
WHERE u.is_delete = 0
|
||||
AND u.type = 3
|
||||
AND NOT EXISTS (
|
||||
SELECT 1
|
||||
FROM t_user_permission up
|
||||
WHERE up.user_id = u.id
|
||||
AND up.permission_id = p.id
|
||||
);
|
||||
|
||||
-- 普通用户不初始化后台权限;当前仅允许前台登录和前台业务访问。
|
||||
-329
@@ -1,329 +0,0 @@
|
||||
-- 2026-03-20 用户资产 / VIP / 优惠券增量补丁
|
||||
-- 适用前提:已先执行 YumiNail.sql 完成基础建表
|
||||
-- 执行说明:
|
||||
-- 1. 本文件只做增量修正,不覆盖原始 YumiNail.sql
|
||||
-- 2. 当前推荐执行链路:YumiNail.sql -> 本补丁 -> 2026-03-20_init_admin_permission_template.sql
|
||||
-- 3. 本补丁仅负责结构补列、索引补齐、VIP 规则与 VIP 自动券模板;权限种子、admin01 初始化与 t_user_permission 模板已迁移到独立初始化模板 SQL
|
||||
-- 4. 历史累计充值金额无法从旧表精确反推,本补丁仅把缺失值归零;如需保留历史累计充值,请按业务数据手工回填 total_recharge_amount
|
||||
use nailart;
|
||||
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 ''最近一次充值时间''');
|
||||
|
||||
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 ''备注''');
|
||||
|
||||
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', 'coupon_source_type', 'varchar(32) NULL COMMENT ''优惠来源类型''');
|
||||
|
||||
UPDATE t_order
|
||||
SET coupon_id = NULL
|
||||
WHERE coupon_id = 0;
|
||||
|
||||
UPDATE t_order o
|
||||
INNER JOIN (
|
||||
SELECT oi.order_id, MIN(p.shop_id) AS resolved_shop_id
|
||||
FROM t_order_item oi
|
||||
INNER JOIN t_product p ON p.id = oi.product_id
|
||||
GROUP BY oi.order_id
|
||||
) detail_shop ON detail_shop.order_id = o.id
|
||||
SET o.shop_id = detail_shop.resolved_shop_id
|
||||
WHERE o.shop_id IS NULL;
|
||||
|
||||
UPDATE t_order
|
||||
SET coupon_source_type = 'USER_COUPON'
|
||||
WHERE coupon_source_type IS NULL
|
||||
AND coupon_id IS NOT NULL;
|
||||
|
||||
CALL sp_add_index_if_not_exists('t_order', 'idx_t_order_shop_id', '(`shop_id`)');
|
||||
CALL sp_add_index_if_not_exists('t_order', 'idx_t_order_coupon_source_type', '(`coupon_source_type`)');
|
||||
|
||||
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`)');
|
||||
|
||||
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);
|
||||
|
||||
-- 权限种子、admin01 初始化与最终的 t_user_permission 分配规则,
|
||||
-- 已迁移到 2026-03-20_init_admin_permission_template.sql 统一维护。
|
||||
|
||||
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 = '黄金'
|
||||
);
|
||||
|
||||
INSERT INTO t_coupon (
|
||||
coupon_code,
|
||||
coupon_name,
|
||||
coupon_type,
|
||||
discount_value,
|
||||
min_amount,
|
||||
reduce_amount,
|
||||
total_count,
|
||||
used_count,
|
||||
start_time,
|
||||
end_time,
|
||||
status,
|
||||
create_time,
|
||||
update_time,
|
||||
is_delete,
|
||||
shop_id,
|
||||
coupon_scene,
|
||||
required_vip_level,
|
||||
auto_match
|
||||
)
|
||||
VALUES
|
||||
('VIP_AUTO_BRONZE_95', '青铜VIP自动95折券', 1, 9.50, 0.00, 0.00, 999999, 0, NOW(), '2099-12-31 23:59:59', 1, NOW(), NOW(), 0, NULL, 'VIP_AUTO', '青铜', 1),
|
||||
('VIP_AUTO_SILVER_92', '白银VIP自动92折券', 1, 9.20, 0.00, 0.00, 999999, 0, NOW(), '2099-12-31 23:59:59', 1, NOW(), NOW(), 0, NULL, 'VIP_AUTO', '白银', 1),
|
||||
('VIP_AUTO_GOLD_90', '黄金VIP自动90折券', 1, 9.00, 0.00, 0.00, 999999, 0, NOW(), '2099-12-31 23:59:59', 1, NOW(), NOW(), 0, NULL, 'VIP_AUTO', '黄金', 1)
|
||||
ON DUPLICATE KEY UPDATE
|
||||
coupon_name = VALUES(coupon_name),
|
||||
coupon_type = VALUES(coupon_type),
|
||||
discount_value = VALUES(discount_value),
|
||||
min_amount = VALUES(min_amount),
|
||||
reduce_amount = VALUES(reduce_amount),
|
||||
total_count = VALUES(total_count),
|
||||
status = VALUES(status),
|
||||
is_delete = VALUES(is_delete),
|
||||
shop_id = VALUES(shop_id),
|
||||
coupon_scene = VALUES(coupon_scene),
|
||||
required_vip_level = VALUES(required_vip_level),
|
||||
auto_match = VALUES(auto_match),
|
||||
update_time = NOW();
|
||||
|
||||
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;
|
||||
-165
@@ -1,165 +0,0 @@
|
||||
-- 2026-03-25 多店铺登录 / 店铺状态 / 用户店铺绑定补丁
|
||||
-- 推荐执行顺序:
|
||||
-- 1. YumiNail.sql
|
||||
-- 2. 2026-03-20_user_asset_vip_coupon_permission_patch.sql
|
||||
-- 3. 2026-03-25_user_shop_binding_and_shop_status_patch.sql
|
||||
-- 4. 2026-03-20_init_admin_permission_template.sql
|
||||
--
|
||||
-- 说明:
|
||||
-- 1. 本文件不覆盖主建表 SQL,只补结构与历史数据回填。
|
||||
-- 2. 本补丁会新增 t_user_shop_binding,并把现有 t_user.shop_id 回填为默认绑定关系。
|
||||
-- 3. t_shop.status 用于店铺启停;停用后不删除绑定,只禁止该店铺登录。
|
||||
|
||||
use nailart;
|
||||
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-停用''');
|
||||
|
||||
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;
|
||||
|
||||
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;
|
||||
-29
@@ -1,29 +0,0 @@
|
||||
-- 为历史美甲师账号补齐“处理订单”默认权限
|
||||
-- 说明:
|
||||
-- 1. 该补丁可重复执行
|
||||
-- 2. 仅影响 type = 3 的美甲师账号
|
||||
-- 3. 若现有系统已通过后台登录触发默认权限同步,也可以不手工执行本文件
|
||||
|
||||
INSERT INTO t_permission (permission_code, permission_name, permission_group, description, create_time, update_time, is_delete)
|
||||
SELECT 'order:process', '处理订单', '订单管理', '处理订单状态或由美甲师完结订单', NOW(), NOW(), 0
|
||||
WHERE NOT EXISTS (
|
||||
SELECT 1
|
||||
FROM t_permission
|
||||
WHERE permission_code = 'order:process'
|
||||
AND is_delete = 0
|
||||
);
|
||||
|
||||
INSERT INTO t_user_permission (user_id, permission_id, create_time, update_time, create_by, update_by, is_delete)
|
||||
SELECT u.id, p.id, NOW(), NOW(), 0, 0, 0
|
||||
FROM t_user u
|
||||
INNER JOIN t_permission p
|
||||
ON p.permission_code = 'order:process'
|
||||
AND p.is_delete = 0
|
||||
WHERE u.is_delete = 0
|
||||
AND u.type = 3
|
||||
AND NOT EXISTS (
|
||||
SELECT 1
|
||||
FROM t_user_permission up
|
||||
WHERE up.user_id = u.id
|
||||
AND up.permission_id = p.id
|
||||
);
|
||||
@@ -1,74 +0,0 @@
|
||||
-- YumiNail 雪花 ID 主键口径对齐补丁
|
||||
-- 适用场景:
|
||||
-- 1. 已经执行过旧版 YumiNail.sql 的存量库
|
||||
-- 2. 需要将运行时已切到应用层雪花 ID 的表,去掉数据库侧 AUTO_INCREMENT
|
||||
--
|
||||
-- 注意:
|
||||
-- 1. 如果你的数据库名不是 nailart,请先修改下面的 use 语句
|
||||
-- 2. 本补丁不会改动已有数据,只会调整 id 列定义
|
||||
|
||||
USE nailart;
|
||||
|
||||
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_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');
|
||||
CALL sp_drop_auto_increment_on_id_if_exists('t_user_shop_binding');
|
||||
|
||||
DROP PROCEDURE IF EXISTS sp_drop_auto_increment_on_id_if_exists;
|
||||
@@ -1,55 +0,0 @@
|
||||
CREATE TABLE IF NOT EXISTS t_wechat_mini_binding
|
||||
(
|
||||
id BIGINT UNSIGNED NOT NULL COMMENT '微信小程序绑定主键ID(雪花ID)',
|
||||
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 '更新时间',
|
||||
PRIMARY KEY (id)
|
||||
) COMMENT = '微信小程序账号绑定表';
|
||||
|
||||
DROP PROCEDURE IF EXISTS sp_add_index_if_not_exists;
|
||||
DELIMITER $$
|
||||
CREATE PROCEDURE sp_add_index_if_not_exists(
|
||||
IN p_table_name VARCHAR(64),
|
||||
IN p_index_name VARCHAR(64),
|
||||
IN p_index_sql 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 @index_sql = p_index_sql;
|
||||
PREPARE stmt FROM @index_sql;
|
||||
EXECUTE stmt;
|
||||
DEALLOCATE PREPARE stmt;
|
||||
END IF;
|
||||
END$$
|
||||
DELIMITER ;
|
||||
|
||||
CALL sp_add_index_if_not_exists(
|
||||
't_wechat_mini_binding',
|
||||
'idx_wechat_mini_unionid',
|
||||
'CREATE INDEX idx_wechat_mini_unionid ON t_wechat_mini_binding (unionid)'
|
||||
);
|
||||
|
||||
CALL sp_add_index_if_not_exists(
|
||||
't_wechat_mini_binding',
|
||||
'uk_wechat_mini_app_openid',
|
||||
'ALTER TABLE t_wechat_mini_binding ADD CONSTRAINT uk_wechat_mini_app_openid UNIQUE (app_id, openid)'
|
||||
);
|
||||
|
||||
CALL sp_add_index_if_not_exists(
|
||||
't_wechat_mini_binding',
|
||||
'uk_wechat_mini_app_user',
|
||||
'ALTER TABLE t_wechat_mini_binding ADD CONSTRAINT uk_wechat_mini_app_user UNIQUE (app_id, user_id)'
|
||||
);
|
||||
|
||||
DROP PROCEDURE IF EXISTS sp_add_index_if_not_exists;
|
||||
@@ -1,661 +0,0 @@
|
||||
-- 用户余额信息表
|
||||
create table t_balance
|
||||
(
|
||||
id bigint unsigned auto_increment comment '余额记录唯一主键ID(雪花ID)'
|
||||
primary key comment '余额表主键索引',
|
||||
user_id bigint unsigned not null comment '关联用户表主键',
|
||||
amount decimal(10, 2) default 0.00 not null comment '当前余额',
|
||||
create_time datetime default CURRENT_TIMESTAMP not null comment '余额账户创建时间',
|
||||
last_update_time datetime default CURRENT_TIMESTAMP not null on update CURRENT_TIMESTAMP comment '最近一次更新时间',
|
||||
constraint uk_user_id
|
||||
unique (user_id) comment '用户余额唯一索引(一个用户对应一条余额记录)'
|
||||
)
|
||||
comment '用户余额信息表';
|
||||
-- 用户余额变动明细表
|
||||
create table t_balance_change_detail
|
||||
(
|
||||
id bigint unsigned auto_increment comment '变动记录唯一主键ID(雪花ID)'
|
||||
primary key comment '余额变动明细主键索引',
|
||||
user_id bigint unsigned not null comment '关联用户表主键',
|
||||
amount decimal(10, 2) not null comment '本次变动金额(正数为增加,负数为减少)',
|
||||
type varchar(20) not null comment '变动类型(如充值、消费、退款)',
|
||||
current_balance decimal(10, 2) not null comment '变动后的当前余额',
|
||||
change_time datetime default CURRENT_TIMESTAMP not null comment '变动时间'
|
||||
)
|
||||
comment '用户余额变动明细表';
|
||||
|
||||
create index idx_change_time
|
||||
on t_balance_change_detail (change_time)
|
||||
comment '按时间查询余额变动的索引';
|
||||
|
||||
create index idx_user_id
|
||||
on t_balance_change_detail (user_id)
|
||||
comment '按用户查询余额变动的索引';
|
||||
|
||||
-- 用户评论信息表
|
||||
create table t_comment
|
||||
(
|
||||
id bigint unsigned auto_increment comment '评论唯一主键ID(雪花ID)'
|
||||
primary key comment '评论主键索引',
|
||||
user_id bigint unsigned not null comment '评论用户ID,关联用户表主键',
|
||||
shop_id bigint unsigned default 0 null comment '关联店铺表主键(0表示非店铺评论)',
|
||||
product_id bigint unsigned default 0 null comment '关联商品表主键(0表示非商品评论)',
|
||||
comment_content text not null comment '评论内容',
|
||||
parent_comment_id bigint unsigned default 0 null comment '父级评论ID(0表示为根评论)',
|
||||
like_count int unsigned default 0 null comment '评论点赞数',
|
||||
create_time datetime default CURRENT_TIMESTAMP not null comment '评论创建时间',
|
||||
update_time datetime default CURRENT_TIMESTAMP not null on update CURRENT_TIMESTAMP comment '评论更新时间',
|
||||
is_delete tinyint unsigned default 0 null comment '逻辑删除标识:0-未删除,1-已删除'
|
||||
)
|
||||
comment '用户评论信息表';
|
||||
|
||||
create index idx_parent_comment_id
|
||||
on t_comment (parent_comment_id)
|
||||
comment '按父级评论查询回复的索引';
|
||||
|
||||
create index idx_product_id
|
||||
on t_comment (product_id)
|
||||
comment '按商品查询评论的索引';
|
||||
|
||||
create index idx_shop_id
|
||||
on t_comment (shop_id)
|
||||
comment '按店铺查询评论的索引';
|
||||
|
||||
create index idx_user_id
|
||||
on t_comment (user_id)
|
||||
comment '按用户查询评论的索引';
|
||||
|
||||
|
||||
|
||||
-- 商品效果图信息表
|
||||
create table t_effect_diagram
|
||||
(
|
||||
id bigint unsigned auto_increment comment '效果图唯一主键ID(雪花id)'
|
||||
primary key comment '效果图主键索引',
|
||||
product_id bigint unsigned not null comment '所属商品ID,关联商品表主键',
|
||||
category varchar(50) default '' null comment '效果图类别',
|
||||
image_file_ids text null comment '图片文件ID集合,多ID以逗号分隔',
|
||||
description text null comment '效果图描述',
|
||||
price decimal(10, 2) default 0.00 null comment '效果图对应服务价格',
|
||||
duration varchar(50) default '' null comment '效果图对应服务耗时',
|
||||
tag varchar(50) default '' null comment '效果图标签',
|
||||
like_count int unsigned default 0 null comment '效果图点赞数',
|
||||
create_time datetime default CURRENT_TIMESTAMP not null comment '创建时间',
|
||||
update_time datetime default CURRENT_TIMESTAMP not null on update CURRENT_TIMESTAMP comment '更新时间',
|
||||
is_delete tinyint unsigned default 0 null comment '逻辑删除:0-未删,1-已删'
|
||||
)
|
||||
comment '商品效果图信息表';
|
||||
|
||||
create index idx_product_id
|
||||
on t_effect_diagram (product_id)
|
||||
comment '按商品查询效果图的索引';
|
||||
|
||||
-- 用户登录标识信息表
|
||||
create table t_login_identity
|
||||
(
|
||||
id bigint unsigned auto_increment comment '登录标识唯一主键ID(雪花id)'
|
||||
primary key comment '登录标识主键索引',
|
||||
user_id bigint unsigned not null comment '关联用户表主键',
|
||||
login_method varchar(50) not null comment '登录方式(0-手机号、1-账号、2-邮箱)',
|
||||
input_value varchar(100) not null comment '前端输入的具体值(如手机号、账号、邮箱)',
|
||||
input_time datetime not null comment '输入时间',
|
||||
update_time datetime default CURRENT_TIMESTAMP not null on update CURRENT_TIMESTAMP comment '更新时间',
|
||||
status tinyint unsigned default 1 null comment '状态:1-有效,0-无效'
|
||||
)
|
||||
comment '用户登录标识信息表';
|
||||
|
||||
create index idx_login_method
|
||||
on t_login_identity (login_method)
|
||||
comment '按登录方式查询的索引';
|
||||
|
||||
create index idx_user_id
|
||||
on t_login_identity (user_id)
|
||||
comment '按用户查询登录标识的索引';
|
||||
|
||||
-- 对象存储文件信息表
|
||||
create table t_object_storage_file
|
||||
(
|
||||
id bigint unsigned auto_increment comment '文件记录唯一主键ID(雪花ID)'
|
||||
primary key comment '对象存储文件主键索引',
|
||||
file_name varchar(100) not null comment '文件名称',
|
||||
file_url text not null comment '文件访问链接',
|
||||
create_time datetime default CURRENT_TIMESTAMP not null comment '文件上传时间',
|
||||
update_time datetime default CURRENT_TIMESTAMP not null on update CURRENT_TIMESTAMP comment '文件更新时间',
|
||||
status tinyint unsigned default 1 null comment '文件状态:1-可用,0-不可用,2-回收站',
|
||||
delete_time datetime null comment '文件删除时间(NULL表示未删除)',
|
||||
recycle_time datetime null comment '文件移入回收站时间(NULL表示未移入)'
|
||||
)
|
||||
comment '对象存储文件信息表';
|
||||
|
||||
create index idx_status
|
||||
on t_object_storage_file (status)
|
||||
comment '按文件状态查询的索引';
|
||||
|
||||
|
||||
-- 系统权限表
|
||||
create table t_permission
|
||||
(
|
||||
id bigint unsigned auto_increment comment '权限唯一主键ID'
|
||||
primary key,
|
||||
permission_code varchar(100) not null comment '权限编码(唯一标识)',
|
||||
permission_name varchar(100) not null comment '权限名称',
|
||||
permission_group varchar(50) not null comment '权限分组(商品管理、用户管理等)',
|
||||
description varchar(255) null comment '权限描述',
|
||||
create_time datetime default CURRENT_TIMESTAMP not null comment '创建时间',
|
||||
update_time datetime default CURRENT_TIMESTAMP not null on update CURRENT_TIMESTAMP comment '更新时间',
|
||||
is_delete tinyint unsigned default 0 null comment '逻辑删除:0-未删,1-已删',
|
||||
constraint uk_permission_code
|
||||
unique (permission_code) comment '权限编码唯一索引'
|
||||
)
|
||||
comment '系统权限表';
|
||||
|
||||
-- 商品信息表
|
||||
create table t_product
|
||||
(
|
||||
id bigint unsigned auto_increment comment '商品唯一主键ID(雪花id)'
|
||||
primary key comment '商品主键索引',
|
||||
shop_id bigint unsigned not null comment '所属店铺ID,关联店铺表主键',
|
||||
title varchar(100) not null comment '商品标题',
|
||||
description text null comment '商品描述',
|
||||
image_file_ids text null comment '图片文件ID集合,多个ID以逗号分隔',
|
||||
price decimal(10, 2) not null comment '商品价格,保留2位小数',
|
||||
tags varchar(512) default '' null comment '标签集合,多个标签以逗号分隔,最多5个',
|
||||
like_count int unsigned default 0 null comment '商品点赞数',
|
||||
collect_count int unsigned default 0 null comment '商品收藏数',
|
||||
approximate_duration varchar(50) default '' null comment '商品对应的服务大约耗时(如“30分钟”)',
|
||||
bookable_artists varchar(200) default '' null comment '可预约的美甲师ID集合,多个ID以逗号分隔',
|
||||
available_coupons text null comment '可用的优惠券ID集合,多个ID以逗号分隔',
|
||||
create_time datetime default CURRENT_TIMESTAMP not null comment '商品创建时间',
|
||||
update_time datetime default CURRENT_TIMESTAMP not null on update CURRENT_TIMESTAMP comment '商品信息最后更新时间',
|
||||
is_delete tinyint unsigned default 0 null comment '逻辑删除标识:0-未删除,1-已删除'
|
||||
)
|
||||
comment '商品信息表';
|
||||
|
||||
create index idx_price
|
||||
on t_product (price)
|
||||
comment '按价格筛选商品的索引';
|
||||
|
||||
create index idx_shop_id
|
||||
on t_product (shop_id)
|
||||
comment '按所属店铺查询商品的索引';
|
||||
|
||||
create index idx_tags
|
||||
on t_product (tags)
|
||||
comment '按标签筛选商品的索引';
|
||||
|
||||
create index idx_title
|
||||
on t_product (title)
|
||||
comment '商品标题搜索的索引';
|
||||
|
||||
-- 店铺信息表
|
||||
create table t_shop
|
||||
(
|
||||
id bigint unsigned comment '店铺唯一主键ID(雪花ID)'
|
||||
primary key comment '店铺主键索引',
|
||||
shop_name varchar(100) not null comment '店铺名称',
|
||||
description text null comment '店铺描述',
|
||||
address varchar(200) not null comment '店铺地址',
|
||||
business_hours varchar(100) default '' null comment '店铺营业时间',
|
||||
cover_image_file_id varchar(50) default '' null comment '店铺封面图文件ID',
|
||||
create_time datetime default CURRENT_TIMESTAMP not null comment '创建时间',
|
||||
update_time datetime default CURRENT_TIMESTAMP not null on update CURRENT_TIMESTAMP comment '更新时间',
|
||||
is_delete tinyint unsigned default 0 null comment '逻辑删除:0-未删,1-已删',
|
||||
image_file_ids text null comment '图片文件ID集合,多个ID以逗号分隔'
|
||||
)
|
||||
comment '店铺信息表';
|
||||
|
||||
create index idx_shop_name
|
||||
on t_shop (shop_name)
|
||||
comment '按店铺名称查询的索引';
|
||||
|
||||
|
||||
-- 系统标签信息表
|
||||
create table t_tag
|
||||
(
|
||||
id bigint unsigned auto_increment comment '标签唯一主键ID'
|
||||
primary key comment '标签主键索引',
|
||||
tag_name varchar(50) not null comment '标签名称',
|
||||
text_color varchar(20) default '#333333' null comment '标签文字颜色(16进制)',
|
||||
bg_color varchar(20) default '#FFFFFF' null comment '标签背景颜色(16进制)',
|
||||
border_color varchar(20) default '#E5E5E5' null comment '标签边框颜色(16进制)',
|
||||
create_time datetime default CURRENT_TIMESTAMP not null comment '创建时间',
|
||||
update_time datetime default CURRENT_TIMESTAMP not null on update CURRENT_TIMESTAMP comment '更新时间',
|
||||
is_delete tinyint unsigned default 0 null comment '逻辑删除:0-未删,1-已删',
|
||||
shop_id bigint null comment '店铺ID',
|
||||
constraint uk_tag_name
|
||||
unique (tag_name) comment '标签名称唯一索引'
|
||||
)
|
||||
comment '系统标签信息表';
|
||||
|
||||
-- 系统用户信息表
|
||||
create table t_user
|
||||
(
|
||||
id bigint unsigned 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 '手机号',
|
||||
email varchar(100) null comment '邮箱',
|
||||
phone_verified tinyint unsigned default 0 null comment '手机号是否已验证:0-未验证,1-已验证',
|
||||
email_verified tinyint unsigned default 0 null comment '邮箱是否已验证:0-未验证,1-已验证',
|
||||
password varchar(100) not null comment '用户密码(加密存储)',
|
||||
signature varchar(200) default '' null comment '用户签名',
|
||||
level varchar(20) default '普通' null comment '用户等级',
|
||||
type tinyint not null comment '用户类型,(0-用户,2-店长,3-美甲师,4-管理员)',
|
||||
vip_id bigint unsigned default 0 null comment '关联VIP信息表主键(0表示非VIP)',
|
||||
create_time datetime default CURRENT_TIMESTAMP not null comment '创建时间',
|
||||
update_time datetime default CURRENT_TIMESTAMP not null on update CURRENT_TIMESTAMP comment '更新时间',
|
||||
is_delete tinyint unsigned default 0 null comment '逻辑删除:0-未删,1-已删',
|
||||
status tinyint unsigned default 1 null comment '用户状态:1-正常,0-禁用',
|
||||
avatar varchar(512) null comment '头像链接',
|
||||
constraint uk_account
|
||||
unique (account) comment '用户账号唯一索引'
|
||||
)
|
||||
comment '系统用户信息表';
|
||||
|
||||
create index idx_email
|
||||
on t_user (email)
|
||||
comment '按邮箱查询的索引';
|
||||
|
||||
create index idx_phone
|
||||
on t_user (phone)
|
||||
comment '按手机号查询的索引';
|
||||
|
||||
create index idx_shop_id
|
||||
on t_user (shop_id)
|
||||
comment '按店铺查询用户的索引';
|
||||
|
||||
create index idx_type
|
||||
on t_user (type)
|
||||
comment '按用户类型查询的索引';
|
||||
|
||||
-- 用户权限关联表
|
||||
create table t_user_permission
|
||||
(
|
||||
id bigint unsigned auto_increment comment '关联ID'
|
||||
primary key,
|
||||
user_id bigint unsigned not null comment '用户ID',
|
||||
permission_id bigint unsigned not null comment '权限ID',
|
||||
create_time datetime default CURRENT_TIMESTAMP not null comment '创建时间',
|
||||
update_time datetime default CURRENT_TIMESTAMP not null on update CURRENT_TIMESTAMP comment '更新时间',
|
||||
create_by bigint unsigned null comment '创建人ID',
|
||||
update_by bigint unsigned null comment '更新人ID',
|
||||
is_delete tinyint unsigned default 0 null comment '逻辑删除:0-未删,1-已删',
|
||||
constraint uk_user_permission
|
||||
unique (user_id, permission_id) comment '用户-权限唯一索引'
|
||||
)
|
||||
comment '用户权限关联表';
|
||||
|
||||
create index idx_permission_id
|
||||
on t_user_permission (permission_id)
|
||||
comment '权限ID索引';
|
||||
|
||||
create index idx_user_id
|
||||
on t_user_permission (user_id)
|
||||
comment '用户ID索引';
|
||||
|
||||
|
||||
-- VIP权益信息表
|
||||
create table t_vip_benefit
|
||||
(
|
||||
id bigint unsigned auto_increment comment 'VIP权益唯一主键ID(雪花ID)'
|
||||
primary key comment 'VIP权益主键索引',
|
||||
benefit_info text not null comment '权益详情(如折扣、专属服务)',
|
||||
required_vip_level varchar(20) not null comment '所需VIP等级',
|
||||
create_time datetime default CURRENT_TIMESTAMP not null comment '创建时间',
|
||||
update_time datetime default CURRENT_TIMESTAMP not null on update CURRENT_TIMESTAMP comment '更新时间'
|
||||
)
|
||||
comment 'VIP权益信息表';
|
||||
|
||||
create index idx_required_vip_level
|
||||
on t_vip_benefit (required_vip_level)
|
||||
comment '按VIP等级查询权益的索引';
|
||||
|
||||
-- 用户VIP信息表
|
||||
create table t_vip_info
|
||||
(
|
||||
id bigint unsigned auto_increment comment 'VIP信息唯一主键ID(雪花ID)'
|
||||
primary key comment 'VIP信息主键索引',
|
||||
vip_level varchar(20) not null comment 'VIP等级(如青铜、白银)',
|
||||
start_time datetime not null comment 'VIP开通时间',
|
||||
expire_time datetime not null comment 'VIP到期时间',
|
||||
activation_method varchar(50) not null comment 'VIP开通方式(如购买、赠送)',
|
||||
benefit_id bigint unsigned not null comment '关联VIP权益信息表主键',
|
||||
create_time datetime default CURRENT_TIMESTAMP not null comment '创建时间',
|
||||
update_time datetime default CURRENT_TIMESTAMP not null on update CURRENT_TIMESTAMP comment '更新时间'
|
||||
)
|
||||
comment '用户VIP信息表';
|
||||
|
||||
create index idx_vip_level
|
||||
on t_vip_info (vip_level)
|
||||
comment '按VIP等级查询的索引';
|
||||
|
||||
|
||||
|
||||
-- 清空现有数据
|
||||
DELETE FROM t_user_permission WHERE 1=1;
|
||||
DELETE FROM t_permission WHERE 1=1;
|
||||
DELETE FROM t_user WHERE 1=1;
|
||||
|
||||
-- 插入完整的系统权限
|
||||
INSERT INTO t_permission (permission_code, permission_name, permission_group, description, create_time, update_time, is_delete) VALUES
|
||||
-- 首页权限
|
||||
('home:view', '查看首页', '首页', '查看系统首页', NOW(), NOW(), 0),
|
||||
|
||||
-- 仪表盘权限
|
||||
('dashboard:view', '查看仪表盘', '仪表盘', '查看系统仪表盘', NOW(), NOW(), 0),
|
||||
|
||||
-- 用户管理权限
|
||||
('user:view', '查看用户', '用户管理', '查看用户列表和详情', NOW(), NOW(), 0),
|
||||
('user:create', '新增用户', '用户管理', '新增用户', NOW(), NOW(), 0),
|
||||
('user:edit', '编辑用户', '用户管理', '编辑用户信息', NOW(), NOW(), 0),
|
||||
('user:reset_password', '重置密码', '用户管理', '重置用户密码', NOW(), NOW(), 0),
|
||||
('user:delete', '删除用户', '用户管理', '删除用户', NOW(), NOW(), 0),
|
||||
|
||||
-- 商品管理权限
|
||||
('product:view', '查看商品', '商品管理', '查看商品列表和详情', NOW(), NOW(), 0),
|
||||
('product:create', '新增商品', '商品管理', '新增商品', NOW(), NOW(), 0),
|
||||
('product:edit', '编辑商品', '商品管理', '编辑商品信息', NOW(), NOW(), 0),
|
||||
('product:delete', '删除商品', '商品管理', '删除商品', NOW(), NOW(), 0),
|
||||
('product:category:manage', '管理商品分类', '商品管理', '管理商品分类', NOW(), NOW(), 0),
|
||||
|
||||
-- 店铺管理权限
|
||||
('shop:view', '查看店铺', '店铺管理', '查看店铺列表和详情', NOW(), NOW(), 0),
|
||||
('shop:create', '新增店铺', '店铺管理', '新增店铺', NOW(), NOW(), 0),
|
||||
('shop:edit', '编辑店铺', '店铺管理', '编辑店铺信息', NOW(), NOW(), 0),
|
||||
('shop:delete', '删除店铺', '店铺管理', '删除店铺', NOW(), NOW(), 0),
|
||||
('shop:staff:manage', '管理店铺员工', '店铺管理', '管理店铺员工', NOW(), NOW(), 0),
|
||||
|
||||
-- 权限管理权限
|
||||
('permission:view', '查看权限', '权限管理', '查看权限列表', NOW(), NOW(), 0),
|
||||
('permission:create', '新增权限', '权限管理', '新增系统权限', NOW(), NOW(), 0),
|
||||
('permission:edit', '编辑权限', '权限管理', '编辑系统权限', NOW(), NOW(), 0),
|
||||
('permission:delete', '删除权限', '权限管理', '删除系统权限', NOW(), NOW(), 0),
|
||||
('permission:assign', '分配权限', '权限管理', '为用户分配权限', NOW(), NOW(), 0),
|
||||
|
||||
-- 标签管理权限
|
||||
('tag:view', '查看标签', '标签管理', '查看标签列表和详情', NOW(), NOW(), 0),
|
||||
('tag:create', '新增标签', '标签管理', '新增标签', NOW(), NOW(), 0),
|
||||
('tag:edit', '编辑标签', '标签管理', '编辑标签信息', NOW(), NOW(), 0),
|
||||
('tag:delete', '删除标签', '标签管理', '删除标签', NOW(), NOW(), 0),
|
||||
('tag:assign', '分配标签', '标签管理', '为商品分配标签', NOW(), NOW(), 0),
|
||||
|
||||
-- 优惠券管理权限
|
||||
('coupon:view', '查看优惠券', '优惠券管理', '查看优惠券列表和详情', NOW(), NOW(), 0),
|
||||
('coupon:create', '新增优惠券', '优惠券管理', '新增优惠券', NOW(), NOW(), 0),
|
||||
('coupon:edit', '编辑优惠券', '优惠券管理', '编辑优惠券信息', NOW(), NOW(), 0),
|
||||
('coupon:delete', '删除优惠券', '优惠券管理', '删除优惠券', NOW(), NOW(), 0),
|
||||
('coupon:assign', '分配优惠券', '优惠券管理', '为用户分配优惠券', NOW(), NOW(), 0),
|
||||
|
||||
-- 订单管理权限
|
||||
('order:view', '查看订单', '订单管理', '查看订单列表和详情', NOW(), NOW(), 0),
|
||||
('order:edit', '编辑订单', '订单管理', '编辑订单信息', NOW(), NOW(), 0),
|
||||
('order:delete', '删除订单', '订单管理', '删除订单', NOW(), NOW(), 0),
|
||||
('order:process', '处理订单', '订单管理', '处理订单状态', NOW(), NOW(), 0);
|
||||
|
||||
-- 初始化admin用户,密码为123456
|
||||
-- 密码使用BCrypt加密,123456的加密值为:$2a$10$EixZaYVK1fsbw1ZfbX3OXePaWxn96p36WQoeG6Lruj3vjPGga31lW
|
||||
INSERT INTO t_user (id, shop_id, nickname, account, password, type, status, create_time, update_time, is_delete) VALUES
|
||||
(1, 0, '管理员', 'admin', '$2a$10$EixZaYVK1fsbw1ZfbX3OXePaWxn96p36WQoeG6Lruj3vjPGga31lW', 4, 1, NOW(), NOW(), 0);
|
||||
|
||||
-- 为管理员分配权限
|
||||
-- 首页的全部权限
|
||||
-- 仪表盘的全部权限
|
||||
-- 所有店铺的用户管理的全部权限
|
||||
-- 所有店铺的商品管理的查看权限,无新增编辑删除管理商品分类权限
|
||||
-- 所有店铺的店铺管理的全部权限
|
||||
-- 所有店铺的权限管理的全部权限
|
||||
-- 所有店铺的标签管理的查看权限无新增编辑删除权限
|
||||
-- 所有店铺的优惠券管理的查看权限
|
||||
-- 所有店铺的订单管理的查看权限
|
||||
INSERT INTO t_user_permission (user_id, permission_id, create_time, update_time, create_by)
|
||||
SELECT
|
||||
1 as user_id,
|
||||
p.id as permission_id,
|
||||
NOW() as create_time,
|
||||
NOW() as update_time,
|
||||
1 as create_by
|
||||
FROM t_permission p
|
||||
WHERE p.is_delete = 0
|
||||
AND p.permission_code IN (
|
||||
'home:view',
|
||||
'dashboard:view',
|
||||
'user:view',
|
||||
'user:create',
|
||||
'user:edit',
|
||||
'user:reset_password',
|
||||
'user:delete',
|
||||
'product:view',
|
||||
'shop:view',
|
||||
'shop:create',
|
||||
'shop:edit',
|
||||
'shop:delete',
|
||||
'shop:staff:manage',
|
||||
'permission:view',
|
||||
'permission:create',
|
||||
'permission:edit',
|
||||
'permission:delete',
|
||||
'permission:assign',
|
||||
'tag:view',
|
||||
'coupon:view',
|
||||
'order:view'
|
||||
);
|
||||
|
||||
-- 注意:店长和美甲师的权限需要在系统中手动分配,因为需要关联具体的店铺
|
||||
-- 这里只初始化管理员的权限
|
||||
|
||||
-- 优惠券信息表
|
||||
create table t_coupon
|
||||
(
|
||||
id bigint unsigned auto_increment comment '优惠券唯一主键ID'
|
||||
primary key comment '优惠券主键索引',
|
||||
coupon_code varchar(50) not null comment '优惠券编码',
|
||||
coupon_name varchar(100) not null comment '优惠券名称',
|
||||
coupon_type tinyint not null comment '优惠券类型:1-折扣券,2-满减券',
|
||||
discount_value decimal(10, 2) default 0.00 null comment '折扣值(如9.5表示95折)',
|
||||
min_amount decimal(10, 2) default 0.00 null comment '满减券最低消费金额',
|
||||
reduce_amount decimal(10, 2) default 0.00 null comment '满减券减免金额',
|
||||
total_count int unsigned default 100 not null comment '优惠券总数量',
|
||||
used_count int unsigned default 0 not null comment '已使用数量',
|
||||
start_time datetime not null comment '开始时间',
|
||||
end_time datetime not null comment '结束时间',
|
||||
status tinyint unsigned default 1 not null comment '状态:1-可用,2-已过期,3-已用完',
|
||||
shop_id bigint unsigned not null comment '所属店铺ID',
|
||||
create_time datetime default CURRENT_TIMESTAMP not null comment '创建时间',
|
||||
update_time datetime default CURRENT_TIMESTAMP not null on update CURRENT_TIMESTAMP comment '更新时间',
|
||||
is_delete tinyint unsigned default 0 null comment '逻辑删除:0-未删,1-已删',
|
||||
constraint uk_coupon_code
|
||||
unique (coupon_code) comment '优惠券编码唯一索引'
|
||||
) comment '优惠券信息表';
|
||||
|
||||
create index idx_status
|
||||
on t_coupon (status) comment '按状态查询优惠券的索引';
|
||||
|
||||
create index idx_shop_id
|
||||
on t_coupon (shop_id) comment '按店铺查询优惠券的索引';
|
||||
|
||||
-- 用户优惠券关联表
|
||||
create table t_user_coupon
|
||||
(
|
||||
id bigint unsigned auto_increment comment '用户优惠券关联唯一主键ID'
|
||||
primary key comment '用户优惠券关联主键索引',
|
||||
user_id bigint unsigned not null comment '关联用户表主键',
|
||||
coupon_id bigint unsigned not null comment '关联优惠券表主键',
|
||||
status tinyint unsigned default 1 not null comment '状态:1-未使用,2-已使用,3-已过期',
|
||||
obtain_time datetime default CURRENT_TIMESTAMP not null comment '获取时间',
|
||||
use_time datetime null comment '使用时间',
|
||||
create_time datetime default CURRENT_TIMESTAMP not null comment '创建时间',
|
||||
update_time datetime default CURRENT_TIMESTAMP not null on update CURRENT_TIMESTAMP comment '更新时间',
|
||||
is_delete tinyint unsigned default 0 null comment '逻辑删除:0-未删,1-已删',
|
||||
constraint uk_user_coupon
|
||||
unique (user_id, coupon_id) comment '用户-优惠券唯一索引'
|
||||
) comment '用户优惠券关联表';
|
||||
|
||||
create index idx_status
|
||||
on t_user_coupon (status) comment '按状态查询用户优惠券的索引';
|
||||
|
||||
create index idx_user_id
|
||||
on t_user_coupon (user_id) comment '按用户查询优惠券的索引';
|
||||
|
||||
-- 优惠券标签关联表
|
||||
create table t_coupon_tag
|
||||
(
|
||||
id bigint unsigned auto_increment comment '优惠券标签关联唯一主键ID'
|
||||
primary key comment '优惠券标签关联主键索引',
|
||||
coupon_id bigint unsigned not null comment '关联优惠券表主键',
|
||||
tag_id bigint unsigned not null comment '关联标签表主键',
|
||||
is_available tinyint unsigned default 1 not null comment '是否可用:1-可用,0-不可用',
|
||||
create_time datetime default CURRENT_TIMESTAMP not null comment '创建时间',
|
||||
update_time datetime default CURRENT_TIMESTAMP not null on update CURRENT_TIMESTAMP comment '更新时间',
|
||||
is_delete tinyint unsigned default 0 null comment '逻辑删除:0-未删,1-已删',
|
||||
constraint uk_coupon_tag
|
||||
unique (coupon_id, tag_id) comment '优惠券-标签唯一索引'
|
||||
) comment '优惠券标签关联表';
|
||||
|
||||
create index idx_coupon_id
|
||||
on t_coupon_tag (coupon_id) comment '按优惠券查询标签的索引';
|
||||
|
||||
create index idx_tag_id
|
||||
on t_coupon_tag (tag_id) comment '按标签查询优惠券的索引';
|
||||
|
||||
-- 购物车表
|
||||
create table t_cart
|
||||
(
|
||||
id bigint unsigned auto_increment comment '购物车唯一主键ID'
|
||||
primary key comment '购物车主键索引',
|
||||
user_id bigint unsigned not null comment '关联用户表主键',
|
||||
product_id bigint unsigned not null comment '关联商品表主键',
|
||||
quantity int unsigned default 1 not null comment '商品数量',
|
||||
create_time datetime default CURRENT_TIMESTAMP not null comment '创建时间',
|
||||
update_time datetime default CURRENT_TIMESTAMP not null on update CURRENT_TIMESTAMP comment '更新时间',
|
||||
is_delete tinyint unsigned default 0 null comment '逻辑删除:0-未删,1-已删',
|
||||
constraint uk_user_product
|
||||
unique (user_id, product_id) comment '用户-商品唯一索引'
|
||||
) comment '购物车表';
|
||||
|
||||
create index idx_user_id
|
||||
on t_cart (user_id) comment '按用户查询购物车的索引';
|
||||
|
||||
-- 订单表
|
||||
create table t_order
|
||||
(
|
||||
id bigint unsigned auto_increment comment '订单唯一主键ID'
|
||||
primary key comment '订单主键索引',
|
||||
order_no varchar(50) not null comment '订单编号',
|
||||
user_id bigint unsigned not null comment '关联用户表主键',
|
||||
total_amount decimal(10, 2) not null comment '订单总金额',
|
||||
actual_amount decimal(10, 2) not null comment '实际支付金额',
|
||||
coupon_id bigint unsigned default 0 null comment '使用的优惠券ID',
|
||||
status tinyint unsigned default 1 not null comment '订单状态:1-待使用,2-已完成,3-已取消',
|
||||
create_time datetime default CURRENT_TIMESTAMP not null comment '创建时间',
|
||||
update_time datetime default CURRENT_TIMESTAMP not null on update CURRENT_TIMESTAMP comment '更新时间',
|
||||
is_delete tinyint unsigned default 0 null comment '逻辑删除:0-未删,1-已删',
|
||||
constraint uk_order_no
|
||||
unique (order_no) comment '订单编号唯一索引'
|
||||
) comment '订单表';
|
||||
|
||||
create index idx_status
|
||||
on t_order (status) comment '按状态查询订单的索引';
|
||||
|
||||
create index idx_user_id
|
||||
on t_order (user_id) comment '按用户查询订单的索引';
|
||||
|
||||
-- 订单商品表
|
||||
create table t_order_item
|
||||
(
|
||||
id bigint unsigned auto_increment comment '订单商品唯一主键ID'
|
||||
primary key comment '订单商品主键索引',
|
||||
order_id bigint unsigned not null comment '关联订单表主键',
|
||||
product_id bigint unsigned not null comment '关联商品表主键',
|
||||
quantity int unsigned not null comment '商品数量',
|
||||
price decimal(10, 2) not null comment '商品单价',
|
||||
create_time datetime default CURRENT_TIMESTAMP not null comment '创建时间',
|
||||
update_time datetime default CURRENT_TIMESTAMP not null on update CURRENT_TIMESTAMP comment '更新时间',
|
||||
is_delete tinyint unsigned default 0 null comment '逻辑删除:0-未删,1-已删'
|
||||
) comment '订单商品表';
|
||||
|
||||
create index idx_order_id
|
||||
on t_order_item (order_id) comment '按订单查询商品的索引';
|
||||
|
||||
|
||||
-- 商品收藏表
|
||||
create table t_wishlist
|
||||
(
|
||||
id bigint unsigned auto_increment comment '收藏记录唯一主键ID'
|
||||
primary key comment '商品收藏主键索引',
|
||||
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
|
||||
unique (user_id, product_id) comment '用户-商品唯一索引'
|
||||
) comment '商品收藏表';
|
||||
|
||||
create index idx_user_id
|
||||
on t_wishlist (user_id) comment '按用户查询收藏的索引';
|
||||
|
||||
create index idx_product_id
|
||||
on t_wishlist (product_id) comment '按商品查询收藏的索引';
|
||||
|
||||
|
||||
-- 美甲师信息表
|
||||
CREATE TABLE t_nail_artist_info (
|
||||
id BIGINT UNSIGNED AUTO_INCREMENT COMMENT '美甲师信息唯一主键ID'
|
||||
PRIMARY KEY COMMENT '美甲师信息主键索引',
|
||||
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 0.0 NULL COMMENT '评分',
|
||||
status TINYINT UNSIGNED DEFAULT 1 NULL COMMENT '状态:1-营业中,0-休息中',
|
||||
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_user_id ON t_nail_artist_info (user_id) COMMENT '按用户查询美甲师信息的索引';
|
||||
CREATE INDEX idx_status ON t_nail_artist_info (status) COMMENT '按状态查询美甲师的索引';
|
||||
|
||||
-- 添加美甲师管理相关权限
|
||||
INSERT INTO t_permission (permission_code, permission_name, permission_group, description, create_time, update_time, is_delete) VALUES
|
||||
('nail_artist:view', '查看美甲师', '美甲师管理', '查看美甲师列表和详情', NOW(), NOW(), 0),
|
||||
('nail_artist:edit', '编辑美甲师', '美甲师管理', '编辑美甲师信息', NOW(), NOW(), 0);
|
||||
|
||||
-- 为管理员分配美甲师管理权限
|
||||
INSERT INTO t_user_permission (user_id, permission_id, create_time, update_time, create_by)
|
||||
SELECT
|
||||
1 as user_id,
|
||||
p.id as permission_id,
|
||||
NOW() as create_time,
|
||||
NOW() as update_time,
|
||||
1 as create_by
|
||||
FROM t_permission p
|
||||
WHERE p.is_delete = 0
|
||||
AND p.permission_code IN (
|
||||
'nail_artist:view',
|
||||
'nail_artist:edit'
|
||||
);
|
||||
-- 商品点赞记录表
|
||||
CREATE TABLE t_product_like (
|
||||
id BIGINT UNSIGNED AUTO_INCREMENT COMMENT '点赞记录唯一主键ID'
|
||||
PRIMARY KEY COMMENT '商品点赞主键索引',
|
||||
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_user_id_like ON t_product_like (user_id) COMMENT '按用户查询点赞的索引';
|
||||
CREATE INDEX idx_product_id_like ON t_product_like (product_id) COMMENT '按商品查询点赞的索引';
|
||||
|
||||
|
||||
ALTER TABLE t_order_item ADD COLUMN artist_id BIGINT UNSIGNED DEFAULT NULL COMMENT '关联美甲师ID' AFTER price;
|
||||
@@ -228,6 +228,9 @@ create table t_nail_artist_info
|
||||
skills text null comment '技能标签ID集合,多个ID以逗号分隔',
|
||||
rating decimal(3, 1) default 0.0 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 '更新时间',
|
||||
@@ -245,6 +248,9 @@ 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
|
||||
(
|
||||
@@ -397,6 +403,9 @@ create table t_shop
|
||||
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',
|
||||
create_time datetime default CURRENT_TIMESTAMP not null comment '创建时间',
|
||||
@@ -522,6 +531,101 @@ 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以逗号分隔',
|
||||
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 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
|
||||
(
|
||||
@@ -1008,6 +1112,10 @@ 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_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 ''店铺纬度''');
|
||||
|
||||
UPDATE t_shop
|
||||
SET status = 1
|
||||
@@ -1077,6 +1185,33 @@ 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''');
|
||||
|
||||
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 'yuminail' 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='YumiNail按业务场景投递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;
|
||||
@@ -1134,7 +1269,38 @@ VALUES
|
||||
('order:edit', '编辑订单', '订单管理', '编辑订单信息的预留权限', NOW(), NOW(), 0),
|
||||
('order:delete', '删除订单', '订单管理', '删除订单的预留权限', NOW(), NOW(), 0),
|
||||
('nail_artist:view', '查看美甲师', '美甲师管理', '查看美甲师信息与排班入口', NOW(), NOW(), 0),
|
||||
('nail_artist:edit', '编辑美甲师', '美甲师管理', '编辑美甲师信息', 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', 'View Announcements', 'Announcement Management', 'View announcement list and detail', NOW(), NOW(), 0),
|
||||
('announcement:create', 'Create Announcements', 'Announcement Management', 'Publish announcements', NOW(), NOW(), 0),
|
||||
('announcement:delete', 'Withdraw Announcements', 'Announcement Management', 'Withdraw published announcements', 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', 'View Announcements', 'Announcement Management', 'View announcement list and detail', NOW(), NOW(), 0),
|
||||
(910000000008012, 'announcement:create', 'Create Announcements', 'Announcement Management', 'Publish announcements', NOW(), NOW(), 0),
|
||||
(910000000008013, 'announcement:delete', 'Withdraw Announcements', 'Announcement Management', 'Withdraw published announcements', NOW(), NOW(), 0)
|
||||
ON DUPLICATE KEY UPDATE
|
||||
permission_name = VALUES(permission_name),
|
||||
permission_group = VALUES(permission_group),
|
||||
@@ -1229,7 +1395,13 @@ INNER JOIN t_permission p
|
||||
'order:edit',
|
||||
'order:delete',
|
||||
'nail_artist:view',
|
||||
'nail_artist:edit'
|
||||
'nail_artist:edit',
|
||||
'message:view',
|
||||
'message:create',
|
||||
'message:delete',
|
||||
'announcement:view',
|
||||
'announcement:create',
|
||||
'announcement:delete'
|
||||
)
|
||||
WHERE u.is_delete = 0
|
||||
AND u.type = 4
|
||||
@@ -1283,7 +1455,11 @@ INNER JOIN t_permission p
|
||||
'order:edit',
|
||||
'order:delete',
|
||||
'nail_artist:view',
|
||||
'nail_artist:edit'
|
||||
'nail_artist:edit',
|
||||
'message:view',
|
||||
'message:create',
|
||||
'announcement:view',
|
||||
'announcement:create'
|
||||
)
|
||||
WHERE u.is_delete = 0
|
||||
AND u.type = 2
|
||||
@@ -1323,6 +1499,224 @@ WHERE u.is_delete = 0
|
||||
AND up.permission_id = p.id
|
||||
);
|
||||
|
||||
|
||||
INSERT INTO t_user_permission (id, user_id, permission_id, create_time, update_time, create_by, update_by, is_delete)
|
||||
SELECT 910000000009000 + ((u.id % 1000000) * 10) + CASE p.permission_code
|
||||
WHEN 'message:view' THEN 1
|
||||
WHEN 'message:create' THEN 2
|
||||
WHEN 'message:delete' THEN 3
|
||||
WHEN 'announcement:view' THEN 4
|
||||
WHEN 'announcement:create' THEN 5
|
||||
WHEN 'announcement:delete' THEN 6
|
||||
ELSE 0
|
||||
END,
|
||||
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
|
||||
AND (
|
||||
(u.type = 4 AND p.permission_code IN ('message:view', 'message:create', 'message:delete', 'announcement:view', 'announcement:create', 'announcement:delete'))
|
||||
OR (u.type = 2 AND p.permission_code IN ('message:view', 'message:create', 'announcement:view', 'announcement:create'))
|
||||
)
|
||||
WHERE u.is_delete = 0
|
||||
AND NOT EXISTS (
|
||||
SELECT 1
|
||||
FROM t_user_permission up
|
||||
WHERE up.user_id = u.id
|
||||
AND up.permission_id = p.id
|
||||
)
|
||||
ON DUPLICATE KEY UPDATE
|
||||
is_delete = 0,
|
||||
update_time = NOW();
|
||||
|
||||
-- YumiNail 手工验收种子数据
|
||||
INSERT INTO t_nail_artist_info (user_id, identity, experience, skills, rating, status, participate_production, work_start_time, work_end_time, portfolio, create_time, update_time, is_delete)
|
||||
SELECT u.id, '店长', 3, '', 5.0, 1, 0, '09:00:00', '18:00:00', '', NOW(), NOW(), 0
|
||||
FROM t_user u
|
||||
WHERE u.type = 2 AND u.is_delete = 0
|
||||
AND NOT EXISTS (SELECT 1 FROM t_nail_artist_info nai WHERE nai.user_id = u.id AND nai.is_delete = 0);
|
||||
|
||||
UPDATE t_nail_artist_info nai
|
||||
INNER JOIN t_user u ON u.id = nai.user_id AND u.type = 3
|
||||
SET nai.participate_production = 1
|
||||
WHERE nai.participate_production IS NULL;
|
||||
|
||||
UPDATE t_nail_artist_info nai
|
||||
INNER JOIN t_user u ON u.id = nai.user_id AND u.type = 2
|
||||
SET nai.participate_production = COALESCE(nai.participate_production, 0);
|
||||
|
||||
-- 小型全覆盖验收数据,便于人工抽检。
|
||||
-- Password hash matches the existing admin seed password hash; reset in non-local environments if needed.
|
||||
INSERT INTO t_shop (id, shop_name, description, address, business_hours, cover_image_file_id, create_time, update_time, is_delete, image_file_ids, status)
|
||||
SELECT 910000000000001, '验收主店', '用于验收的主门店', '验收路 1 号', '09:00-21:00', '', NOW(), NOW(), 0, '', 1
|
||||
WHERE NOT EXISTS (SELECT 1 FROM t_shop WHERE id = 910000000000001);
|
||||
|
||||
INSERT INTO t_shop (id, shop_name, description, address, business_hours, cover_image_file_id, create_time, update_time, is_delete, image_file_ids, status)
|
||||
SELECT 910000000000002, '验收分店', '用于验收的分门店', '验收路 2 号', '10:00-20:00', '', NOW(), NOW(), 0, '', 1
|
||||
WHERE NOT EXISTS (SELECT 1 FROM t_shop WHERE id = 910000000000002);
|
||||
|
||||
INSERT INTO t_vip_info (id, vip_level, start_time, expire_time, activation_method, benefit_id, create_time, update_time)
|
||||
SELECT 910000000000101, '青铜会员', NOW(), DATE_ADD(NOW(), INTERVAL 1 YEAR), '验收种子数据', COALESCE((SELECT id FROM t_vip_benefit WHERE level_rank = 1 LIMIT 1), 0), NOW(), NOW()
|
||||
WHERE NOT EXISTS (SELECT 1 FROM t_vip_info WHERE id = 910000000000101);
|
||||
|
||||
INSERT INTO t_vip_info (id, vip_level, start_time, expire_time, activation_method, benefit_id, create_time, update_time)
|
||||
SELECT 910000000000102, '白银会员', NOW(), DATE_ADD(NOW(), INTERVAL 1 YEAR), '验收种子数据', COALESCE((SELECT id FROM t_vip_benefit WHERE level_rank = 2 LIMIT 1), 0), NOW(), NOW()
|
||||
WHERE NOT EXISTS (SELECT 1 FROM t_vip_info WHERE id = 910000000000102);
|
||||
|
||||
INSERT INTO t_vip_info (id, vip_level, start_time, expire_time, activation_method, benefit_id, create_time, update_time)
|
||||
SELECT 910000000000103, '黄金会员', NOW(), DATE_ADD(NOW(), INTERVAL 1 YEAR), '验收种子数据', COALESCE((SELECT id FROM t_vip_benefit WHERE level_rank = 3 LIMIT 1), 0), NOW(), NOW()
|
||||
WHERE NOT EXISTS (SELECT 1 FROM t_vip_info WHERE id = 910000000000103);
|
||||
|
||||
INSERT INTO t_user (id, shop_id, nickname, account, phone, email, phone_verified, email_verified, password, signature, level, type, vip_id, create_time, update_time, is_delete, status, avatar)
|
||||
VALUES
|
||||
(910000000001001, 910000000000001, '验收普通用户', 'accept_user_normal', '18800001001', NULL, 1, 0, '$2a$10$9v.6PztWy3.vmJiVMaOyKuWeVqAnpuHB3hQ3Dgiuz6L8IwBe7Cn9W', '', '普通用户', 0, 0, NOW(), NOW(), 0, 1, NULL),
|
||||
(910000000001002, 910000000000001, '验收青铜用户', 'accept_user_bronze', '18800001002', NULL, 1, 0, '$2a$10$9v.6PztWy3.vmJiVMaOyKuWeVqAnpuHB3hQ3Dgiuz6L8IwBe7Cn9W', '', '青铜会员', 0, 910000000000101, NOW(), NOW(), 0, 1, NULL),
|
||||
(910000000001003, 910000000000001, '验收白银用户', 'accept_user_silver', '18800001003', NULL, 1, 0, '$2a$10$9v.6PztWy3.vmJiVMaOyKuWeVqAnpuHB3hQ3Dgiuz6L8IwBe7Cn9W', '', '白银会员', 0, 910000000000102, NOW(), NOW(), 0, 1, NULL),
|
||||
(910000000001004, 910000000000001, '验收黄金用户', 'accept_user_gold', '18800001004', NULL, 1, 0, '$2a$10$9v.6PztWy3.vmJiVMaOyKuWeVqAnpuHB3hQ3Dgiuz6L8IwBe7Cn9W', '', '黄金会员', 0, 910000000000103, NOW(), NOW(), 0, 1, NULL),
|
||||
(910000000002001, 910000000000001, '验收店长', 'accept_manager_main', '18800002001', NULL, 1, 0, '$2a$10$9v.6PztWy3.vmJiVMaOyKuWeVqAnpuHB3hQ3Dgiuz6L8IwBe7Cn9W', '', '店长', 2, 0, NOW(), NOW(), 0, 1, NULL),
|
||||
(910000000002002, 910000000000001, '验收参与制作店长', 'accept_manager_artist', '18800002002', NULL, 1, 0, '$2a$10$9v.6PztWy3.vmJiVMaOyKuWeVqAnpuHB3hQ3Dgiuz6L8IwBe7Cn9W', '', '店长', 2, 0, NOW(), NOW(), 0, 1, NULL),
|
||||
(910000000002003, 910000000000002, '验收分店店长', 'accept_manager_branch', '18800002003', NULL, 1, 0, '$2a$10$9v.6PztWy3.vmJiVMaOyKuWeVqAnpuHB3hQ3Dgiuz6L8IwBe7Cn9W', '', '店长', 2, 0, NOW(), NOW(), 0, 1, NULL),
|
||||
(910000000003001, 910000000000001, '验收美甲师', 'accept_artist_main', '18800003001', NULL, 1, 0, '$2a$10$9v.6PztWy3.vmJiVMaOyKuWeVqAnpuHB3hQ3Dgiuz6L8IwBe7Cn9W', '', '美甲师', 3, 0, NOW(), NOW(), 0, 1, NULL),
|
||||
(910000000003002, 910000000000002, '验收分店美甲师', 'accept_artist_branch', '18800003002', NULL, 1, 0, '$2a$10$9v.6PztWy3.vmJiVMaOyKuWeVqAnpuHB3hQ3Dgiuz6L8IwBe7Cn9W', '', '美甲师', 3, 0, NOW(), NOW(), 0, 1, NULL)
|
||||
ON DUPLICATE KEY UPDATE
|
||||
shop_id = VALUES(shop_id),
|
||||
nickname = VALUES(nickname),
|
||||
phone = VALUES(phone),
|
||||
level = VALUES(level),
|
||||
type = VALUES(type),
|
||||
vip_id = VALUES(vip_id),
|
||||
status = VALUES(status),
|
||||
is_delete = 0,
|
||||
update_time = NOW();
|
||||
|
||||
INSERT INTO t_user_shop_binding (user_id, shop_id, status, create_time, update_time, is_delete)
|
||||
SELECT u.id, u.shop_id, 1, NOW(), NOW(), 0
|
||||
FROM t_user u
|
||||
WHERE u.id BETWEEN 910000000001001 AND 910000000003002
|
||||
AND u.shop_id > 0
|
||||
ON DUPLICATE KEY UPDATE
|
||||
status = 1,
|
||||
is_delete = 0,
|
||||
update_time = NOW();
|
||||
|
||||
INSERT INTO t_nail_artist_info (user_id, identity, experience, skills, rating, status, participate_production, work_start_time, work_end_time, portfolio, create_time, update_time, is_delete)
|
||||
VALUES
|
||||
(910000000002001, '店长', 5, '门店管理', 5.0, 1, 0, '09:00:00', '18:00:00', '', NOW(), NOW(), 0),
|
||||
(910000000002002, '参与制作店长', 8, '美甲设计', 5.0, 1, 1, '09:30:00', '20:00:00', '', NOW(), NOW(), 0),
|
||||
(910000000002003, '分店店长', 4, '分店管理', 4.8, 1, 1, '10:00:00', '19:00:00', '', NOW(), NOW(), 0),
|
||||
(910000000003001, '美甲师', 3, '凝胶,护理', 4.9, 1, 1, '10:00:00', '21:00:00', '', NOW(), NOW(), 0),
|
||||
(910000000003002, '分店美甲师', 2, '基础护理,修复', 4.7, 1, 1, '10:00:00', '19:00:00', '', NOW(), NOW(), 0)
|
||||
ON DUPLICATE KEY UPDATE
|
||||
identity = VALUES(identity),
|
||||
experience = VALUES(experience),
|
||||
skills = VALUES(skills),
|
||||
rating = VALUES(rating),
|
||||
status = VALUES(status),
|
||||
participate_production = VALUES(participate_production),
|
||||
work_start_time = VALUES(work_start_time),
|
||||
work_end_time = VALUES(work_end_time),
|
||||
is_delete = 0,
|
||||
update_time = NOW();
|
||||
|
||||
INSERT INTO t_balance (user_id, amount, create_time, last_update_time, total_recharge_amount, last_recharge_time)
|
||||
VALUES
|
||||
(910000000001001, 68.00, NOW(), NOW(), 100.00, DATE_SUB(NOW(), INTERVAL 10 DAY)),
|
||||
(910000000001002, 288.00, NOW(), NOW(), 600.00, DATE_SUB(NOW(), INTERVAL 8 DAY)),
|
||||
(910000000001003, 588.00, NOW(), NOW(), 1200.00, DATE_SUB(NOW(), INTERVAL 6 DAY)),
|
||||
(910000000001004, 988.00, NOW(), NOW(), 2600.00, DATE_SUB(NOW(), INTERVAL 4 DAY))
|
||||
ON DUPLICATE KEY UPDATE
|
||||
amount = VALUES(amount),
|
||||
total_recharge_amount = VALUES(total_recharge_amount),
|
||||
last_recharge_time = VALUES(last_recharge_time),
|
||||
last_update_time = NOW();
|
||||
|
||||
INSERT INTO t_balance_change_detail (id, user_id, amount, type, current_balance, change_time)
|
||||
VALUES
|
||||
(910000000007001, 910000000001001, 100.00, 'RECHARGE', 100.00, DATE_SUB(NOW(), INTERVAL 10 DAY)),
|
||||
(910000000007002, 910000000001001, -32.00, 'CONSUME', 68.00, DATE_SUB(NOW(), INTERVAL 9 DAY)),
|
||||
(910000000007003, 910000000001002, 600.00, 'RECHARGE', 600.00, DATE_SUB(NOW(), INTERVAL 8 DAY)),
|
||||
(910000000007004, 910000000001002, -312.00, 'CONSUME', 288.00, DATE_SUB(NOW(), INTERVAL 7 DAY)),
|
||||
(910000000007005, 910000000001003, 1200.00, 'RECHARGE', 1200.00, DATE_SUB(NOW(), INTERVAL 6 DAY)),
|
||||
(910000000007006, 910000000001003, -612.00, 'CONSUME', 588.00, DATE_SUB(NOW(), INTERVAL 5 DAY)),
|
||||
(910000000007007, 910000000001004, 2600.00, 'RECHARGE', 2600.00, DATE_SUB(NOW(), INTERVAL 4 DAY)),
|
||||
(910000000007008, 910000000001004, -1612.00, 'CONSUME', 988.00, DATE_SUB(NOW(), INTERVAL 3 DAY))
|
||||
ON DUPLICATE KEY UPDATE
|
||||
amount = VALUES(amount),
|
||||
type = VALUES(type),
|
||||
current_balance = VALUES(current_balance),
|
||||
change_time = VALUES(change_time);
|
||||
|
||||
INSERT INTO t_product (id, shop_id, title, description, image_file_ids, price, tags, like_count, collect_count, approximate_duration, bookable_artists, available_coupons, create_time, update_time, is_delete)
|
||||
VALUES
|
||||
(910000000004001, 910000000000001, '验收凝胶美甲', '可由普通美甲师和参与制作店长预约服务。', '', 168.00, '验收,凝胶', 0, 0, '90 分钟', '910000000003001,910000000002002', '', NOW(), NOW(), 0),
|
||||
(910000000004002, 910000000000001, '验收店长专属款', '用于验证参与制作店长的预约流程。', '', 268.00, '验收,店长', 0, 0, '120 分钟', '910000000002002', '', NOW(), NOW(), 0),
|
||||
(910000000004003, 910000000000002, '验收分店护理', '用于验证跨店不可预约的分店商品。', '', 128.00, '验收,分店', 0, 0, '60 分钟', '910000000003002,910000000002003', '', NOW(), NOW(), 0)
|
||||
ON DUPLICATE KEY UPDATE
|
||||
shop_id = VALUES(shop_id),
|
||||
title = VALUES(title),
|
||||
description = VALUES(description),
|
||||
price = VALUES(price),
|
||||
tags = VALUES(tags),
|
||||
approximate_duration = VALUES(approximate_duration),
|
||||
bookable_artists = VALUES(bookable_artists),
|
||||
is_delete = 0,
|
||||
update_time = NOW();
|
||||
|
||||
INSERT INTO t_cart (user_id, product_id, quantity, create_time, update_time, is_delete)
|
||||
VALUES (910000000001004, 910000000004001, 1, NOW(), NOW(), 0)
|
||||
ON DUPLICATE KEY UPDATE
|
||||
quantity = VALUES(quantity),
|
||||
is_delete = 0,
|
||||
update_time = NOW();
|
||||
|
||||
INSERT INTO t_order (id, order_no, user_id, total_amount, actual_amount, coupon_id, status, create_time, update_time, is_delete)
|
||||
SELECT 910000000005001, 'ACCEPTANCE-ORDER-001', 910000000001004, 168.00, 168.00, 0, 1, NOW(), NOW(), 0
|
||||
WHERE NOT EXISTS (SELECT 1 FROM t_order WHERE order_no = 'ACCEPTANCE-ORDER-001');
|
||||
|
||||
INSERT INTO t_order_item (order_id, product_id, quantity, price, artist_id, create_time, update_time, is_delete)
|
||||
SELECT 910000000005001, 910000000004001, 1, 168.00, 910000000002002, NOW(), NOW(), 0
|
||||
WHERE EXISTS (SELECT 1 FROM t_order WHERE id = 910000000005001)
|
||||
AND NOT EXISTS (SELECT 1 FROM t_order_item WHERE order_id = 910000000005001 AND product_id = 910000000004001);
|
||||
|
||||
INSERT INTO t_system_message (id, title, content, publisher_id, publisher_name, publisher_type, target_type, target_ids, popup_enabled, status, publish_time, create_time, update_time, is_delete)
|
||||
VALUES
|
||||
(910000000006001, '平台验收通知', '这是一条面向当前和后续新增用户的平台通知。', 910000000001001, '验收管理员', 4, 'PLATFORM_ALL', '', 1, 1, NOW(), NOW(), NOW(), 0),
|
||||
(910000000006002, '本店验收通知', '这是一条面向本店动态用户范围的店铺通知。', 910000000002002, '参与制作店长', 2, 'CURRENT_SHOP_ALL', '910000000000001', 1, 1, NOW(), NOW(), NOW(), 0),
|
||||
(910000000006003, '指定用户验收通知', '这是一条仅指定用户可见的通知。', 910000000002002, '参与制作店长', 2, 'SELECTED_USERS', '910000000001004', 1, 1, NOW(), NOW(), NOW(), 0)
|
||||
ON DUPLICATE KEY UPDATE
|
||||
title = VALUES(title),
|
||||
content = VALUES(content),
|
||||
publisher_id = VALUES(publisher_id),
|
||||
publisher_name = VALUES(publisher_name),
|
||||
publisher_type = VALUES(publisher_type),
|
||||
target_type = VALUES(target_type),
|
||||
target_ids = VALUES(target_ids),
|
||||
popup_enabled = VALUES(popup_enabled),
|
||||
status = VALUES(status),
|
||||
is_delete = 0,
|
||||
update_time = NOW();
|
||||
|
||||
INSERT INTO t_system_message_user_state (message_id, user_id, popup_shown, read_status, popup_time, read_time, create_time, update_time, is_delete)
|
||||
VALUES
|
||||
(910000000006001, 910000000001001, 1, 1, DATE_SUB(NOW(), INTERVAL 1 DAY), DATE_SUB(NOW(), INTERVAL 1 DAY), NOW(), NOW(), 0),
|
||||
(910000000006002, 910000000001002, 1, 0, DATE_SUB(NOW(), INTERVAL 2 HOUR), NULL, NOW(), NOW(), 0),
|
||||
(910000000006003, 910000000001004, 0, 0, NULL, NULL, NOW(), NOW(), 0)
|
||||
ON DUPLICATE KEY UPDATE
|
||||
popup_shown = VALUES(popup_shown),
|
||||
read_status = VALUES(read_status),
|
||||
popup_time = VALUES(popup_time),
|
||||
read_time = VALUES(read_time),
|
||||
is_delete = 0,
|
||||
update_time = NOW();
|
||||
|
||||
-- 小型全覆盖抽检数据可在空库初始化后按需扩展:管理员、店长、美甲师、普通用户、VIP 等级、商品、余额流水均由本初始化文件统一承载。
|
||||
|
||||
-- ========================================
|
||||
-- 雪花 ID 口径收口区:去掉运行时主键表的 AUTO_INCREMENT
|
||||
-- 说明:
|
||||
@@ -1331,6 +1725,43 @@ WHERE u.is_delete = 0
|
||||
-- 3. 与 2026-03-30_snowflake_id_alignment_patch.sql 保持同口径
|
||||
-- ========================================
|
||||
|
||||
INSERT INTO t_announcement (id, title, content, publisher_id, publisher_name, publisher_type, target_type, target_ids, status, sort_order, publish_time, create_time, update_time, is_delete)
|
||||
VALUES
|
||||
(910000000010001, '平台公告', '平台公告:欢迎体验首页滚动公告功能。', 910000000001001, '验收管理员', 4, 'PLATFORM_ALL', '', 1, 10, NOW(), NOW(), NOW(), 0),
|
||||
(910000000010002, '本店公告', '本店公告:今日可预约店长参与制作服务。', 910000000002002, '参与制作店长', 2, 'CURRENT_SHOP_ALL', '910000000000001', 1, 20, NOW(), NOW(), NOW(), 0),
|
||||
(910000000010003, '专属公告', '专属公告:这是指定用户可见的验收公告。', 910000000002002, '参与制作店长', 2, 'SELECTED_USERS', '910000000001004', 1, 30, NOW(), NOW(), NOW(), 0)
|
||||
ON DUPLICATE KEY UPDATE
|
||||
title = VALUES(title),
|
||||
content = VALUES(content),
|
||||
publisher_id = VALUES(publisher_id),
|
||||
publisher_name = VALUES(publisher_name),
|
||||
publisher_type = VALUES(publisher_type),
|
||||
target_type = VALUES(target_type),
|
||||
target_ids = VALUES(target_ids),
|
||||
status = VALUES(status),
|
||||
sort_order = VALUES(sort_order),
|
||||
is_delete = 0,
|
||||
update_time = NOW();
|
||||
|
||||
INSERT INTO t_vip_recharge_plan (id, shop_id, title, recharge_amount, gift_amount, vip_level, description, sort_order, status, create_time, update_time, is_delete)
|
||||
VALUES
|
||||
(910000000011001, 910000000000001, '充100送10', 100.00, 10.00, '青铜VIP', '适合轻量体验用户,仅展示不发起支付。', 10, 1, NOW(), NOW(), 0),
|
||||
(910000000011002, 910000000000001, '充500送80', 500.00, 80.00, '白银VIP', '适合常规护理用户,仅展示不发起支付。', 20, 1, NOW(), NOW(), 0),
|
||||
(910000000011003, 910000000000001, '充1000送200', 1000.00, 200.00, '黄金VIP', '适合高频预约用户,仅展示不发起支付。', 30, 1, NOW(), NOW(), 0),
|
||||
(910000000011004, 910000000000002, '分店充100送10', 100.00, 10.00, '青铜VIP', '分店验收充值档位。', 10, 1, NOW(), NOW(), 0),
|
||||
(910000000011005, 910000000000002, '分店充500送80', 500.00, 80.00, '白银VIP', '分店验收充值档位。', 20, 1, NOW(), NOW(), 0)
|
||||
ON DUPLICATE KEY UPDATE
|
||||
shop_id = VALUES(shop_id),
|
||||
title = VALUES(title),
|
||||
recharge_amount = VALUES(recharge_amount),
|
||||
gift_amount = VALUES(gift_amount),
|
||||
vip_level = VALUES(vip_level),
|
||||
description = VALUES(description),
|
||||
sort_order = VALUES(sort_order),
|
||||
status = VALUES(status),
|
||||
is_delete = 0,
|
||||
update_time = NOW();
|
||||
|
||||
DROP PROCEDURE IF EXISTS sp_drop_auto_increment_on_id_if_exists;
|
||||
|
||||
DELIMITER $$
|
||||
@@ -1393,5 +1824,267 @@ 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');
|
||||
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');
|
||||
|
||||
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='邀请码表';
|
||||
|
||||
-- Indexes are created by the corresponding migration path in environments that need them.
|
||||
-- Existing databases already have these indexes, and MySQL 5.7 does not support CREATE INDEX IF NOT EXISTS.
|
||||
|
||||
INSERT INTO t_permission (id, permission_code, permission_name, permission_group, description, create_time, update_time, is_delete)
|
||||
VALUES
|
||||
(313931273555136490, 'messagehub:config:manage', '管理MessageHub配置', '消息配置', '管理YumiNail投递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_user_permission (user_id, permission_id, create_time, update_time, create_by, update_by, is_delete)
|
||||
SELECT 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
|
||||
AND p.permission_code = 'messagehub:config:manage'
|
||||
WHERE u.is_delete = 0
|
||||
AND u.type = 4
|
||||
AND NOT EXISTS (
|
||||
SELECT 1
|
||||
FROM t_user_permission up
|
||||
WHERE up.user_id = u.id
|
||||
AND up.permission_id = p.id
|
||||
AND up.is_delete = 0
|
||||
);
|
||||
|
||||
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', 'yuminail', 'SPUG0001', NULL, 'SPUG', 1, '注册功能发送验证码时使用', NOW(), NOW(), 0),
|
||||
(313931273555137002, 'USER_LOGIN_SMS_CODE', '手机号登录验证码', 'SMS', 'VERIFICATION', 'smsQueue', 'yuminail', 'SPUG0001', NULL, 'SPUG', 1, '手机号验证码登录时使用', NOW(), NOW(), 0),
|
||||
(313931273555137003, 'USER_RESET_PASSWORD_SMS_CODE', '找回密码验证码', 'SMS', 'VERIFICATION', 'smsQueue', 'yuminail', 'SPUG0001', NULL, 'SPUG', 1, '找回密码时使用', NOW(), NOW(), 0),
|
||||
(313931273555137004, 'USER_BIND_PHONE_SMS_CODE', '绑定手机号验证码', 'SMS', 'VERIFICATION', 'smsQueue', 'yuminail', 'SPUG0001', NULL, 'SPUG', 1, '绑定手机号时使用', NOW(), NOW(), 0),
|
||||
(313931273555137005, 'USER_CHANGE_PHONE_SMS_CODE', '修改手机号验证码', 'SMS', 'VERIFICATION', 'smsQueue', 'yuminail', 'SPUG0001', NULL, 'SPUG', 1, '修改手机号时使用', NOW(), NOW(), 0),
|
||||
(313931273555137006, 'USER_CHANGE_PASSWORD_SMS_CODE', '修改密码验证码', 'SMS', 'VERIFICATION', 'smsQueue', 'yuminail', '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='系统参数配置';
|
||||
|
||||
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', '欢迎使用 YumiNail。请在使用账号、预约、订单、会员、消息等功能前仔细阅读本协议。继续登录或注册即表示你已理解并同意平台基础服务规则、账号安全要求、订单预约规则和依法合规使用要求。', 1, NOW(), NOW(), NOW(), 0),
|
||||
(313931273555138002, 'PRIVACY_POLICY', '隐私政策', '2026.05.18', 'YumiNail 会在提供登录注册、预约下单、会员余额、消息通知和客户服务时处理必要的手机号、昵称、门店归属、订单与设备信息。我们仅在业务需要和法律允许范围内使用这些信息,并采取访问控制、脱敏展示和审计记录等措施保护数据安全。', 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_user_permission (user_id, permission_id, create_time, update_time, create_by, update_by, is_delete)
|
||||
SELECT 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
|
||||
AND p.permission_code = 'legal_agreement:manage'
|
||||
WHERE u.is_delete = 0
|
||||
AND u.type = 4
|
||||
AND NOT EXISTS (
|
||||
SELECT 1
|
||||
FROM t_user_permission up
|
||||
WHERE up.user_id = u.id
|
||||
AND up.permission_id = p.id
|
||||
AND up.is_delete = 0
|
||||
);
|
||||
|
||||
INSERT INTO t_system_parameter_config (
|
||||
id, config_group, config_key, config_name, config_value, enabled, remark, create_time, update_time, is_delete
|
||||
)
|
||||
VALUES
|
||||
(313931273555139001, 'MAP', 'TENCENT_MAP_KEY', '腾讯位置服务 Key', '', 0, '用于后台店铺选点和腾讯地图展示;请在后台参数管理中填入真实 Key 后启用', NOW(), NOW(), 0)
|
||||
ON DUPLICATE KEY UPDATE
|
||||
config_name = VALUES(config_name),
|
||||
remark = VALUES(remark),
|
||||
is_delete = 0,
|
||||
update_time = NOW();
|
||||
|
||||
Reference in New Issue
Block a user