商家店铺, 资讯, 文旅sql

This commit is contained in:
2026-03-18 11:07:51 +08:00
parent 3712034b1d
commit fca67baccb

View File

@@ -0,0 +1,203 @@
DROP TABLE IF EXISTS merchant_flagship_store CASCADE;
CREATE TABLE merchant_flagship_store
(
id int8 NOT NULL PRIMARY KEY, -- [主键]
store_name VARCHAR(255) NOT NULL, -- 商家全称
contact_phone VARCHAR(20), -- 商家联系电话
regions_id int8 NOT NULL,
full_address text NOT NULL, -- 详细地址
location geometry(Point, 4326) NOT NULL, -- 门店经纬度坐标(用于地图打点和距离计算)
thumbnail_url text, -- 缩略图
main_image_url text[] default '{}'::text[], -- 商家主图
detail_images text[] default '{}'::text[], -- 详情展示多图
business_hours VARCHAR(100), -- 营业时间描述
store_description text, -- 商家详细介绍
create_user int8 NULL, -- 创建人
create_dept int8 NULL, -- 创建部门
create_time timestamp(6) NULL, -- 创建时间
update_user int8 NULL, -- 修改人
update_time timestamp(6) NULL, -- 修改时间
status int4 NULL, -- 状态
is_deleted int4 DEFAULT 0 NULL -- 是否已删除
);
COMMENT ON TABLE merchant_flagship_store IS '商家旗舰店信息表';
COMMENT ON COLUMN merchant_flagship_store.id IS '主键 ID';
COMMENT ON COLUMN merchant_flagship_store.store_name IS '店铺名字';
COMMENT ON COLUMN merchant_flagship_store.contact_phone IS '商家联系电话';
COMMENT ON COLUMN merchant_flagship_store.regions_id IS '地址id';
COMMENT ON COLUMN merchant_flagship_store.full_address IS '完整详细地址';
COMMENT ON COLUMN merchant_flagship_store.location IS '地理坐标 POINT(经度,纬度),用于地图定位和距离计算';
COMMENT ON COLUMN merchant_flagship_store.main_image_url IS '商家主图';
COMMENT ON COLUMN merchant_flagship_store.thumbnail_url IS '缩略图';
COMMENT ON COLUMN merchant_flagship_store.detail_images IS '详情图';
COMMENT ON COLUMN merchant_flagship_store.business_hours IS '营业时间,如:10:00--23:00';
COMMENT ON COLUMN merchant_flagship_store.store_description IS '商家详细介绍';
COMMENT ON COLUMN merchant_flagship_store.create_user IS '创建人';
COMMENT ON COLUMN merchant_flagship_store.create_dept IS '创建部门';
COMMENT ON COLUMN merchant_flagship_store.create_time IS '创建时间';
COMMENT ON COLUMN merchant_flagship_store.update_user IS '修改人';
COMMENT ON COLUMN merchant_flagship_store.update_time IS '修改时间';
COMMENT ON COLUMN merchant_flagship_store.status IS '状态';
COMMENT ON COLUMN merchant_flagship_store.is_deleted IS '是否已删除';
-- 4.3 地理位置索引 (GiST):核心!用于“附近店铺”查询和距离排序
CREATE INDEX idx_mfs_location ON merchant_flagship_store USING gist(location);
DROP TABLE IF EXISTS cultural_tourism_spot CASCADE;
CREATE TABLE cultural_tourism_spot
(
id int8 NOT NULL PRIMARY KEY, -- 自增主键
is_recommended int4 DEFAULT 0, -- 是否推荐
spot_name VARCHAR(255) NOT NULL, -- 景点名称
summary varchar(255), -- 简短摘要(列表页显示,如:“中国最美的地方”)
rating NUMERIC(3, 2) DEFAULT 0.00, -- 用户评分
visit_count int4 DEFAULT 0, -- 出行人数
thumbnail_url text, -- 缩略图
main_image_url text[] default '{}'::text[], -- 主图
detail_images text[] default '{}'::text[], -- 详情多图集合
video_url text, -- 宣传视频链接
description text, -- 详细介绍
create_user int8 NULL, -- 创建人
create_dept int8 NULL, -- 创建部门
create_time timestamp(6) NULL, -- 创建时间
update_user int8 NULL, -- 修改人
update_time timestamp(6) NULL, -- 修改时间
status int4 NULL, -- 状态
is_deleted int4 DEFAULT 0 NULL -- 是否已删除
);
COMMENT ON TABLE cultural_tourism_spot IS '文旅景点信息表';
COMMENT ON COLUMN cultural_tourism_spot.id IS '主键ID';
COMMENT ON COLUMN cultural_tourism_spot.is_recommended IS '是否推荐';
COMMENT ON COLUMN cultural_tourism_spot.spot_name IS '景点全称';
COMMENT ON COLUMN cultural_tourism_spot.rating IS '用户评分,范围0.00~5.00';
COMMENT ON COLUMN cultural_tourism_spot.visit_count IS '出行人数';
COMMENT ON COLUMN cultural_tourism_spot.thumbnail_url IS '缩略图';
COMMENT ON COLUMN cultural_tourism_spot.main_image_url IS '主图';
COMMENT ON COLUMN cultural_tourism_spot.detail_images IS '详情图';
COMMENT ON COLUMN cultural_tourism_spot.video_url IS '宣传视频链接';
COMMENT ON COLUMN cultural_tourism_spot.summary IS '简短摘要';
COMMENT ON COLUMN cultural_tourism_spot.description IS '详细介绍';
COMMENT ON COLUMN cultural_tourism_spot.create_user IS '创建人';
COMMENT ON COLUMN cultural_tourism_spot.create_dept IS '创建部门';
COMMENT ON COLUMN cultural_tourism_spot.create_time IS '创建时间';
COMMENT ON COLUMN cultural_tourism_spot.update_user IS '修改人';
COMMENT ON COLUMN cultural_tourism_spot.update_time IS '修改时间';
COMMENT ON COLUMN cultural_tourism_spot.status IS '状态';
COMMENT ON COLUMN cultural_tourism_spot.is_deleted IS '是否已删除';
DROP TABLE IF EXISTS news_category CASCADE;
CREATE TABLE news_category
(
id int8 NOT NULL PRIMARY KEY, -- 自增主键
category_name VARCHAR(50) NOT NULL, -- 分类名称
sort_order int4 DEFAULT 0, -- 排序
is_top int4 DEFAULT 0, -- 是否置顶
create_user int8 NULL, -- 创建人
create_dept int8 NULL, -- 创建部门
create_time timestamp(6) NULL, -- 创建时间
update_user int8 NULL, -- 修改人
update_time timestamp(6) NULL, -- 修改时间
status int4 NULL, -- 状态
is_deleted int4 DEFAULT 0 NULL -- 是否已删除
);
COMMENT ON TABLE news_category IS '资讯分类表,用于管理顶部导航标签';
COMMENT ON COLUMN news_category.id IS '主键';
COMMENT ON COLUMN news_category.category_name IS '分类名称';
COMMENT ON COLUMN news_category.sort_order IS '排序';
COMMENT ON COLUMN news_category.is_top IS '是否置顶';
COMMENT ON COLUMN news_category.create_user IS '创建人';
COMMENT ON COLUMN news_category.create_dept IS '创建部门';
COMMENT ON COLUMN news_category.create_time IS '创建时间';
COMMENT ON COLUMN news_category.update_user IS '修改人';
COMMENT ON COLUMN news_category.update_time IS '修改时间';
COMMENT ON COLUMN news_category.status IS '状态';
COMMENT ON COLUMN news_category.is_deleted IS '是否已删除';
CREATE INDEX idx_nc_pinned_sort ON news_category(is_top DESC, sort_order DESC, create_time DESC);
DROP TABLE IF EXISTS news_content CASCADE;
-- =================================================================
-- 2. 创建资讯内容表
-- =================================================================
CREATE TABLE news_content
(
id int8 NOT NULL PRIMARY KEY, -- 自增主键
category_id int8 NOT NULL, -- 所属分类ID
title VARCHAR(255) NOT NULL, -- 标题
summary varchar(255), -- 简短摘要
content_type int4 DEFAULT 0, -- 内容类型:0-图文 1-视频
video_url text, -- 视频链接
play_count int8 DEFAULT 0, -- 播放次数
thumbnail_url text, -- 缩略图
main_image_url text[] default '{}'::text[], -- 主图(
detail_images text[] default '{}'::text[], -- 详情多图集合
article_content text, -- 正文内容
comment_count int8 DEFAULT 0, -- 评论数量
is_featured int4 DEFAULT 0, -- 是否置顶
sort_order int4 DEFAULT 0, -- 排序
view_count int8 DEFAULT 0, -- 浏览次数
create_user int8 NULL, -- 创建人
create_dept int8 NULL, -- 创建部门
create_time timestamp(6) NULL, -- 创建时间
update_user int8 NULL, -- 修改人
update_time timestamp(6) NULL, -- 修改时间
status int4 NULL DEFAULT 1, -- 状态 ,0=下架,1=上架
is_deleted int4 DEFAULT 0 NULL -- 是否已删除
);
-- =================================================================
-- 3. 添加字段备注
-- =================================================================
COMMENT ON TABLE news_content IS '资讯内容表';
COMMENT ON COLUMN news_content.id IS '主键ID';
COMMENT ON COLUMN news_content.category_id IS '所属分类ID';
COMMENT ON COLUMN news_content.title IS '资讯标题';
COMMENT ON COLUMN news_content.summary IS '简短摘要';
COMMENT ON COLUMN news_content.content_type IS '内容类型 0-图文 1-视频';
COMMENT ON COLUMN news_content.video_url IS '视频链接';
COMMENT ON COLUMN news_content.play_count IS '视频播放次数';
COMMENT ON COLUMN news_content.thumbnail_url IS '缩略图';
COMMENT ON COLUMN news_content.main_image_url IS '主图';
COMMENT ON COLUMN news_content.detail_images IS '详情多图';
COMMENT ON COLUMN news_content.article_content IS '正文内容';
COMMENT ON COLUMN news_content.comment_count IS '评论数量';
COMMENT ON COLUMN news_content.is_featured IS '是否置顶';
COMMENT ON COLUMN news_content.sort_order IS '排序';
COMMENT ON COLUMN news_content.view_count IS '浏览次数';
COMMENT ON COLUMN news_content.create_user IS '创建人';
COMMENT ON COLUMN news_content.create_dept IS '创建部门';
COMMENT ON COLUMN news_content.create_time IS '创建时间';
COMMENT ON COLUMN news_content.update_user IS '修改人';
COMMENT ON COLUMN news_content.update_time IS '修改时间';
COMMENT ON COLUMN news_content.status IS '状态 0=下架,1=上架';
COMMENT ON COLUMN news_content.is_deleted IS '是否已删除';
CREATE INDEX idx_ncc_featured_sort ON news_content(is_featured DESC, sort_order DESC, create_time DESC);