功能:完善订单流程和加固

This commit is contained in:
xiaowang
2026-05-23 15:16:40 +08:00
parent 9227ec6175
commit 3e6e1cc4e8
90 changed files with 6859 additions and 368 deletions
@@ -19,6 +19,7 @@ create table t_balance
last_recharge_time datetime null comment '最近一次充值时间',
create_time datetime default CURRENT_TIMESTAMP not null comment '余额账户创建时间',
last_update_time datetime default CURRENT_TIMESTAMP not null on update CURRENT_TIMESTAMP comment '最近一次更新时间',
update_time datetime default CURRENT_TIMESTAMP not null on update CURRENT_TIMESTAMP comment '更新时间',
constraint uk_user_id
unique (user_id) comment '用户余额唯一索引(一个用户对应一条余额记录)'
)
@@ -336,6 +337,75 @@ create index idx_order_id
on t_order_item (order_id)
comment '按订单查询商品的索引';
CREATE TABLE IF NOT EXISTS t_order_artist_review
(
id bigint unsigned auto_increment comment '评价任务ID'
primary key,
order_id bigint unsigned not null comment '订单ID',
order_item_id bigint unsigned not null comment '订单项ID',
customer_id bigint unsigned not null comment '下单客户ID',
shop_id bigint unsigned null comment '店铺ID',
artist_id bigint unsigned not null comment '被评价美甲师ID',
product_id bigint unsigned null comment '商品ID',
rating_score decimal(2, 1) null comment '评分,提交后必填0.5-5',
content varchar(1000) null comment '评价文字',
image_file_ids text null comment '评价图片文件ID集合',
status tinyint unsigned default 0 not null comment '状态:0-待评价,1-已评价',
reminder_message_id bigint unsigned null comment '提醒消息ID',
submitted_at datetime null comment '提交时间',
create_time datetime default CURRENT_TIMESTAMP not null comment '创建时间',
update_time datetime default CURRENT_TIMESTAMP not null on update CURRENT_TIMESTAMP comment '更新时间',
is_delete tinyint unsigned default 0 null comment '逻辑删除:0-未删,1-已删'
)
comment '订单美甲师评价任务表';
create unique index uk_order_artist_review_item
on t_order_artist_review (order_item_id, is_delete);
create index idx_order_artist_review_customer
on t_order_artist_review (customer_id, status, create_time);
create index idx_order_artist_review_artist
on t_order_artist_review (artist_id, status);
CREATE TABLE IF NOT EXISTS t_order_artist_change_request
(
id bigint unsigned auto_increment comment '改派申请ID'
primary key,
order_id bigint unsigned not null comment '订单ID',
order_item_id bigint unsigned not null comment '订单项ID',
customer_id bigint unsigned not null comment '下单客户ID',
shop_id bigint unsigned null comment '店铺ID',
product_id bigint unsigned null comment '商品ID',
from_artist_id bigint unsigned not null comment '原美甲师ID',
to_artist_id bigint unsigned not null comment '新美甲师ID',
requester_id bigint unsigned not null comment '申请人ID',
status varchar(20) default 'PENDING' not null comment '状态:PENDING/APPROVED/REJECTED',
reason varchar(500) null comment '申请原因',
reject_reason varchar(500) null comment '拒绝原因',
message_id bigint unsigned null comment '提醒消息ID',
pending_key varchar(80) null comment '待处理唯一键,PENDING时为订单项维度',
approved_time datetime null comment '同意时间',
rejected_time datetime null comment '拒绝时间',
expire_time datetime null comment '过期时间',
create_time datetime default CURRENT_TIMESTAMP not null comment '创建时间',
update_time datetime default CURRENT_TIMESTAMP not null on update CURRENT_TIMESTAMP comment '更新时间',
is_delete tinyint unsigned default 0 null comment '逻辑删除:0-未删,1-已删'
)
comment '订单美甲师改派申请表';
create index idx_order_artist_change_customer
on t_order_artist_change_request (customer_id, status, create_time);
create index idx_order_artist_change_artist
on t_order_artist_change_request (from_artist_id, to_artist_id, status);
create index idx_order_artist_change_shop
on t_order_artist_change_request (shop_id, status, create_time);
create unique index uk_order_artist_change_pending_key
on t_order_artist_change_request (pending_key);
-- auto-generated definition
create table t_permission
(
@@ -572,6 +642,10 @@ create table if not exists t_system_message
publisher_type tinyint not null comment '发布人类型:2-店长,4-管理员',
target_type varchar(30) not null comment '目标范围:PLATFORM_ALL/CURRENT_SHOP_ALL/SHOP_ALL/SELECTED_SHOPS/SELECTED_USERS',
target_ids text null comment '目标ID集合,多个ID以逗号分隔',
business_type varchar(64) null comment '业务类型',
business_id bigint unsigned null comment '业务ID',
action_path varchar(255) null comment '业务跳转路径',
idempotency_key varchar(160) null comment '业务消息幂等键',
popup_enabled tinyint unsigned default 1 not null comment '是否弹窗:1-弹窗,0-不弹窗',
status tinyint unsigned default 1 not null comment '状态:1-已发布,0-已撤回',
publish_time datetime default CURRENT_TIMESTAMP not null comment '发布时间',
@@ -587,6 +661,9 @@ create index idx_t_system_message_publish_time
create index idx_t_system_message_target
on t_system_message (target_type, status);
create unique index uk_t_system_message_idempotency
on t_system_message (idempotency_key);
create table if not exists t_system_message_user_state
(
id bigint unsigned auto_increment comment '用户消息状态主键'
@@ -804,6 +881,7 @@ DELIMITER ;
CALL sp_add_column_if_not_exists('t_balance', 'total_recharge_amount', 'decimal(10,2) NOT NULL DEFAULT 0.00 COMMENT ''累计充值金额''');
CALL sp_add_column_if_not_exists('t_balance', 'last_recharge_time', 'datetime NULL COMMENT ''最近一次充值时间''');
CALL sp_add_column_if_not_exists('t_balance', 'update_time', 'datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT ''更新时间''');
UPDATE t_balance
SET total_recharge_amount = COALESCE(total_recharge_amount, 0.00)
@@ -1195,6 +1273,99 @@ CALL sp_add_column_if_not_exists('t_nail_artist_info', 'work_end_time', 'time NU
CALL sp_add_index_if_not_exists('t_nail_artist_info', 'idx_t_nail_artist_info_participate', '(`participate_production`, `status`)');
CALL sp_add_column_if_not_exists('t_system_message', 'image_file_id', 'bigint unsigned NULL COMMENT ''消息图片文件ID''');
CALL sp_add_column_if_not_exists('t_system_message', 'business_type', 'varchar(64) NULL COMMENT ''业务类型''');
CALL sp_add_column_if_not_exists('t_system_message', 'business_id', 'bigint unsigned NULL COMMENT ''业务ID''');
CALL sp_add_column_if_not_exists('t_system_message', 'action_path', 'varchar(255) NULL COMMENT ''业务跳转路径''');
CALL sp_add_column_if_not_exists('t_system_message', 'idempotency_key', 'varchar(160) NULL COMMENT ''业务消息幂等键''');
CREATE TABLE IF NOT EXISTS t_order_artist_review
(
id bigint unsigned auto_increment comment '评价任务ID'
primary key,
order_id bigint unsigned not null comment '订单ID',
order_item_id bigint unsigned not null comment '订单项ID',
customer_id bigint unsigned not null comment '下单客户ID',
shop_id bigint unsigned null comment '店铺ID',
artist_id bigint unsigned not null comment '被评价美甲师ID',
product_id bigint unsigned null comment '商品ID',
rating_score decimal(2, 1) null comment '评分,提交后必填0.5-5',
content varchar(1000) null comment '评价文字',
image_file_ids text null comment '评价图片文件ID集合',
status tinyint unsigned default 0 not null comment '状态:0-待评价,1-已评价',
reminder_message_id bigint unsigned null comment '提醒消息ID',
submitted_at datetime null comment '提交时间',
create_time datetime default CURRENT_TIMESTAMP not null comment '创建时间',
update_time datetime default CURRENT_TIMESTAMP not null on update CURRENT_TIMESTAMP comment '更新时间',
is_delete tinyint unsigned default 0 null comment '逻辑删除:0-未删,1-已删'
)
comment '订单美甲师评价任务表';
CREATE TABLE IF NOT EXISTS t_order_artist_change_request
(
id bigint unsigned auto_increment comment '改派申请ID'
primary key,
order_id bigint unsigned not null comment '订单ID',
order_item_id bigint unsigned not null comment '订单项ID',
customer_id bigint unsigned not null comment '下单客户ID',
shop_id bigint unsigned null comment '店铺ID',
product_id bigint unsigned null comment '商品ID',
from_artist_id bigint unsigned not null comment '原美甲师ID',
to_artist_id bigint unsigned not null comment '新美甲师ID',
requester_id bigint unsigned not null comment '申请人ID',
status varchar(20) default 'PENDING' not null comment '状态:PENDING/APPROVED/REJECTED',
reason varchar(500) null comment '申请原因',
reject_reason varchar(500) null comment '拒绝原因',
message_id bigint unsigned null comment '提醒消息ID',
pending_key varchar(80) null comment '待处理唯一键,PENDING时为订单项维度',
approved_time datetime null comment '同意时间',
rejected_time datetime null comment '拒绝时间',
expire_time datetime null comment '过期时间',
create_time datetime default CURRENT_TIMESTAMP not null comment '创建时间',
update_time datetime default CURRENT_TIMESTAMP not null on update CURRENT_TIMESTAMP comment '更新时间',
is_delete tinyint unsigned default 0 null comment '逻辑删除:0-未删,1-已删'
)
comment '订单美甲师改派申请表';
CALL sp_add_unique_index_if_not_exists('t_order_artist_review', 'uk_order_artist_review_item', '(`order_item_id`, `is_delete`)');
CALL sp_add_index_if_not_exists('t_order_artist_review', 'idx_order_artist_review_customer', '(`customer_id`, `status`, `create_time`)');
CALL sp_add_index_if_not_exists('t_order_artist_review', 'idx_order_artist_review_artist', '(`artist_id`, `status`)');
CALL sp_add_index_if_not_exists('t_order_artist_review', 'idx_order_artist_review_order', '(`order_id`)');
CALL sp_add_unique_index_if_not_exists('t_system_message', 'uk_t_system_message_idempotency', '(`idempotency_key`)');
CALL sp_add_column_if_not_exists('t_order_artist_change_request', 'pending_key', 'varchar(80) NULL COMMENT ''待处理唯一键,PENDING时为订单项维度''');
CALL sp_add_unique_index_if_not_exists('t_order_artist_change_request', 'uk_order_artist_change_pending_key', '(`pending_key`)');
CALL sp_add_index_if_not_exists('t_order_artist_change_request', 'idx_order_artist_change_item_status', '(`order_item_id`, `status`, `is_delete`)');
CALL sp_add_index_if_not_exists('t_order_artist_change_request', 'idx_order_artist_change_customer', '(`customer_id`, `status`, `create_time`)');
CALL sp_add_index_if_not_exists('t_order_artist_change_request', 'idx_order_artist_change_artist', '(`from_artist_id`, `to_artist_id`, `status`)');
CALL sp_add_index_if_not_exists('t_order_artist_change_request', 'idx_order_artist_change_shop', '(`shop_id`, `status`, `create_time`)');
CALL sp_add_index_if_not_exists('t_order_artist_change_request', 'idx_order_artist_change_expire', '(`status`, `expire_time`, `is_delete`)');
CREATE TABLE IF NOT EXISTS t_business_event_outbox
(
id bigint unsigned auto_increment comment '事件ID'
primary key,
event_key varchar(160) not null comment '事件幂等键',
event_type varchar(64) not null comment '事件类型',
business_type varchar(64) not null comment '业务类型',
business_id bigint unsigned not null comment '业务ID',
payload_json text null comment '事件载荷',
status varchar(20) default 'PENDING' not null comment 'PENDING/PROCESSING/SUCCEEDED/FAILED',
retry_count int unsigned default 0 not null comment '重试次数',
next_retry_time datetime null comment '下次重试时间',
last_error varchar(500) null comment '最近错误',
claimed_at datetime null comment '认领时间',
processed_at datetime null comment '处理完成时间',
create_time datetime default CURRENT_TIMESTAMP not null comment '创建时间',
update_time datetime default CURRENT_TIMESTAMP not null on update CURRENT_TIMESTAMP comment '更新时间',
is_delete tinyint unsigned default 0 null comment '逻辑删除'
)
comment '业务事件Outbox表';
CALL sp_add_unique_index_if_not_exists('t_business_event_outbox', 'uk_business_event_outbox_event_key', '(`event_key`)');
CALL sp_add_index_if_not_exists('t_business_event_outbox', 'idx_business_event_outbox_due', '(`status`, `next_retry_time`, `create_time`)');
-- Artist change requests can be expired asynchronously; expired rows release pending_key for a new request.
-- EXPIRED
CREATE TABLE IF NOT EXISTS `t_messagehub_push_config` (
`id` bigint unsigned NOT NULL COMMENT '主键ID',
`scene_code` varchar(80) NOT NULL COMMENT '业务场景编码',
@@ -1312,6 +1483,15 @@ ON DUPLICATE KEY UPDATE
update_time = NOW(),
is_delete = 0;
INSERT INTO t_permission (permission_code, permission_name, permission_group, description, create_time, update_time, is_delete)
VALUES ('order:artist-change', '处理改派申请', '订单管理', '处理订单美甲师改派申请', NOW(), NOW(), 0)
ON DUPLICATE KEY UPDATE
permission_name = VALUES(permission_name),
permission_group = VALUES(permission_group),
description = VALUES(description),
update_time = NOW(),
is_delete = 0;
INSERT INTO t_user (
shop_id,
nickname,
@@ -1396,6 +1576,7 @@ INNER JOIN t_permission p
'comment:delete',
'order:view',
'order:process',
'order:artist-change',
'order:edit',
'order:delete',
'nail_artist:view',
@@ -1456,6 +1637,7 @@ INNER JOIN t_permission p
'comment:delete',
'order:view',
'order:process',
'order:artist-change',
'order:edit',
'order:delete',
'nail_artist:view',
@@ -1482,17 +1664,15 @@ INNER JOIN t_permission p
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',
'comment:view',
'order:view',
'order:process'
'order:process',
'order:artist-change'
)
WHERE u.is_delete = 0
AND u.type = 3
@@ -1884,3 +2064,13 @@ ON DUPLICATE KEY UPDATE
is_delete = 0,
update_by = VALUES(update_by),
update_time = NOW();
INSERT INTO t_permission (id, permission_code, permission_name, permission_group, description, create_time, update_time, is_delete)
VALUES
(313931273555136602, 'security:audit:view', '查看安全审计', '安全审计', '查看高危操作和登录安全审计日志', NOW(), NOW(), 0)
ON DUPLICATE KEY UPDATE
permission_name = VALUES(permission_name),
permission_group = VALUES(permission_group),
description = VALUES(description),
is_delete = 0,
update_time = NOW();