将历史补单字段合并到初始化SQL
This commit is contained in:
@@ -336,14 +336,18 @@ create table t_order
|
||||
id bigint unsigned auto_increment comment '订单主键索引'
|
||||
primary key,
|
||||
order_no varchar(50) not null comment '订单编号',
|
||||
user_id bigint unsigned not null comment '关联用户表主键',
|
||||
user_id bigint unsigned null comment '关联用户表主键,历史补单可为空',
|
||||
shop_id bigint unsigned null comment '所属店铺ID',
|
||||
total_amount decimal(10, 2) not null comment '订单总金额',
|
||||
actual_amount decimal(10, 2) not null comment '实际支付金额',
|
||||
coupon_id bigint unsigned default 0 null comment '使用的优惠券ID',
|
||||
user_coupon_id bigint unsigned null comment '用户券ID',
|
||||
coupon_source_type varchar(32) null comment '优惠来源类型',
|
||||
status tinyint unsigned default 1 not null comment '订单状态:1-待使用,2-已完成,3-已取消',
|
||||
customer_remark varchar(500) null comment '用户询价预约备注',
|
||||
customer_name_snapshot varchar(100) null comment '补单客户名称快照',
|
||||
customer_phone_snapshot varchar(32) null comment '补单客户手机号快照',
|
||||
order_source varchar(32) default 'NORMAL_APPOINTMENT' not null comment '订单来源:NORMAL_APPOINTMENT/HISTORICAL_BACKFILL',
|
||||
status tinyint unsigned default 1 not null comment '订单状态:0-价格确认中,1-待服务,2-已完成,3-已取消,4-服务中',
|
||||
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-已删',
|
||||
@@ -360,6 +364,10 @@ create index idx_user_id
|
||||
on t_order (user_id)
|
||||
comment '按用户查询订单的索引';
|
||||
|
||||
create index idx_order_source_status_delete
|
||||
on t_order (order_source, status, is_delete)
|
||||
comment '按订单来源和状态查询的索引';
|
||||
|
||||
-- auto-generated definition
|
||||
create table t_order_item
|
||||
(
|
||||
@@ -371,6 +379,7 @@ create table t_order_item
|
||||
price decimal(10, 2) not null comment '商品单价',
|
||||
artist_id bigint unsigned null comment '关联美甲师ID',
|
||||
appointment_time datetime null comment '预约开始时间',
|
||||
service_date date 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-已删'
|
||||
@@ -381,6 +390,10 @@ create index idx_order_id
|
||||
on t_order_item (order_id)
|
||||
comment '按订单查询商品的索引';
|
||||
|
||||
create index idx_order_item_artist_service_date
|
||||
on t_order_item (artist_id, service_date, is_delete)
|
||||
comment '按员工和业务服务日期查询的索引';
|
||||
|
||||
CREATE TABLE IF NOT EXISTS t_order_artist_review
|
||||
(
|
||||
id bigint unsigned auto_increment comment '评价任务ID'
|
||||
@@ -1050,8 +1063,22 @@ CALL sp_add_index_if_not_exists('t_balance_change_detail', 'idx_balance_detail_o
|
||||
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''');
|
||||
|
||||
SET @sql = (SELECT IF(COUNT(*) = 0,
|
||||
'ALTER TABLE t_order MODIFY COLUMN user_id BIGINT UNSIGNED NULL COMMENT ''关联用户表主键,历史补单可为空''',
|
||||
'SELECT 1') FROM information_schema.columns
|
||||
WHERE table_schema = DATABASE() AND table_name = 't_order' AND column_name = 'user_id' AND is_nullable = 'YES');
|
||||
PREPARE stmt FROM @sql; EXECUTE stmt; DEALLOCATE PREPARE stmt;
|
||||
|
||||
CALL sp_add_column_if_not_exists('t_order', 'customer_remark', 'varchar(500) NULL COMMENT ''用户询价预约备注''');
|
||||
CALL sp_add_column_if_not_exists('t_order', 'customer_name_snapshot', 'varchar(100) NULL COMMENT ''补单客户名称快照''');
|
||||
CALL sp_add_column_if_not_exists('t_order', 'customer_phone_snapshot', 'varchar(32) NULL COMMENT ''补单客户手机号快照''');
|
||||
CALL sp_add_column_if_not_exists('t_order', 'order_source', 'varchar(32) NOT NULL DEFAULT ''NORMAL_APPOINTMENT'' COMMENT ''订单来源:NORMAL_APPOINTMENT/HISTORICAL_BACKFILL''');
|
||||
|
||||
CALL sp_add_column_if_not_exists('t_order_item', 'appointment_time', 'datetime NULL COMMENT ''预约开始时间''');
|
||||
CALL sp_add_column_if_not_exists('t_order_item', 'service_date', 'date 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_index_if_not_exists('t_order', 'idx_order_source_status_delete', '(`order_source`, `status`, `is_delete`)');
|
||||
CALL sp_add_index_if_not_exists('t_order_item', 'idx_order_item_artist_service_date', '(`artist_id`, `service_date`, `is_delete`)');
|
||||
|
||||
SET @drop_old_tag_unique_sql = (
|
||||
SELECT IF(
|
||||
|
||||
@@ -1,43 +0,0 @@
|
||||
-- 历史补单与服务中状态(可重复执行)
|
||||
-- 不执行数据迁移,仅为新部署环境补充字段。
|
||||
SET @db_name = DATABASE();
|
||||
|
||||
SET @sql = (SELECT IF(COUNT(*) = 0,
|
||||
'ALTER TABLE t_order MODIFY COLUMN user_id BIGINT UNSIGNED NULL COMMENT ''客户用户ID,补单可为空''',
|
||||
'SELECT 1') FROM information_schema.columns
|
||||
WHERE table_schema = @db_name AND table_name = 't_order' AND column_name = 'user_id' AND is_nullable = 'YES');
|
||||
PREPARE stmt FROM @sql; EXECUTE stmt; DEALLOCATE PREPARE stmt;
|
||||
|
||||
SET @sql = (SELECT IF(COUNT(*) = 0,
|
||||
'ALTER TABLE t_order ADD COLUMN customer_name_snapshot VARCHAR(100) NULL COMMENT ''补单客户名称快照'' AFTER customer_remark',
|
||||
'SELECT 1') FROM information_schema.columns WHERE table_schema = @db_name AND table_name = 't_order' AND column_name = 'customer_name_snapshot');
|
||||
PREPARE stmt FROM @sql; EXECUTE stmt; DEALLOCATE PREPARE stmt;
|
||||
|
||||
SET @sql = (SELECT IF(COUNT(*) = 0,
|
||||
'ALTER TABLE t_order ADD COLUMN customer_phone_snapshot VARCHAR(32) NULL COMMENT ''补单客户手机号快照'' AFTER customer_name_snapshot',
|
||||
'SELECT 1') FROM information_schema.columns WHERE table_schema = @db_name AND table_name = 't_order' AND column_name = 'customer_phone_snapshot');
|
||||
PREPARE stmt FROM @sql; EXECUTE stmt; DEALLOCATE PREPARE stmt;
|
||||
|
||||
SET @sql = (SELECT IF(COUNT(*) = 0,
|
||||
'ALTER TABLE t_order ADD COLUMN order_source VARCHAR(32) NOT NULL DEFAULT ''NORMAL_APPOINTMENT'' COMMENT ''订单来源'' AFTER customer_remark',
|
||||
'SELECT 1') FROM information_schema.columns
|
||||
WHERE table_schema = @db_name AND table_name = 't_order' AND column_name = 'order_source');
|
||||
PREPARE stmt FROM @sql; EXECUTE stmt; DEALLOCATE PREPARE stmt;
|
||||
|
||||
SET @sql = (SELECT IF(COUNT(*) = 0,
|
||||
'ALTER TABLE t_order_item ADD COLUMN service_date DATE NULL COMMENT ''业务服务日期,历史补单无具体时间时使用'' AFTER appointment_time',
|
||||
'SELECT 1') FROM information_schema.columns
|
||||
WHERE table_schema = @db_name AND table_name = 't_order_item' AND column_name = 'service_date');
|
||||
PREPARE stmt FROM @sql; EXECUTE stmt; DEALLOCATE PREPARE stmt;
|
||||
|
||||
SET @sql = (SELECT IF(COUNT(*) = 0,
|
||||
'ALTER TABLE t_order ADD INDEX idx_order_source_status_delete (order_source, status, is_delete)',
|
||||
'SELECT 1') FROM information_schema.statistics
|
||||
WHERE table_schema = @db_name AND table_name = 't_order' AND index_name = 'idx_order_source_status_delete');
|
||||
PREPARE stmt FROM @sql; EXECUTE stmt; DEALLOCATE PREPARE stmt;
|
||||
|
||||
SET @sql = (SELECT IF(COUNT(*) = 0,
|
||||
'ALTER TABLE t_order_item ADD INDEX idx_order_item_artist_service_date (artist_id, service_date, is_delete)',
|
||||
'SELECT 1') FROM information_schema.statistics
|
||||
WHERE table_schema = @db_name AND table_name = 't_order_item' AND index_name = 'idx_order_item_artist_service_date');
|
||||
PREPARE stmt FROM @sql; EXECUTE stmt; DEALLOCATE PREPARE stmt;
|
||||
@@ -2,4 +2,4 @@
|
||||
|
||||
历史补单使用订单来源 `HISTORICAL_BACKFILL`,状态 `4` 表示服务中。补单必须归属员工,可不填写客户和具体服务时间;没有具体时间时仅按 `service_date` 参与规划日期统计,不创建预约占用,也不执行排班冲突校验。
|
||||
|
||||
数据库字段由 `docs/scripts/sql/versions/历史补单与服务中状态_20261013.sql` 增补。该脚本只修改字段和索引,不连接或清理已有业务数据。
|
||||
数据库字段和索引已融合到 `docs/scripts/sql/init/jayucloud-salon.sql`,初始化脚本可重复执行,不连接或清理已有业务数据。
|
||||
|
||||
@@ -14,4 +14,4 @@
|
||||
|
||||
## 兼容与验证
|
||||
|
||||
普通预约接口和状态流转保持原规则。数据库字段通过 `docs/scripts/sql/versions/历史补单与服务中状态_20261013.sql` 增补,不修改冻结初始化 SQL;后端编译通过,客户端脚本执行语法检查。
|
||||
普通预约接口和状态流转保持原规则。数据库字段和索引统一写入 `docs/scripts/sql/init/jayucloud-salon.sql`,脚本可重复执行;后端编译通过,客户端脚本执行语法检查。
|
||||
|
||||
+1
-1
@@ -184,4 +184,4 @@
|
||||
- 新增历史补单接口与小程序独立补单页面,补单可直接进入“服务中”或“已完成”。
|
||||
- 新增 `IN_SERVICE(4)` 状态、历史补单来源和服务日期字段;无具体时间的补单仅参与日期统计,不创建预约占用。
|
||||
- 规划页增加补录入口、历史补单展示,后台订单筛选增加服务中状态。
|
||||
- 数据库字段与索引变更见 `docs/scripts/sql/versions/历史补单与服务中状态_20261013.sql`。
|
||||
- 数据库字段与索引已融合到 `docs/scripts/sql/init/jayucloud-salon.sql`,初始化脚本可重复执行。
|
||||
|
||||
Reference in New Issue
Block a user