旅游团sql-update

This commit is contained in:
2026-03-20 18:39:46 +08:00
parent e8573b90db
commit 2cf3aa552a

View File

@@ -68,44 +68,64 @@ COMMENT ON COLUMN tour_product.is_deleted IS '是否已删除:0=未删除,1=
DROP TABLE IF EXISTS tour_order_traveler; DROP TABLE IF EXISTS tour_order_detail;
CREATE TABLE tour_order_traveler
CREATE TABLE tour_order_detail
( (
id int8 NOT NULL PRIMARY KEY, -- 主键ID id int8 NOT NULL PRIMARY KEY, -- 主键ID
order_id int8 NOT NULL, -- 关联订单ID order_id int8 NOT NULL, -- 关联订单ID (主表 tour_order 的ID)
user_id int8 NOT NULL, user_id int8 NOT NULL, -- 下单用户ID
traveler_detail text DEFAULT NULL, -- 出行信息快照 traveler_detail jsonb DEFAULT NULL, -- 出行人信息快照 (数组格式,冗余存储,防止档案修改影响历史订单)
start_date timestamp(6) DEFAULT NULL, -- 出行日期 product_snapshot jsonb DEFAULT NULL, -- 产品信息快照 (数组格式,包含线路名称、单价、数量、规格等,防止产品下架/改价影响历史订单)
contract_url varchar(500) DEFAULT NULL, -- 电子合同地址/编号 (存储生成的合同PDF路径或第三方合同号)
contract_status int4 DEFAULT 0, -- 合同状态:0=未签署,1=已签署,2=已过期 (扩展字段,建议加上)
guide_name varchar(50) DEFAULT NULL, -- 导游姓名
guide_phone varchar(20) DEFAULT NULL, -- 导游联系电话
start_date timestamp(6) DEFAULT NULL, -- 出行日期 (具体出发时间)
end_date timestamp(6) DEFAULT NULL, -- 预计返回日期 end_date timestamp(6) DEFAULT NULL, -- 预计返回日期
remark varchar(255) DEFAULT NULL, -- 订单备注 (用户留言或内部备注)
create_user int8 NULL, -- 创建人ID create_user int8 NULL, -- 创建人ID
create_dept int8 NULL, -- 创建部门ID create_dept int8 NULL, -- 创建部门ID
create_time timestamp(6) NULL, -- 创建时间 create_time timestamp(6) NULL, -- 创建时间
update_user int8 NULL, -- 修改人ID update_user int8 NULL, -- 修改人ID
update_time timestamp(6) NULL, -- 修改时间 update_time timestamp(6) NULL, -- 修改时间
status int4 NULL DEFAULT 1, -- 状态:0=无效,1=有效 status int4 NULL DEFAULT 1, -- 状态:0=下架,1=上架
is_deleted int4 DEFAULT 0 NULL -- 是否已删除:0=未删除,1=已删除 is_deleted int4 DEFAULT 0 NULL -- 是否已删除:0=未删除,1=已删除
); );
COMMENT ON TABLE tour_order_traveler IS '订单出行人明细表'; -- 表注释
COMMENT ON COLUMN tour_order_traveler.id IS '主键ID'; COMMENT ON TABLE tour_order_detail IS '订单详情扩展表';
COMMENT ON COLUMN tour_order_traveler.order_id IS '关联订单ID';
COMMENT ON COLUMN tour_user_profile.user_id IS '关联系统用户ID (所属人)';
COMMENT ON COLUMN tour_order_traveler.traveler_detail IS '出行信息快照';
COMMENT ON COLUMN tour_order_traveler.start_date IS '出行日期';
COMMENT ON COLUMN tour_order_traveler.end_date IS '预计返回日期';
COMMENT ON COLUMN tour_order_traveler.create_user IS '创建人ID';
COMMENT ON COLUMN tour_order_traveler.create_dept IS '创建部门ID';
COMMENT ON COLUMN tour_order_traveler.create_time IS '创建时间';
COMMENT ON COLUMN tour_order_traveler.update_user IS '修改人ID';
COMMENT ON COLUMN tour_order_traveler.update_time IS '修改时间';
COMMENT ON COLUMN tour_order_traveler.status IS '状态:0=无效,1=有效';
COMMENT ON COLUMN tour_order_traveler.is_deleted IS '是否已删除:0=未删除,1=已删除';
CREATE INDEX idx_tot_oid ON tour_order_traveler (order_id); -- 字段注释
CREATE INDEX idx_tot_uid ON tour_order_traveler (user_id); COMMENT ON COLUMN tour_order_detail.id IS '主键ID';
COMMENT ON COLUMN tour_order_detail.order_id IS '关联订单ID';
COMMENT ON COLUMN tour_order_detail.user_id IS '下单用户ID';
COMMENT ON COLUMN tour_order_detail.traveler_detail IS '出行人信息快照 (JSONB数组)';
COMMENT ON COLUMN tour_order_detail.product_snapshot IS '产品信息快照 (JSONB数组)';
COMMENT ON COLUMN tour_order_detail.contract_url IS '电子合同地址或编号';
COMMENT ON COLUMN tour_order_detail.contract_status IS '合同签署状态:0=未签署,1=已签署,2=已过期';
COMMENT ON COLUMN tour_order_detail.guide_name IS '导游姓名';
COMMENT ON COLUMN tour_order_detail.guide_phone IS '导游联系电话';
COMMENT ON COLUMN tour_order_detail.start_date IS '出行日期';
COMMENT ON COLUMN tour_order_detail.end_date IS '预计返回日期';
COMMENT ON COLUMN tour_order_detail.remark IS '备注信息';
COMMENT ON COLUMN tour_order_detail.create_user IS '创建人ID';
COMMENT ON COLUMN tour_order_detail.create_dept IS '创建部门ID';
COMMENT ON COLUMN tour_order_detail.create_time IS '创建时间';
COMMENT ON COLUMN tour_order_detail.update_user IS '修改人ID';
COMMENT ON COLUMN tour_order_detail.update_time IS '修改时间';
COMMENT ON COLUMN tour_order_detail.status IS '数据状态:0=无效,1=有效';
COMMENT ON COLUMN tour_order_detail.is_deleted IS '是否已删除:0=未删除,1=已删除';
DROP TABLE IF EXISTS tour_user_profile; -- 索引优化
CREATE TABLE tour_user_profile -- 1. 关联订单查询 (最常用)
CREATE INDEX idx_tod_order_id ON tour_order_detail (order_id);
-- 2. 用户查询我的订单详情
CREATE INDEX idx_tod_user_id ON tour_order_detail (user_id);
DROP TABLE IF EXISTS common_tour_info;
CREATE TABLE common_tour_info
( (
id int8 NOT NULL PRIMARY KEY, -- 主键ID id int8 NOT NULL PRIMARY KEY, -- 主键ID
user_id int8 NOT NULL, -- 关联系统用户ID user_id int8 NOT NULL, -- 关联系统用户ID
@@ -127,23 +147,23 @@ CREATE TABLE tour_user_profile
); );
-- 表注释 -- 表注释
COMMENT ON TABLE tour_user_profile IS '基础出行人档案表'; COMMENT ON TABLE common_tour_info IS '基础出行人档案表';
COMMENT ON COLUMN tour_user_profile.id IS '主键ID'; COMMENT ON COLUMN common_tour_info.id IS '主键ID';
COMMENT ON COLUMN tour_user_profile.user_id IS '关联系统用户ID (所属人)'; COMMENT ON COLUMN common_tour_info.user_id IS '关联系统用户ID (所属人)';
COMMENT ON COLUMN tour_user_profile.id_card_no IS '身份证号'; COMMENT ON COLUMN common_tour_info.id_card_no IS '身份证号';
COMMENT ON COLUMN tour_user_profile.passport_no IS '护照号码'; COMMENT ON COLUMN common_tour_info.passport_no IS '护照号码';
COMMENT ON COLUMN tour_user_profile.hk_macau_pass_no IS '港澳通行证号码'; COMMENT ON COLUMN common_tour_info.hk_macau_pass_no IS '港澳通行证号码';
COMMENT ON COLUMN tour_user_profile.user_name IS '姓名'; COMMENT ON COLUMN common_tour_info.user_name IS '姓名';
COMMENT ON COLUMN tour_user_profile.gender IS '性别:1=男,2=女'; COMMENT ON COLUMN common_tour_info.gender IS '性别:1=男,2=女';
COMMENT ON COLUMN tour_user_profile.contact_phone IS '本人手机号'; COMMENT ON COLUMN common_tour_info.contact_phone IS '本人手机号';
COMMENT ON COLUMN tour_user_profile.traveler_type IS '默认人员类型:1=成人,2=儿童,3=老人'; COMMENT ON COLUMN common_tour_info.traveler_type IS '默认人员类型:1=成人,2=儿童,3=老人';
COMMENT ON COLUMN tour_user_profile.remark IS '备注偏好'; COMMENT ON COLUMN common_tour_info.remark IS '备注偏好';
COMMENT ON COLUMN tour_user_profile.create_user IS '创建人ID'; COMMENT ON COLUMN common_tour_info.create_user IS '创建人ID';
COMMENT ON COLUMN tour_user_profile.create_dept IS '创建部门ID'; COMMENT ON COLUMN common_tour_info.create_dept IS '创建部门ID';
COMMENT ON COLUMN tour_user_profile.create_time IS '创建时间'; COMMENT ON COLUMN common_tour_info.create_time IS '创建时间';
COMMENT ON COLUMN tour_user_profile.update_user IS '修改人ID'; COMMENT ON COLUMN common_tour_info.update_user IS '修改人ID';
COMMENT ON COLUMN tour_user_profile.update_time IS '修改时间'; COMMENT ON COLUMN common_tour_info.update_time IS '修改时间';
COMMENT ON COLUMN tour_user_profile.is_deleted IS '是否已删除:0=未删除,1=已删除'; COMMENT ON COLUMN common_tour_info.is_deleted IS '是否已删除:0=未删除,1=已删除';
CREATE INDEX idx_tup_uid ON tour_user_profile (user_id); CREATE INDEX idx_tup_uid ON common_tour_info (user_id);