/*
 Navicat Premium Data Transfer

 Source Server         : local
 Source Server Type    : PostgreSQL
 Source Server Version : 110005
 Source Host           : localhost:5432
 Source Catalog        : web_manage
 Source Schema         : public

 Target Server Type    : PostgreSQL
 Target Server Version : 110005
 File Encoding         : 65001

 Date: 14/08/2025 19:19:38
*/


-- ----------------------------
-- Sequence structure for cart_id_seq
-- ----------------------------
DROP SEQUENCE IF EXISTS "public"."cart_id_seq";
CREATE SEQUENCE "public"."cart_id_seq" 
INCREMENT 1
MINVALUE  1
MAXVALUE 9223372036854775807
START 1
CACHE 1;

-- ----------------------------
-- Sequence structure for order_approval_id_seq
-- ----------------------------
DROP SEQUENCE IF EXISTS "public"."order_approval_id_seq";
CREATE SEQUENCE "public"."order_approval_id_seq" 
INCREMENT 1
MINVALUE  1
MAXVALUE 9223372036854775807
START 1
CACHE 1;

-- ----------------------------
-- Sequence structure for order_attachment_id_seq
-- ----------------------------
DROP SEQUENCE IF EXISTS "public"."order_attachment_id_seq";
CREATE SEQUENCE "public"."order_attachment_id_seq" 
INCREMENT 1
MINVALUE  1
MAXVALUE 9223372036854775807
START 1
CACHE 1;

-- ----------------------------
-- Sequence structure for order_detail_id_seq
-- ----------------------------
DROP SEQUENCE IF EXISTS "public"."order_detail_id_seq";
CREATE SEQUENCE "public"."order_detail_id_seq" 
INCREMENT 1
MINVALUE  1
MAXVALUE 9223372036854775807
START 1
CACHE 1;

-- ----------------------------
-- Sequence structure for order_evaluation_id_seq
-- ----------------------------
DROP SEQUENCE IF EXISTS "public"."order_evaluation_id_seq";
CREATE SEQUENCE "public"."order_evaluation_id_seq" 
INCREMENT 1
MINVALUE  1
MAXVALUE 9223372036854775807
START 1
CACHE 1;

-- ----------------------------
-- Sequence structure for points_account_id_seq
-- ----------------------------
DROP SEQUENCE IF EXISTS "public"."points_account_id_seq";
CREATE SEQUENCE "public"."points_account_id_seq" 
INCREMENT 1
MINVALUE  1
MAXVALUE 9223372036854775807
START 1
CACHE 1;

-- ----------------------------
-- Sequence structure for points_flow_id_seq
-- ----------------------------
DROP SEQUENCE IF EXISTS "public"."points_flow_id_seq";
CREATE SEQUENCE "public"."points_flow_id_seq" 
INCREMENT 1
MINVALUE  1
MAXVALUE 9223372036854775807
START 1
CACHE 1;

-- ----------------------------
-- Sequence structure for points_id_seq
-- ----------------------------
DROP SEQUENCE IF EXISTS "public"."points_id_seq";
CREATE SEQUENCE "public"."points_id_seq" 
INCREMENT 1
MINVALUE  1
MAXVALUE 9223372036854775807
START 1
CACHE 1;

-- ----------------------------
-- Sequence structure for points_rule_detail_id_seq
-- ----------------------------
DROP SEQUENCE IF EXISTS "public"."points_rule_detail_id_seq";
CREATE SEQUENCE "public"."points_rule_detail_id_seq" 
INCREMENT 1
MINVALUE  1
MAXVALUE 9223372036854775807
START 1
CACHE 1;

-- ----------------------------
-- Sequence structure for points_rule_id_seq
-- ----------------------------
DROP SEQUENCE IF EXISTS "public"."points_rule_id_seq";
CREATE SEQUENCE "public"."points_rule_id_seq" 
INCREMENT 1
MINVALUE  1
MAXVALUE 9223372036854775807
START 1
CACHE 1;

-- ----------------------------
-- Sequence structure for points_transaction_id_seq
-- ----------------------------
DROP SEQUENCE IF EXISTS "public"."points_transaction_id_seq";
CREATE SEQUENCE "public"."points_transaction_id_seq" 
INCREMENT 1
MINVALUE  1
MAXVALUE 9223372036854775807
START 1
CACHE 1;

-- ----------------------------
-- Sequence structure for product_id_seq
-- ----------------------------
DROP SEQUENCE IF EXISTS "public"."product_id_seq";
CREATE SEQUENCE "public"."product_id_seq" 
INCREMENT 1
MINVALUE  1
MAXVALUE 9223372036854775807
START 1
CACHE 1;

-- ----------------------------
-- Sequence structure for product_pricing_id_seq
-- ----------------------------
DROP SEQUENCE IF EXISTS "public"."product_pricing_id_seq";
CREATE SEQUENCE "public"."product_pricing_id_seq" 
INCREMENT 1
MINVALUE  1
MAXVALUE 9223372036854775807
START 1
CACHE 1;

-- ----------------------------
-- Sequence structure for unit_id_seq
-- ----------------------------
DROP SEQUENCE IF EXISTS "public"."unit_id_seq";
CREATE SEQUENCE "public"."unit_id_seq" 
INCREMENT 1
MINVALUE  1
MAXVALUE 9223372036854775807
START 1
CACHE 1;

-- ----------------------------
-- Sequence structure for user_points_id_seq
-- ----------------------------
DROP SEQUENCE IF EXISTS "public"."user_points_id_seq";
CREATE SEQUENCE "public"."user_points_id_seq" 
INCREMENT 1
MINVALUE  1
MAXVALUE 9223372036854775807
START 1
CACHE 1;

-- ----------------------------
-- Sequence structure for users_id_seq
-- ----------------------------
DROP SEQUENCE IF EXISTS "public"."users_id_seq";
CREATE SEQUENCE "public"."users_id_seq" 
INCREMENT 1
MINVALUE  1
MAXVALUE 9223372036854775807
START 1
CACHE 1;

-- ----------------------------
-- Table structure for cart
-- ----------------------------
DROP TABLE IF EXISTS "public"."cart";
CREATE TABLE "public"."cart" (
  "id" int8 NOT NULL GENERATED ALWAYS AS IDENTITY (
INCREMENT 1
MINVALUE  1
MAXVALUE 9223372036854775807
START 1
),
  "user_id" int8 NOT NULL,
  "unit_id" int8 NOT NULL,
  "pricing_id" int8 NOT NULL,
  "product_id" int8 NOT NULL,
  "product_name" text COLLATE "pg_catalog"."default",
  "suite_name" text COLLATE "pg_catalog"."default",
  "sales_form" text COLLATE "pg_catalog"."default",
  "customer_type" text COLLATE "pg_catalog"."default",
  "account_limit" text COLLATE "pg_catalog"."default",
  "concurrent_nodes" text COLLATE "pg_catalog"."default",
  "price_type" text COLLATE "pg_catalog"."default",
  "price_unit" text COLLATE "pg_catalog"."default",
  "unit_price" numeric(15,2) NOT NULL,
  "quantity" int4 NOT NULL DEFAULT 1,
  "duration" int4,
  "total_price" numeric(15,2),
  "provider_id" int8,
  "provider_name" text COLLATE "pg_catalog"."default",
  "remarks" text COLLATE "pg_catalog"."default",
  "add_time" timestamp(6) DEFAULT CURRENT_TIMESTAMP,
  "update_time" timestamp(6) DEFAULT CURRENT_TIMESTAMP,
  "deleted" int4 DEFAULT 0
)
;
COMMENT ON TABLE "public"."cart" IS '购物车表';

-- ----------------------------
-- Records of cart
-- ----------------------------

-- ----------------------------
-- Table structure for order_approval
-- ----------------------------
DROP TABLE IF EXISTS "public"."order_approval";
CREATE TABLE "public"."order_approval" (
  "id" int8 NOT NULL GENERATED ALWAYS AS IDENTITY (
INCREMENT 1
MINVALUE  1
MAXVALUE 9223372036854775807
START 1
),
  "order_id" text COLLATE "pg_catalog"."default" NOT NULL,
  "approval_step" text COLLATE "pg_catalog"."default" NOT NULL,
  "approval_type" text COLLATE "pg_catalog"."default" NOT NULL,
  "approval_opinion" text COLLATE "pg_catalog"."default",
  "approval_result" text COLLATE "pg_catalog"."default" NOT NULL,
  "approver_id" int8 NOT NULL,
  "approver_name" text COLLATE "pg_catalog"."default" NOT NULL,
  "approver_role" text COLLATE "pg_catalog"."default",
  "approval_time" timestamp(6) DEFAULT CURRENT_TIMESTAMP,
  "next_approver_id" int8,
  "next_approver_name" text COLLATE "pg_catalog"."default",
  "workflow_status" text COLLATE "pg_catalog"."default",
  "created_at" timestamp(6) DEFAULT CURRENT_TIMESTAMP,
  "updated_at" timestamp(6) DEFAULT CURRENT_TIMESTAMP,
  "deleted" int4 DEFAULT 0
)
;
COMMENT ON TABLE "public"."order_approval" IS '订单审核表';

-- ----------------------------
-- Records of order_approval
-- ----------------------------

-- ----------------------------
-- Table structure for order_attachment
-- ----------------------------
DROP TABLE IF EXISTS "public"."order_attachment";
CREATE TABLE "public"."order_attachment" (
  "id" int8 NOT NULL GENERATED ALWAYS AS IDENTITY (
INCREMENT 1
MINVALUE  1
MAXVALUE 9223372036854775807
START 1
),
  "order_id" text COLLATE "pg_catalog"."default" NOT NULL,
  "file_name" text COLLATE "pg_catalog"."default" NOT NULL,
  "original_name" text COLLATE "pg_catalog"."default",
  "file_type" text COLLATE "pg_catalog"."default" NOT NULL,
  "file_size" int8 NOT NULL,
  "file_url" text COLLATE "pg_catalog"."default" NOT NULL,
  "file_path" text COLLATE "pg_catalog"."default",
  "bucket_name" text COLLATE "pg_catalog"."default",
  "object_name" text COLLATE "pg_catalog"."default",
  "upload_user_id" int8,
  "upload_user_name" text COLLATE "pg_catalog"."default",
  "attachment_type" text COLLATE "pg_catalog"."default",
  "description" text COLLATE "pg_catalog"."default",
  "created_at" timestamp(6) DEFAULT CURRENT_TIMESTAMP,
  "updated_at" timestamp(6) DEFAULT CURRENT_TIMESTAMP,
  "deleted" int4 DEFAULT 0
)
;
COMMENT ON TABLE "public"."order_attachment" IS '订单附件表';

-- ----------------------------
-- Records of order_attachment
-- ----------------------------

-- ----------------------------
-- Table structure for order_detail
-- ----------------------------
DROP TABLE IF EXISTS "public"."order_detail";
CREATE TABLE "public"."order_detail" (
  "id" int8 NOT NULL GENERATED ALWAYS AS IDENTITY (
INCREMENT 1
MINVALUE  1
MAXVALUE 9223372036854775807
START 1
),
  "order_id" text COLLATE "pg_catalog"."default" NOT NULL,
  "pricing_id" int8 NOT NULL,
  "product_id" int8 NOT NULL,
  "suite_name" text COLLATE "pg_catalog"."default" NOT NULL,
  "sales_form" text COLLATE "pg_catalog"."default" NOT NULL,
  "customer_type" text COLLATE "pg_catalog"."default" NOT NULL,
  "account_limit" text COLLATE "pg_catalog"."default",
  "concurrent_nodes" text COLLATE "pg_catalog"."default",
  "price_type" text COLLATE "pg_catalog"."default" NOT NULL,
  "price_unit" text COLLATE "pg_catalog"."default" NOT NULL,
  "unit_price" numeric(15,2) NOT NULL,
  "quantity" int4 NOT NULL,
  "duration" int4,
  "total_price" numeric(15,2) NOT NULL,
  "provider_id" int8 NOT NULL,
  "provider_name" text COLLATE "pg_catalog"."default",
  "created_at" timestamp(6) DEFAULT CURRENT_TIMESTAMP,
  "updated_at" timestamp(6) DEFAULT CURRENT_TIMESTAMP,
  "remarks" text COLLATE "pg_catalog"."default",
  "deleted" int4 DEFAULT 0
)
;
COMMENT ON TABLE "public"."order_detail" IS '订单详情表';

-- ----------------------------
-- Records of order_detail
-- ----------------------------

-- ----------------------------
-- Table structure for order_evaluation
-- ----------------------------
DROP TABLE IF EXISTS "public"."order_evaluation";
CREATE TABLE "public"."order_evaluation" (
  "id" int8 NOT NULL GENERATED ALWAYS AS IDENTITY (
INCREMENT 1
MINVALUE  1
MAXVALUE 9223372036854775807
START 1
),
  "order_id" text COLLATE "pg_catalog"."default" NOT NULL,
  "evaluator_id" int8 NOT NULL,
  "evaluator_name" text COLLATE "pg_catalog"."default" NOT NULL,
  "evaluator_type" text COLLATE "pg_catalog"."default" NOT NULL,
  "content" text COLLATE "pg_catalog"."default" NOT NULL,
  "rating" int4 NOT NULL,
  "service_rating" int4,
  "quality_rating" int4,
  "delivery_rating" int4,
  "is_anonymous" bool DEFAULT false,
  "reply_content" text COLLATE "pg_catalog"."default",
  "reply_user_id" int8,
  "reply_time" timestamp(6),
  "created_at" timestamp(6) DEFAULT CURRENT_TIMESTAMP,
  "updated_at" timestamp(6) DEFAULT CURRENT_TIMESTAMP,
  "deleted" int4 DEFAULT 0
)
;
COMMENT ON TABLE "public"."order_evaluation" IS '订单评价表';

-- ----------------------------
-- Records of order_evaluation
-- ----------------------------

-- ----------------------------
-- Table structure for order_info
-- ----------------------------
DROP TABLE IF EXISTS "public"."order_info";
CREATE TABLE "public"."order_info" (
  "order_id" text COLLATE "pg_catalog"."default" NOT NULL,
  "product_id" int8 NOT NULL,
  "user_id" int8 NOT NULL,
  "unit_id" int8,
  "product_name" text COLLATE "pg_catalog"."default" NOT NULL,
  "provider_name" text COLLATE "pg_catalog"."default" NOT NULL,
  "provider_id" int8 NOT NULL,
  "apply_time" timestamp(6) DEFAULT CURRENT_TIMESTAMP,
  "order_status" text COLLATE "pg_catalog"."default" NOT NULL DEFAULT '待审批'::text,
  "total_amount" numeric(15,2) NOT NULL,
  "payment_type" text COLLATE "pg_catalog"."default",
  "payment_status" text COLLATE "pg_catalog"."default" DEFAULT '未支付'::text,
  "workflow_id" text COLLATE "pg_catalog"."default",
  "current_step" text COLLATE "pg_catalog"."default",
  "approval_flow" text COLLATE "pg_catalog"."default",
  "buyer_remarks" text COLLATE "pg_catalog"."default",
  "seller_remarks" text COLLATE "pg_catalog"."default",
  "created_at" timestamp(6) DEFAULT CURRENT_TIMESTAMP,
  "updated_at" timestamp(6) DEFAULT CURRENT_TIMESTAMP,
  "deleted" int4 DEFAULT 0
)
;
COMMENT ON TABLE "public"."order_info" IS '订单表';

-- ----------------------------
-- Records of order_info
-- ----------------------------

-- ----------------------------
-- Table structure for points
-- ----------------------------
DROP TABLE IF EXISTS "public"."points";
CREATE TABLE "public"."points" (
  "id" int8 NOT NULL DEFAULT nextval('points_id_seq'::regclass),
  "points_name" varchar COLLATE "pg_catalog"."default" NOT NULL,
  "effective_start" timestamp(0) NOT NULL,
  "modifier_id" int8 NOT NULL,
  "modifier_name" varchar COLLATE "pg_catalog"."default" NOT NULL,
  "version" numeric(2,1) NOT NULL,
  "description" text COLLATE "pg_catalog"."default",
  "status" int2,
  "created_at" timestamp(6) DEFAULT CURRENT_TIMESTAMP,
  "updated_at" timestamp(6) DEFAULT CURRENT_TIMESTAMP,
  "deleted" int2 DEFAULT 0
)
;
COMMENT ON COLUMN "public"."points"."points_name" IS '积分名称';
COMMENT ON COLUMN "public"."points"."effective_start" IS '生效开始时间';
COMMENT ON COLUMN "public"."points"."modifier_id" IS '修改人ID';
COMMENT ON COLUMN "public"."points"."modifier_name" IS '修改人姓名';
COMMENT ON COLUMN "public"."points"."version" IS '版本号';
COMMENT ON COLUMN "public"."points"."description" IS '积分描述';
COMMENT ON COLUMN "public"."points"."status" IS '状态(0启用1禁用)';
COMMENT ON COLUMN "public"."points"."created_at" IS '创建时间';
COMMENT ON COLUMN "public"."points"."updated_at" IS '更新时间';
COMMENT ON COLUMN "public"."points"."deleted" IS '逻辑删除(1删除)';
COMMENT ON TABLE "public"."points" IS '积分主表';

-- ----------------------------
-- Records of points
-- ----------------------------
INSERT INTO "public"."points" VALUES (1, '积分运行规则', '2025-08-14 00:00:00', 1, '管理员', 1.0, NULL, 0, '2025-08-14 11:01:32.086436', '2025-08-14 11:01:32.086436', 0);

-- ----------------------------
-- Table structure for points_account
-- ----------------------------
DROP TABLE IF EXISTS "public"."points_account";
CREATE TABLE "public"."points_account" (
  "id" int8 NOT NULL DEFAULT nextval('points_account_id_seq'::regclass),
  "user_id" int8 NOT NULL,
  "points_balance" int4 NOT NULL DEFAULT 0,
  "total_earned" int4 NOT NULL DEFAULT 0,
  "total_consumed" int4 NOT NULL DEFAULT 0,
  "account_type" text COLLATE "pg_catalog"."default" NOT NULL,
  "account_status" text COLLATE "pg_catalog"."default" DEFAULT '正常'::text,
  "last_transaction_time" timestamptz(6),
  "created_at" timestamptz(6) DEFAULT CURRENT_TIMESTAMP,
  "updated_at" timestamptz(6) DEFAULT CURRENT_TIMESTAMP,
  "deleted" int2 DEFAULT 0
)
;
COMMENT ON COLUMN "public"."points_account"."user_id" IS '用户ID';
COMMENT ON COLUMN "public"."points_account"."points_balance" IS '积分余额';
COMMENT ON COLUMN "public"."points_account"."total_earned" IS '累计获取积分';
COMMENT ON COLUMN "public"."points_account"."total_consumed" IS '累计消耗积分';
COMMENT ON COLUMN "public"."points_account"."account_type" IS '账户类型';
COMMENT ON COLUMN "public"."points_account"."account_status" IS '账户状态';
COMMENT ON COLUMN "public"."points_account"."last_transaction_time" IS '最后交易时间';
COMMENT ON COLUMN "public"."points_account"."created_at" IS '创建时间';
COMMENT ON COLUMN "public"."points_account"."updated_at" IS '更新时间';
COMMENT ON COLUMN "public"."points_account"."deleted" IS '逻辑删除';
COMMENT ON TABLE "public"."points_account" IS '积分账户表';

-- ----------------------------
-- Records of points_account
-- ----------------------------

-- ----------------------------
-- Table structure for points_flow
-- ----------------------------
DROP TABLE IF EXISTS "public"."points_flow";
CREATE TABLE "public"."points_flow" (
  "id" int8 NOT NULL DEFAULT nextval('points_flow_id_seq'::regclass),
  "user_id" int8,
  "unit_id" int8,
  "data_category" varchar(100) COLLATE "pg_catalog"."default" NOT NULL,
  "data_type" varchar(50) COLLATE "pg_catalog"."default" NOT NULL,
  "name" text COLLATE "pg_catalog"."default" NOT NULL,
  "points" int4 NOT NULL,
  "flow_time" timestamp(6) NOT NULL,
  "create_time" timestamp(6) DEFAULT CURRENT_TIMESTAMP,
  "update_time" timestamp(6) DEFAULT CURRENT_TIMESTAMP,
  "deleted" int4 DEFAULT 0
)
;
COMMENT ON COLUMN "public"."points_flow"."user_id" IS '用户ID';
COMMENT ON COLUMN "public"."points_flow"."unit_id" IS '单位ID';
COMMENT ON COLUMN "public"."points_flow"."data_category" IS '数据类目';
COMMENT ON COLUMN "public"."points_flow"."data_type" IS '数据类型';
COMMENT ON COLUMN "public"."points_flow"."name" IS '名称/描述';
COMMENT ON COLUMN "public"."points_flow"."points" IS '积分值';
COMMENT ON COLUMN "public"."points_flow"."flow_time" IS '流水时间';
COMMENT ON COLUMN "public"."points_flow"."create_time" IS '创建时间';
COMMENT ON COLUMN "public"."points_flow"."update_time" IS '更新时间';
COMMENT ON COLUMN "public"."points_flow"."deleted" IS '逻辑删除：1-已删除，0-未删除';
COMMENT ON TABLE "public"."points_flow" IS '积分流水表';

-- ----------------------------
-- Records of points_flow
-- ----------------------------
INSERT INTO "public"."points_flow" VALUES (1, 1, 1, 'user_participation', 'earned', '用户每日首次登录', 1, '2025-05-18 16:00:00', '2025-08-07 11:48:21.579058', '2025-08-07 11:48:21.579058', 0);
INSERT INTO "public"."points_flow" VALUES (2, 1, 1, 'user_participation', 'earned', '交流社区发布评论"基建行业如何利用AI技术提高效率"', 1, '2025-05-17 15:00:00', '2025-08-07 11:48:21.579058', '2025-08-07 11:48:21.579058', 0);
INSERT INTO "public"."points_flow" VALUES (3, 1, 1, 'user_participation', 'earned', '用户每日首次登录', 1, '2025-05-16 14:00:00', '2025-08-07 11:48:21.579058', '2025-08-07 11:48:21.579058', 0);
INSERT INTO "public"."points_flow" VALUES (4, 1, 1, 'user_participation', 'consumed', '交流社区删除提问"基建项目如何应用数字孪生技术?"', -1, '2025-05-15 13:00:00', '2025-08-07 11:48:21.579058', '2025-08-07 11:48:21.579058', 0);
INSERT INTO "public"."points_flow" VALUES (5, 1, 1, 'points_conversion', 'earned', '单位积分转入', 1000, '2025-05-06 12:00:00', '2025-08-07 11:48:21.579058', '2025-08-07 11:48:21.579058', 0);
INSERT INTO "public"."points_flow" VALUES (6, 1, 1, 'user_participation', 'earned', '用户每日首次登录', 1, '2025-05-05 11:00:00', '2025-08-07 11:48:21.579058', '2025-08-07 11:48:21.579058', 0);
INSERT INTO "public"."points_flow" VALUES (7, 1, 1, 'other', 'earned', '积分奖励', 100, '2025-05-04 10:00:00', '2025-08-07 11:48:21.579058', '2025-08-07 11:48:21.579058', 0);
INSERT INTO "public"."points_flow" VALUES (8, 1, 1, 'user_participation', 'earned', '交流社区发布提问"基建项目如何应用数字孪生技术?"', 1, '2025-05-02 09:10:00', '2025-08-07 11:48:21.579058', '2025-08-07 11:48:21.579058', 0);
INSERT INTO "public"."points_flow" VALUES (9, 1, 1, 'user_participation', 'earned', '用户每日首次登录', 1, '2025-05-02 09:02:00', '2025-08-07 11:48:21.579058', '2025-08-07 11:48:21.579058', 0);
INSERT INTO "public"."points_flow" VALUES (10, 1, 1, 'other', 'earned', '初始化积分', 100, '2025-05-01 09:01:00', '2025-08-07 11:48:21.579058', '2025-08-07 11:48:21.579058', 0);
INSERT INTO "public"."points_flow" VALUES (17, 1, 1, 'other', 'earned', '积分奖励', 100, '2025-08-08 18:34:36', '2025-08-08 18:34:39', '2025-08-08 18:34:41', 0);

-- ----------------------------
-- Table structure for points_rule
-- ----------------------------
DROP TABLE IF EXISTS "public"."points_rule";
CREATE TABLE "public"."points_rule" (
  "id" int8 NOT NULL DEFAULT nextval('points_rule_id_seq'::regclass),
  "points_id" int8 NOT NULL,
  "rule_type" int2 NOT NULL,
  "category" varchar COLLATE "pg_catalog"."default" NOT NULL,
  "rule_name" varchar COLLATE "pg_catalog"."default" NOT NULL,
  "rule_description" varchar COLLATE "pg_catalog"."default",
  "is_enabled" int2 DEFAULT 0,
  "created_at" timestamp(6) DEFAULT CURRENT_TIMESTAMP,
  "updated_at" timestamp(6) DEFAULT CURRENT_TIMESTAMP,
  "deleted" int2 DEFAULT 0,
  "points_winner" int2,
  "is_limit" int2,
  "rule_order" int2
)
;
COMMENT ON COLUMN "public"."points_rule"."points_id" IS '关联积分ID';
COMMENT ON COLUMN "public"."points_rule"."rule_type" IS '积分规则类型(0获取1消耗)';
COMMENT ON COLUMN "public"."points_rule"."category" IS '积分类别';
COMMENT ON COLUMN "public"."points_rule"."rule_name" IS '规则名称';
COMMENT ON COLUMN "public"."points_rule"."rule_description" IS '规则描述';
COMMENT ON COLUMN "public"."points_rule"."is_enabled" IS '规则状态(0启动1禁用)';
COMMENT ON COLUMN "public"."points_rule"."created_at" IS '创建时间';
COMMENT ON COLUMN "public"."points_rule"."updated_at" IS '更新时间';
COMMENT ON COLUMN "public"."points_rule"."deleted" IS '逻辑删除';
COMMENT ON COLUMN "public"."points_rule"."points_winner" IS '积分获得者（0贡献者1用户）';
COMMENT ON COLUMN "public"."points_rule"."is_limit" IS '积分是否有上限(0没有1有)';
COMMENT ON COLUMN "public"."points_rule"."rule_order" IS '排序规则';
COMMENT ON TABLE "public"."points_rule" IS '积分规则表';

-- ----------------------------
-- Records of points_rule
-- ----------------------------
INSERT INTO "public"."points_rule" VALUES (2, 1, 0, '资源贡献', '新增数字化标杆', '每成功上架1个标杆，贡献者 获', 0, '2025-08-14 14:24:00.753678', '2025-08-14 14:24:00.753678', 0, 0, 0, NULL);
INSERT INTO "public"."points_rule" VALUES (4, 1, 0, '资源贡献', '新增数字化产品', '每成功上架1个产品，贡献者 获', 0, '2025-08-14 14:44:37.128422', '2025-08-14 14:44:37.128422', 0, 0, 0, NULL);
INSERT INTO "public"."points_rule" VALUES (34, 1, 0, '交流社区互动', '回复帖子', '每回复1次帖子，贡献者 获', 0, '2025-08-14 15:08:19.324645', '2025-08-14 15:08:19.324645', 0, 0, 1, NULL);
INSERT INTO "public"."points_rule" VALUES (35, 1, 0, '交流社区互动', '帖子点赞', '发布的帖子或做出的回答每被点赞一次，贡献者 获', 0, '2025-08-14 15:08:19.325826', '2025-08-14 15:08:19.325826', 0, 0, 0, NULL);
INSERT INTO "public"."points_rule" VALUES (3, 1, 0, '资源贡献', '新增数字化知识', '每成功上架1个知识，贡献者 获', 0, '2025-08-14 14:44:37.124901', '2025-08-14 14:44:37.124901', 0, 0, 0, NULL);
INSERT INTO "public"."points_rule" VALUES (36, 1, 0, '交流社区互动', '帖子收藏', '发布的帖子每被收藏一次，贡献者 获', 0, '2025-08-14 15:08:19.326955', '2025-08-14 15:08:19.326955', 0, 0, 0, NULL);
INSERT INTO "public"."points_rule" VALUES (52, 1, 1, '交流社区互动', '取消收藏', '发布的帖子被收藏，后又取消收藏，贡献者 扣除', 0, '2025-08-14 15:15:13.333528', '2025-08-14 15:15:13.333528', 0, 0, 0, NULL);
INSERT INTO "public"."points_rule" VALUES (49, 1, 1, '交流社区互动', '删除帖子', '自己发布的帖子被删除，贡献者 扣除', 0, '2025-08-14 15:15:13.330326', '2025-08-14 15:15:13.330326', 0, 0, 0, NULL);
INSERT INTO "public"."points_rule" VALUES (50, 1, 1, '交流社区互动', '删除回复', '自己的回复被删除，贡献者 扣除', 0, '2025-08-14 15:15:13.331467', '2025-08-14 15:15:13.331467', 0, 0, 0, NULL);
INSERT INTO "public"."points_rule" VALUES (11, 1, 0, '资源传播', '评价数字化资源', '每被评价1次，贡献者 获', 0, '2025-08-14 15:07:54.732016', '2025-08-14 15:07:54.732016', 0, 0, 1, NULL);
INSERT INTO "public"."points_rule" VALUES (12, 1, 0, '资源传播', '评价数字化资源', '评价者 获', 0, '2025-08-14 15:07:54.733588', '2025-08-14 15:07:54.733588', 0, 1, 1, NULL);
INSERT INTO "public"."points_rule" VALUES (51, 1, 1, '交流社区互动', '取消点赞', '发布的帖子或做出的回答被点赞后又取消点赞，贡献者 扣除', 0, '2025-08-14 15:15:13.332602', '2025-08-14 15:15:13.332602', 0, 0, 0, NULL);
INSERT INTO "public"."points_rule" VALUES (15, 1, 0, '资源传播', '订阅数字化资源', '每被订阅1次，贡献者 获', 0, '2025-08-14 15:07:54.736641', '2025-08-14 15:07:54.736641', 0, 0, 0, NULL);
INSERT INTO "public"."points_rule" VALUES (16, 1, 0, '资源传播', '订阅数字化资源', '订阅者 获', 0, '2025-08-14 15:07:54.737529', '2025-08-14 15:07:54.737529', 0, 1, 0, NULL);
INSERT INTO "public"."points_rule" VALUES (17, 1, 0, '资源交易', '数字化产品接入', '每成功接入1次，贡献者 获', 0, '2025-08-14 15:07:54.738396', '2025-08-14 15:07:54.738396', 0, 0, 0, NULL);
INSERT INTO "public"."points_rule" VALUES (18, 1, 0, '资源交易', '数字化产品交易', '每成功交易1次，贡献者 获', 0, '2025-08-14 15:07:54.739469', '2025-08-14 15:07:54.739469', 0, 0, 0, NULL);
INSERT INTO "public"."points_rule" VALUES (20, 1, 0, '资源传播', '浏览数字化资源', '浏览者', 0, '2025-08-14 15:08:19.309681', '2025-08-14 15:08:19.309681', 0, 1, 1, NULL);
INSERT INTO "public"."points_rule" VALUES (21, 1, 0, '资源传播', '收藏数字化资源', '每被收藏1次，贡献者 获', 0, '2025-08-14 15:08:19.311096', '2025-08-14 15:08:19.311096', 0, 0, 1, NULL);
INSERT INTO "public"."points_rule" VALUES (33, 1, 0, '交流社区互动', '发布帖子', '每成功发布1次，贡献者 获', 0, '2025-08-14 15:08:19.323293', '2025-08-14 15:08:19.323293', 0, 0, 1, NULL);
INSERT INTO "public"."points_rule" VALUES (42, 1, 1, '资源传播', '取消订阅', '操作者 扣除', 0, '2025-08-14 15:12:29.49397', '2025-08-14 15:12:29.49397', 0, 1, 0, NULL);
INSERT INTO "public"."points_rule" VALUES (43, 1, 1, '资源传播', '取消收藏', '数字化资源被取消收藏，贡献者 扣除', 0, '2025-08-14 15:15:13.324114', '2025-08-14 15:15:13.324114', 0, 0, 0, NULL);
INSERT INTO "public"."points_rule" VALUES (44, 1, 1, '资源传播', '取消收藏', '操作者 扣除', 0, '2025-08-14 15:15:13.325517', '2025-08-14 15:15:13.325517', 0, 1, 0, NULL);
INSERT INTO "public"."points_rule" VALUES (22, 1, 0, '资源传播', '收藏数字化资源', '收藏者 获', 0, '2025-08-14 15:08:19.312482', '2025-08-14 15:08:19.312482', 0, 1, 1, NULL);
INSERT INTO "public"."points_rule" VALUES (23, 1, 0, '资源传播', '点赞数字化资源', '每被点赞1次，贡献者 获', 0, '2025-08-14 15:08:19.313654', '2025-08-14 15:08:19.313654', 0, 0, 1, NULL);
INSERT INTO "public"."points_rule" VALUES (24, 1, 0, '资源传播', '点赞数字化资源', '点赞者 获', 0, '2025-08-14 15:08:19.314647', '2025-08-14 15:08:19.314647', 0, 1, 1, NULL);
INSERT INTO "public"."points_rule" VALUES (28, 1, 0, '资源传播', '试用数字化资源', '试用者 获', 0, '2025-08-14 15:08:19.318477', '2025-08-14 15:08:19.318477', 0, 1, 0, NULL);
INSERT INTO "public"."points_rule" VALUES (39, 1, 1, '资源传播', '取消点赞', '数字化资源被取消点赞，贡献者 扣除', 0, '2025-08-14 15:12:29.490075', '2025-08-14 15:12:29.490075', 0, 0, 0, NULL);
INSERT INTO "public"."points_rule" VALUES (40, 1, 1, '资源传播', '取消点赞', '操作者 扣除', 0, '2025-08-14 15:12:29.49113', '2025-08-14 15:12:29.49113', 0, 1, 0, NULL);
INSERT INTO "public"."points_rule" VALUES (41, 1, 1, '资源传播', '取消订阅', '数字化产品被取消订阅，贡献者 扣除', 0, '2025-08-14 15:12:29.492296', '2025-08-14 15:12:29.492296', 0, 0, 0, NULL);
INSERT INTO "public"."points_rule" VALUES (13, 1, 0, '资源传播', '试用数字化资源', '每被试用1次，贡献者 获', 0, '2025-08-14 15:07:54.734444', '2025-08-14 15:07:54.734444', 0, 0, 0, NULL);
INSERT INTO "public"."points_rule" VALUES (19, 1, 0, '资源传播', '浏览数字化资源', '每被浏览1次，贡献者', 0, '2025-08-14 15:08:19.308203', '2025-08-14 15:08:19.308203', 0, 0, 1, NULL);

-- ----------------------------
-- Table structure for points_rule_detail
-- ----------------------------
DROP TABLE IF EXISTS "public"."points_rule_detail";
CREATE TABLE "public"."points_rule_detail" (
  "id" int8 NOT NULL DEFAULT nextval('points_rule_detail_id_seq'::regclass),
  "rule_id" int8 NOT NULL,
  "points_id" int8 NOT NULL,
  "points_value" int4 NOT NULL,
  "daily_limit" int4,
  "monthly_limit" int4,
  "yearly_limit" int4,
  "min_value" int4 DEFAULT 0,
  "max_value" int4,
  "conversion_rate" numeric(10,4) DEFAULT 1.0,
  "created_at" timestamptz(6) DEFAULT CURRENT_TIMESTAMP,
  "updated_at" timestamptz(6) DEFAULT CURRENT_TIMESTAMP,
  "deleted" int2 DEFAULT 0
)
;
COMMENT ON COLUMN "public"."points_rule_detail"."rule_id" IS '关联积分规则ID';
COMMENT ON COLUMN "public"."points_rule_detail"."points_id" IS '关联积分ID';
COMMENT ON COLUMN "public"."points_rule_detail"."points_value" IS '积分值';
COMMENT ON COLUMN "public"."points_rule_detail"."daily_limit" IS '每日积分上限值';
COMMENT ON COLUMN "public"."points_rule_detail"."monthly_limit" IS '每月积分上限值';
COMMENT ON COLUMN "public"."points_rule_detail"."yearly_limit" IS '每年积分上限值';
COMMENT ON COLUMN "public"."points_rule_detail"."min_value" IS '最小值';
COMMENT ON COLUMN "public"."points_rule_detail"."max_value" IS '最大值';
COMMENT ON COLUMN "public"."points_rule_detail"."conversion_rate" IS '转换比率';
COMMENT ON COLUMN "public"."points_rule_detail"."created_at" IS '创建时间';
COMMENT ON COLUMN "public"."points_rule_detail"."updated_at" IS '更新时间';
COMMENT ON COLUMN "public"."points_rule_detail"."deleted" IS '逻辑删除';
COMMENT ON TABLE "public"."points_rule_detail" IS '积分规则详情表';

-- ----------------------------
-- Records of points_rule_detail
-- ----------------------------

-- ----------------------------
-- Table structure for points_transaction
-- ----------------------------
DROP TABLE IF EXISTS "public"."points_transaction";
CREATE TABLE "public"."points_transaction" (
  "id" int8 NOT NULL DEFAULT nextval('points_transaction_id_seq'::regclass),
  "data_category" text COLLATE "pg_catalog"."default" NOT NULL,
  "transaction_name" text COLLATE "pg_catalog"."default" NOT NULL,
  "transaction_time" timestamptz(6) DEFAULT CURRENT_TIMESTAMP,
  "points_change" int4 NOT NULL,
  "rule_type" text COLLATE "pg_catalog"."default" NOT NULL,
  "user_id" int8,
  "unit_id" int8,
  "user_type" text COLLATE "pg_catalog"."default" NOT NULL,
  "rule_id" int8,
  "detail_id" int8,
  "created_at" timestamptz(6) DEFAULT CURRENT_TIMESTAMP,
  "deleted" int2 DEFAULT 0
)
;
COMMENT ON COLUMN "public"."points_transaction"."data_category" IS '数据类目';
COMMENT ON COLUMN "public"."points_transaction"."transaction_name" IS '名称';
COMMENT ON COLUMN "public"."points_transaction"."transaction_time" IS '时间';
COMMENT ON COLUMN "public"."points_transaction"."points_change" IS '积分变动值';
COMMENT ON COLUMN "public"."points_transaction"."rule_type" IS '积分规则类型';
COMMENT ON COLUMN "public"."points_transaction"."user_id" IS '用户ID';
COMMENT ON COLUMN "public"."points_transaction"."unit_id" IS '企业ID';
COMMENT ON COLUMN "public"."points_transaction"."user_type" IS '用户类型';
COMMENT ON COLUMN "public"."points_transaction"."rule_id" IS '关联规则ID';
COMMENT ON COLUMN "public"."points_transaction"."detail_id" IS '关联规则详情ID';
COMMENT ON COLUMN "public"."points_transaction"."created_at" IS '创建时间';
COMMENT ON COLUMN "public"."points_transaction"."deleted" IS '逻辑删除';
COMMENT ON TABLE "public"."points_transaction" IS '积分流水表';

-- ----------------------------
-- Records of points_transaction
-- ----------------------------

-- ----------------------------
-- Table structure for product
-- ----------------------------
DROP TABLE IF EXISTS "public"."product";
CREATE TABLE "public"."product" (
  "id" int8 NOT NULL GENERATED ALWAYS AS IDENTITY (
INCREMENT 1
MINVALUE  1
MAXVALUE 9223372036854775807
START 1
),
  "product_name" text COLLATE "pg_catalog"."default" NOT NULL,
  "product_code" text COLLATE "pg_catalog"."default" NOT NULL,
  "product_type" text COLLATE "pg_catalog"."default",
  "category" text COLLATE "pg_catalog"."default",
  "description" text COLLATE "pg_catalog"."default",
  "provider_id" int8 NOT NULL,
  "provider_name" text COLLATE "pg_catalog"."default" NOT NULL,
  "provider_type" text COLLATE "pg_catalog"."default",
  "status" text COLLATE "pg_catalog"."default" DEFAULT '上架'::text,
  "audit_status" text COLLATE "pg_catalog"."default" DEFAULT '待审核'::text,
  "tags" text COLLATE "pg_catalog"."default",
  "cover_image" text COLLATE "pg_catalog"."default",
  "demo_url" text COLLATE "pg_catalog"."default",
  "doc_url" text COLLATE "pg_catalog"."default",
  "created_at" timestamp(6) DEFAULT CURRENT_TIMESTAMP,
  "updated_at" timestamp(6) DEFAULT CURRENT_TIMESTAMP,
  "created_by" int8,
  "updated_by" int8,
  "deleted" int4 DEFAULT 0
)
;
COMMENT ON TABLE "public"."product" IS '产品表';

-- ----------------------------
-- Records of product
-- ----------------------------
INSERT INTO "public"."product" OVERRIDING SYSTEM VALUE VALUES (1, '测试产品1', 'TEST_PRODUCT_001', '软件产品', '企业管理', '这是一个测试产品', 3, '测试提供者', NULL, '上架', '审核通过', NULL, NULL, NULL, NULL, '2025-08-13 14:50:16.574223', '2025-08-13 14:50:16.574223', NULL, NULL, 0);
INSERT INTO "public"."product" OVERRIDING SYSTEM VALUE VALUES (2, '测试产品2', 'TEST_PRODUCT_002', '服务产品', '技术服务', '这是另一个测试产品', 3, '测试提供者', NULL, '上架', '审核通过', NULL, NULL, NULL, NULL, '2025-08-13 14:50:16.574223', '2025-08-13 14:50:16.574223', NULL, NULL, 0);

-- ----------------------------
-- Table structure for product_pricing
-- ----------------------------
DROP TABLE IF EXISTS "public"."product_pricing";
CREATE TABLE "public"."product_pricing" (
  "id" int8 NOT NULL GENERATED ALWAYS AS IDENTITY (
INCREMENT 1
MINVALUE  1
MAXVALUE 9223372036854775807
START 1
),
  "suite_name" text COLLATE "pg_catalog"."default" NOT NULL,
  "sales_form" text COLLATE "pg_catalog"."default" NOT NULL,
  "customer_type" text COLLATE "pg_catalog"."default" NOT NULL,
  "account_limit" text COLLATE "pg_catalog"."default" DEFAULT '不限'::text,
  "concurrent_nodes" text COLLATE "pg_catalog"."default" DEFAULT '不限'::text,
  "price_type" text COLLATE "pg_catalog"."default" NOT NULL,
  "price_unit" text COLLATE "pg_catalog"."default" NOT NULL,
  "price" numeric(15,2) NOT NULL,
  "is_active" bool DEFAULT true,
  "product_id" int8 NOT NULL,
  "product_name" text COLLATE "pg_catalog"."default",
  "provider_id" int8,
  "provider_name" text COLLATE "pg_catalog"."default",
  "description" text COLLATE "pg_catalog"."default",
  "created_at" timestamp(6) DEFAULT CURRENT_TIMESTAMP,
  "updated_at" timestamp(6) DEFAULT CURRENT_TIMESTAMP,
  "created_by" int8,
  "updated_by" int8,
  "deleted" int4 DEFAULT 0
)
;
COMMENT ON COLUMN "public"."product_pricing"."suite_name" IS '产品套件名称';
COMMENT ON COLUMN "public"."product_pricing"."sales_form" IS '销售形式';
COMMENT ON TABLE "public"."product_pricing" IS '产品定价表';

-- ----------------------------
-- Records of product_pricing
-- ----------------------------
INSERT INTO "public"."product_pricing" OVERRIDING SYSTEM VALUE VALUES (1, '基础版', '买断', '企业', '不限', '不限', '积分', '套', 1000.00, 't', 1, '测试产品1', 3, '测试提供者', NULL, '2025-08-13 14:50:16.574223', '2025-08-13 14:50:16.574223', NULL, NULL, 0);
INSERT INTO "public"."product_pricing" OVERRIDING SYSTEM VALUE VALUES (2, '专业版', '租赁', '企业', '不限', '不限', '积分', '套/年', 500.00, 't', 1, '测试产品1', 3, '测试提供者', NULL, '2025-08-13 14:50:16.574223', '2025-08-13 14:50:16.574223', NULL, NULL, 0);
INSERT INTO "public"."product_pricing" OVERRIDING SYSTEM VALUE VALUES (3, '企业版', '买断', '企业', '不限', '不限', '货币', '套', 10000.00, 't', 2, '测试产品2', 3, '测试提供者', NULL, '2025-08-13 14:50:16.574223', '2025-08-13 14:50:16.574223', NULL, NULL, 0);

-- ----------------------------
-- Table structure for unit
-- ----------------------------
DROP TABLE IF EXISTS "public"."unit";
CREATE TABLE "public"."unit" (
  "id" int8 NOT NULL GENERATED ALWAYS AS IDENTITY (
INCREMENT 1
MINVALUE  1
MAXVALUE 9223372036854775807
START 1
),
  "unit_name" text COLLATE "pg_catalog"."default" NOT NULL,
  "unit_code" text COLLATE "pg_catalog"."default",
  "unit_type" text COLLATE "pg_catalog"."default",
  "industry" text COLLATE "pg_catalog"."default",
  "address" text COLLATE "pg_catalog"."default",
  "contact_person" text COLLATE "pg_catalog"."default",
  "contact_phone" text COLLATE "pg_catalog"."default",
  "contact_email" text COLLATE "pg_catalog"."default",
  "business_license" text COLLATE "pg_catalog"."default",
  "legal_person" text COLLATE "pg_catalog"."default",
  "registered_capital" numeric(15,2),
  "establishment_date" date,
  "status" text COLLATE "pg_catalog"."default" DEFAULT '正常'::text,
  "created_at" timestamp(6) DEFAULT CURRENT_TIMESTAMP,
  "updated_at" timestamp(6) DEFAULT CURRENT_TIMESTAMP,
  "deleted" int4 DEFAULT 0
)
;
COMMENT ON TABLE "public"."unit" IS '单位表';

-- ----------------------------
-- Records of unit
-- ----------------------------
INSERT INTO "public"."unit" OVERRIDING SYSTEM VALUE VALUES (1, '测试企业', 'TEST_ENTERPRISE', '企业', '信息技术', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, '正常', '2025-08-13 14:50:16.574223', '2025-08-13 14:50:16.574223', 0);
INSERT INTO "public"."unit" OVERRIDING SYSTEM VALUE VALUES (2, '测试单位', 'TEST_UNIT', '事业单位', '教育', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, '正常', '2025-08-13 14:50:16.574223', '2025-08-13 14:50:16.574223', 0);

-- ----------------------------
-- Table structure for user_points
-- ----------------------------
DROP TABLE IF EXISTS "public"."user_points";
CREATE TABLE "public"."user_points" (
  "id" int8 NOT NULL DEFAULT nextval('user_points_id_seq'::regclass),
  "user_id" int8 NOT NULL,
  "unit_id" int8,
  "balance" int4 NOT NULL DEFAULT 0,
  "total_earned" int4 NOT NULL DEFAULT 0,
  "total_consumed" int4 NOT NULL DEFAULT 0,
  "total_converted" int4 NOT NULL DEFAULT 0,
  "create_time" timestamp(6) DEFAULT CURRENT_TIMESTAMP,
  "update_time" timestamp(6) DEFAULT CURRENT_TIMESTAMP,
  "deleted" int4 DEFAULT 0
)
;
COMMENT ON COLUMN "public"."user_points"."user_id" IS '用户ID';
COMMENT ON COLUMN "public"."user_points"."unit_id" IS '单位ID';
COMMENT ON COLUMN "public"."user_points"."balance" IS '积分余额';
COMMENT ON COLUMN "public"."user_points"."total_earned" IS '累计获取积分';
COMMENT ON COLUMN "public"."user_points"."total_consumed" IS '累计消耗积分';
COMMENT ON COLUMN "public"."user_points"."total_converted" IS '累计转换积分';
COMMENT ON COLUMN "public"."user_points"."create_time" IS '创建时间';
COMMENT ON COLUMN "public"."user_points"."update_time" IS '更新时间';
COMMENT ON COLUMN "public"."user_points"."deleted" IS '逻辑删除：1-已删除，0-未删除';
COMMENT ON TABLE "public"."user_points" IS '用户积分表';

-- ----------------------------
-- Records of user_points
-- ----------------------------
INSERT INTO "public"."user_points" VALUES (1, 1, 1, 20000, 10000, 200, 0, '2025-08-07 11:48:21.574933', '2025-08-07 11:48:21.574933', 0);

-- ----------------------------
-- Table structure for users
-- ----------------------------
DROP TABLE IF EXISTS "public"."users";
CREATE TABLE "public"."users" (
  "id" int8 NOT NULL GENERATED ALWAYS AS IDENTITY (
INCREMENT 1
MINVALUE  1
MAXVALUE 9223372036854775807
START 1
),
  "username" text COLLATE "pg_catalog"."default" NOT NULL,
  "real_name" text COLLATE "pg_catalog"."default",
  "email" text COLLATE "pg_catalog"."default",
  "phone" text COLLATE "pg_catalog"."default",
  "avatar" text COLLATE "pg_catalog"."default",
  "user_type" text COLLATE "pg_catalog"."default" DEFAULT '个人用户'::text,
  "unit_id" int8,
  "unit_name" text COLLATE "pg_catalog"."default",
  "status" text COLLATE "pg_catalog"."default" DEFAULT '正常'::text,
  "last_login_time" timestamp(6),
  "created_at" timestamp(6) DEFAULT CURRENT_TIMESTAMP,
  "updated_at" timestamp(6) DEFAULT CURRENT_TIMESTAMP,
  "deleted" int4 DEFAULT 0
)
;
COMMENT ON TABLE "public"."users" IS '用户表';

-- ----------------------------
-- Records of users
-- ----------------------------
INSERT INTO "public"."users" OVERRIDING SYSTEM VALUE VALUES (1, 'admin', '系统管理员', NULL, NULL, NULL, '个人用户', NULL, NULL, '正常', NULL, '2025-08-13 14:50:16.574223', '2025-08-13 14:50:16.574223', 0);
INSERT INTO "public"."users" OVERRIDING SYSTEM VALUE VALUES (2, 'test_user', '测试用户', NULL, NULL, NULL, '个人用户', 1, NULL, '正常', NULL, '2025-08-13 14:50:16.574223', '2025-08-13 14:50:16.574223', 0);
INSERT INTO "public"."users" OVERRIDING SYSTEM VALUE VALUES (3, 'test_provider', '测试提供者', NULL, NULL, NULL, '单位用户', 1, NULL, '正常', NULL, '2025-08-13 14:50:16.574223', '2025-08-13 14:50:16.574223', 0);

-- ----------------------------
-- Alter sequences owned by
-- ----------------------------
ALTER SEQUENCE "public"."cart_id_seq"
OWNED BY "public"."cart"."id";
SELECT setval('"public"."cart_id_seq"', 2, false);

-- ----------------------------
-- Alter sequences owned by
-- ----------------------------
ALTER SEQUENCE "public"."order_approval_id_seq"
OWNED BY "public"."order_approval"."id";
SELECT setval('"public"."order_approval_id_seq"', 2, false);

-- ----------------------------
-- Alter sequences owned by
-- ----------------------------
ALTER SEQUENCE "public"."order_attachment_id_seq"
OWNED BY "public"."order_attachment"."id";
SELECT setval('"public"."order_attachment_id_seq"', 2, false);

-- ----------------------------
-- Alter sequences owned by
-- ----------------------------
ALTER SEQUENCE "public"."order_detail_id_seq"
OWNED BY "public"."order_detail"."id";
SELECT setval('"public"."order_detail_id_seq"', 2, false);

-- ----------------------------
-- Alter sequences owned by
-- ----------------------------
ALTER SEQUENCE "public"."order_evaluation_id_seq"
OWNED BY "public"."order_evaluation"."id";
SELECT setval('"public"."order_evaluation_id_seq"', 2, false);

-- ----------------------------
-- Alter sequences owned by
-- ----------------------------
ALTER SEQUENCE "public"."points_account_id_seq"
OWNED BY "public"."points_account"."id";
SELECT setval('"public"."points_account_id_seq"', 2, false);

-- ----------------------------
-- Alter sequences owned by
-- ----------------------------
ALTER SEQUENCE "public"."points_flow_id_seq"
OWNED BY "public"."points_flow"."id";
SELECT setval('"public"."points_flow_id_seq"', 18, true);

-- ----------------------------
-- Alter sequences owned by
-- ----------------------------
ALTER SEQUENCE "public"."points_id_seq"
OWNED BY "public"."points"."id";
SELECT setval('"public"."points_id_seq"', 2, true);

-- ----------------------------
-- Alter sequences owned by
-- ----------------------------
ALTER SEQUENCE "public"."points_rule_detail_id_seq"
OWNED BY "public"."points_rule_detail"."id";
SELECT setval('"public"."points_rule_detail_id_seq"', 2, false);

-- ----------------------------
-- Alter sequences owned by
-- ----------------------------
ALTER SEQUENCE "public"."points_rule_id_seq"
OWNED BY "public"."points_rule"."id";
SELECT setval('"public"."points_rule_id_seq"', 53, true);

-- ----------------------------
-- Alter sequences owned by
-- ----------------------------
ALTER SEQUENCE "public"."points_transaction_id_seq"
OWNED BY "public"."points_transaction"."id";
SELECT setval('"public"."points_transaction_id_seq"', 2, false);

-- ----------------------------
-- Alter sequences owned by
-- ----------------------------
ALTER SEQUENCE "public"."product_id_seq"
OWNED BY "public"."product"."id";
SELECT setval('"public"."product_id_seq"', 3, true);

-- ----------------------------
-- Alter sequences owned by
-- ----------------------------
ALTER SEQUENCE "public"."product_pricing_id_seq"
OWNED BY "public"."product_pricing"."id";
SELECT setval('"public"."product_pricing_id_seq"', 4, true);

-- ----------------------------
-- Alter sequences owned by
-- ----------------------------
ALTER SEQUENCE "public"."unit_id_seq"
OWNED BY "public"."unit"."id";
SELECT setval('"public"."unit_id_seq"', 3, true);

-- ----------------------------
-- Alter sequences owned by
-- ----------------------------
ALTER SEQUENCE "public"."user_points_id_seq"
OWNED BY "public"."user_points"."id";
SELECT setval('"public"."user_points_id_seq"', 2, true);

-- ----------------------------
-- Alter sequences owned by
-- ----------------------------
ALTER SEQUENCE "public"."users_id_seq"
OWNED BY "public"."users"."id";
SELECT setval('"public"."users_id_seq"', 4, true);

-- ----------------------------
-- Indexes structure for table cart
-- ----------------------------
CREATE INDEX "idx_cart_add_time" ON "public"."cart" USING btree (
  "add_time" "pg_catalog"."timestamp_ops" ASC NULLS LAST,
  "deleted" "pg_catalog"."int4_ops" ASC NULLS LAST
);
CREATE INDEX "idx_cart_pricing" ON "public"."cart" USING btree (
  "pricing_id" "pg_catalog"."int8_ops" ASC NULLS LAST,
  "deleted" "pg_catalog"."int4_ops" ASC NULLS LAST
);
CREATE INDEX "idx_cart_product" ON "public"."cart" USING btree (
  "product_id" "pg_catalog"."int8_ops" ASC NULLS LAST,
  "deleted" "pg_catalog"."int4_ops" ASC NULLS LAST
);
CREATE INDEX "idx_cart_provider" ON "public"."cart" USING btree (
  "provider_id" "pg_catalog"."int8_ops" ASC NULLS LAST,
  "deleted" "pg_catalog"."int4_ops" ASC NULLS LAST
);
CREATE INDEX "idx_cart_user_unit" ON "public"."cart" USING btree (
  "user_id" "pg_catalog"."int8_ops" ASC NULLS LAST,
  "unit_id" "pg_catalog"."int8_ops" ASC NULLS LAST,
  "deleted" "pg_catalog"."int4_ops" ASC NULLS LAST
);

-- ----------------------------
-- Uniques structure for table cart
-- ----------------------------
ALTER TABLE "public"."cart" ADD CONSTRAINT "cart_user_id_unit_id_pricing_id_deleted_key" UNIQUE ("user_id", "unit_id", "pricing_id", "deleted");

-- ----------------------------
-- Checks structure for table cart
-- ----------------------------
ALTER TABLE "public"."cart" ADD CONSTRAINT "cart_deleted_check" CHECK ((deleted = ANY (ARRAY[0, 1])));

-- ----------------------------
-- Primary Key structure for table cart
-- ----------------------------
ALTER TABLE "public"."cart" ADD CONSTRAINT "cart_pkey" PRIMARY KEY ("id");

-- ----------------------------
-- Indexes structure for table order_approval
-- ----------------------------
CREATE INDEX "idx_order_approval_approver_id" ON "public"."order_approval" USING btree (
  "approver_id" "pg_catalog"."int8_ops" ASC NULLS LAST
);
CREATE INDEX "idx_order_approval_order_id" ON "public"."order_approval" USING btree (
  "order_id" COLLATE "pg_catalog"."default" "pg_catalog"."text_ops" ASC NULLS LAST
);

-- ----------------------------
-- Checks structure for table order_approval
-- ----------------------------
ALTER TABLE "public"."order_approval" ADD CONSTRAINT "order_approval_approval_result_check" CHECK ((approval_result = ANY (ARRAY['通过'::text, '驳回'::text, '待处理'::text])));
ALTER TABLE "public"."order_approval" ADD CONSTRAINT "order_approval_deleted_check" CHECK ((deleted = ANY (ARRAY[0, 1])));
ALTER TABLE "public"."order_approval" ADD CONSTRAINT "order_approval_approval_type_check" CHECK ((approval_type = ANY (ARRAY['审批'::text, '授权'::text])));

-- ----------------------------
-- Primary Key structure for table order_approval
-- ----------------------------
ALTER TABLE "public"."order_approval" ADD CONSTRAINT "order_approval_pkey" PRIMARY KEY ("id");

-- ----------------------------
-- Indexes structure for table order_attachment
-- ----------------------------
CREATE INDEX "idx_order_attachment_order_id" ON "public"."order_attachment" USING btree (
  "order_id" COLLATE "pg_catalog"."default" "pg_catalog"."text_ops" ASC NULLS LAST
);

-- ----------------------------
-- Checks structure for table order_attachment
-- ----------------------------
ALTER TABLE "public"."order_attachment" ADD CONSTRAINT "order_attachment_attachment_type_check" CHECK ((attachment_type = ANY (ARRAY['合同'::text, '发票'::text, '其他'::text])));
ALTER TABLE "public"."order_attachment" ADD CONSTRAINT "order_attachment_deleted_check" CHECK ((deleted = ANY (ARRAY[0, 1])));

-- ----------------------------
-- Primary Key structure for table order_attachment
-- ----------------------------
ALTER TABLE "public"."order_attachment" ADD CONSTRAINT "order_attachment_pkey" PRIMARY KEY ("id");

-- ----------------------------
-- Indexes structure for table order_detail
-- ----------------------------
CREATE INDEX "idx_order_detail_order_id" ON "public"."order_detail" USING btree (
  "order_id" COLLATE "pg_catalog"."default" "pg_catalog"."text_ops" ASC NULLS LAST
);

-- ----------------------------
-- Checks structure for table order_detail
-- ----------------------------
ALTER TABLE "public"."order_detail" ADD CONSTRAINT "order_detail_deleted_check" CHECK ((deleted = ANY (ARRAY[0, 1])));

-- ----------------------------
-- Primary Key structure for table order_detail
-- ----------------------------
ALTER TABLE "public"."order_detail" ADD CONSTRAINT "order_detail_pkey" PRIMARY KEY ("id");

-- ----------------------------
-- Indexes structure for table order_evaluation
-- ----------------------------
CREATE INDEX "idx_order_evaluation_evaluator_id" ON "public"."order_evaluation" USING btree (
  "evaluator_id" "pg_catalog"."int8_ops" ASC NULLS LAST
);
CREATE INDEX "idx_order_evaluation_order_id" ON "public"."order_evaluation" USING btree (
  "order_id" COLLATE "pg_catalog"."default" "pg_catalog"."text_ops" ASC NULLS LAST
);

-- ----------------------------
-- Checks structure for table order_evaluation
-- ----------------------------
ALTER TABLE "public"."order_evaluation" ADD CONSTRAINT "order_evaluation_rating_check" CHECK (((rating >= 1) AND (rating <= 5)));
ALTER TABLE "public"."order_evaluation" ADD CONSTRAINT "order_evaluation_service_rating_check" CHECK (((service_rating >= 1) AND (service_rating <= 5)));
ALTER TABLE "public"."order_evaluation" ADD CONSTRAINT "order_evaluation_quality_rating_check" CHECK (((quality_rating >= 1) AND (quality_rating <= 5)));
ALTER TABLE "public"."order_evaluation" ADD CONSTRAINT "order_evaluation_delivery_rating_check" CHECK (((delivery_rating >= 1) AND (delivery_rating <= 5)));
ALTER TABLE "public"."order_evaluation" ADD CONSTRAINT "order_evaluation_deleted_check" CHECK ((deleted = ANY (ARRAY[0, 1])));
ALTER TABLE "public"."order_evaluation" ADD CONSTRAINT "order_evaluation_evaluator_type_check" CHECK ((evaluator_type = ANY (ARRAY['买家'::text, '卖家'::text])));

-- ----------------------------
-- Primary Key structure for table order_evaluation
-- ----------------------------
ALTER TABLE "public"."order_evaluation" ADD CONSTRAINT "order_evaluation_pkey" PRIMARY KEY ("id");

-- ----------------------------
-- Indexes structure for table order_info
-- ----------------------------
CREATE INDEX "idx_order_info_apply_time" ON "public"."order_info" USING btree (
  "apply_time" "pg_catalog"."timestamp_ops" ASC NULLS LAST
);
CREATE INDEX "idx_order_info_provider_id" ON "public"."order_info" USING btree (
  "provider_id" "pg_catalog"."int8_ops" ASC NULLS LAST
);
CREATE INDEX "idx_order_info_status" ON "public"."order_info" USING btree (
  "order_status" COLLATE "pg_catalog"."default" "pg_catalog"."text_ops" ASC NULLS LAST
);
CREATE INDEX "idx_order_info_user_id" ON "public"."order_info" USING btree (
  "user_id" "pg_catalog"."int8_ops" ASC NULLS LAST
);

-- ----------------------------
-- Checks structure for table order_info
-- ----------------------------
ALTER TABLE "public"."order_info" ADD CONSTRAINT "order_info_payment_type_check" CHECK ((payment_type = ANY (ARRAY['积分'::text, '货币'::text, '协议'::text])));
ALTER TABLE "public"."order_info" ADD CONSTRAINT "order_info_payment_status_check" CHECK ((payment_status = ANY (ARRAY['未支付'::text, '已支付'::text, '支付失败'::text, '已退款'::text])));
ALTER TABLE "public"."order_info" ADD CONSTRAINT "order_info_deleted_check" CHECK ((deleted = ANY (ARRAY[0, 1])));
ALTER TABLE "public"."order_info" ADD CONSTRAINT "order_info_order_status_check" CHECK ((order_status = ANY (ARRAY['待审批'::text, '待审批授权'::text, '待授权'::text, '待上传文件'::text, '待交易确认'::text, '已完成'::text, '已取消'::text, '已驳回'::text])));

-- ----------------------------
-- Primary Key structure for table order_info
-- ----------------------------
ALTER TABLE "public"."order_info" ADD CONSTRAINT "order_info_pkey" PRIMARY KEY ("order_id");

-- ----------------------------
-- Checks structure for table points
-- ----------------------------
ALTER TABLE "public"."points" ADD CONSTRAINT "chk_deleted" CHECK ((deleted = ANY (ARRAY[0, 1])));

-- ----------------------------
-- Primary Key structure for table points
-- ----------------------------
ALTER TABLE "public"."points" ADD CONSTRAINT "points_pkey" PRIMARY KEY ("id");

-- ----------------------------
-- Indexes structure for table points_account
-- ----------------------------
CREATE INDEX "idx_account_user" ON "public"."points_account" USING btree (
  "user_id" "pg_catalog"."int8_ops" ASC NULLS LAST
);

-- ----------------------------
-- Checks structure for table points_account
-- ----------------------------
ALTER TABLE "public"."points_account" ADD CONSTRAINT "chk_account_type" CHECK ((account_type = ANY (ARRAY['个人积分'::text, '单位积分'::text])));
ALTER TABLE "public"."points_account" ADD CONSTRAINT "chk_account_status" CHECK ((account_status = ANY (ARRAY['正常'::text, '冻结'::text, '注销'::text])));
ALTER TABLE "public"."points_account" ADD CONSTRAINT "chk_account_deleted" CHECK ((deleted = ANY (ARRAY[0, 1])));

-- ----------------------------
-- Primary Key structure for table points_account
-- ----------------------------
ALTER TABLE "public"."points_account" ADD CONSTRAINT "points_account_pkey" PRIMARY KEY ("id");

-- ----------------------------
-- Indexes structure for table points_flow
-- ----------------------------
CREATE INDEX "idx_points_flow_data_category" ON "public"."points_flow" USING btree (
  "data_category" COLLATE "pg_catalog"."default" "pg_catalog"."text_ops" ASC NULLS LAST
);
CREATE INDEX "idx_points_flow_flow_time" ON "public"."points_flow" USING btree (
  "flow_time" "pg_catalog"."timestamp_ops" ASC NULLS LAST
);
CREATE INDEX "idx_points_flow_unit_id" ON "public"."points_flow" USING btree (
  "unit_id" "pg_catalog"."int8_ops" ASC NULLS LAST
);
CREATE INDEX "idx_points_flow_user_id" ON "public"."points_flow" USING btree (
  "user_id" "pg_catalog"."int8_ops" ASC NULLS LAST
);

-- ----------------------------
-- Primary Key structure for table points_flow
-- ----------------------------
ALTER TABLE "public"."points_flow" ADD CONSTRAINT "points_flow_pkey" PRIMARY KEY ("id");

-- ----------------------------
-- Indexes structure for table points_rule
-- ----------------------------
CREATE INDEX "idx_points_rule_points" ON "public"."points_rule" USING btree (
  "points_id" "pg_catalog"."int8_ops" ASC NULLS LAST
);
CREATE INDEX "idx_points_rule_points_id" ON "public"."points_rule" USING btree (
  "points_id" "pg_catalog"."int8_ops" ASC NULLS LAST
);
CREATE INDEX "idx_points_rule_type" ON "public"."points_rule" USING btree (
  "rule_type" "pg_catalog"."int2_ops" ASC NULLS LAST
);

-- ----------------------------
-- Checks structure for table points_rule
-- ----------------------------
ALTER TABLE "public"."points_rule" ADD CONSTRAINT "chk_rule_deleted" CHECK ((deleted = ANY (ARRAY[0, 1])));
ALTER TABLE "public"."points_rule" ADD CONSTRAINT "chk_category" CHECK (((category)::text = ANY (ARRAY['资源贡献'::text, '资源传播'::text, '资源交易'::text, '交流社区互动'::text])));

-- ----------------------------
-- Primary Key structure for table points_rule
-- ----------------------------
ALTER TABLE "public"."points_rule" ADD CONSTRAINT "points_rule_pkey" PRIMARY KEY ("id");

-- ----------------------------
-- Indexes structure for table points_rule_detail
-- ----------------------------
CREATE INDEX "idx_points_detail_rule" ON "public"."points_rule_detail" USING btree (
  "rule_id" "pg_catalog"."int8_ops" ASC NULLS LAST
);
CREATE INDEX "idx_points_rule_detail_rule_id" ON "public"."points_rule_detail" USING btree (
  "rule_id" "pg_catalog"."int8_ops" ASC NULLS LAST
);

-- ----------------------------
-- Checks structure for table points_rule_detail
-- ----------------------------
ALTER TABLE "public"."points_rule_detail" ADD CONSTRAINT "chk_detail_deleted" CHECK ((deleted = ANY (ARRAY[0, 1])));

-- ----------------------------
-- Primary Key structure for table points_rule_detail
-- ----------------------------
ALTER TABLE "public"."points_rule_detail" ADD CONSTRAINT "points_rule_detail_pkey" PRIMARY KEY ("id");

-- ----------------------------
-- Indexes structure for table points_transaction
-- ----------------------------
CREATE INDEX "idx_transaction_time" ON "public"."points_transaction" USING btree (
  "transaction_time" "pg_catalog"."timestamptz_ops" ASC NULLS LAST
);
CREATE INDEX "idx_transaction_user" ON "public"."points_transaction" USING btree (
  "user_id" "pg_catalog"."int8_ops" ASC NULLS LAST
);

-- ----------------------------
-- Checks structure for table points_transaction
-- ----------------------------
ALTER TABLE "public"."points_transaction" ADD CONSTRAINT "chk_data_category" CHECK ((data_category = ANY (ARRAY['用户参与'::text, '其他'::text])));
ALTER TABLE "public"."points_transaction" ADD CONSTRAINT "chk_trans_rule_type" CHECK ((rule_type = ANY (ARRAY['获取'::text, '消耗'::text])));
ALTER TABLE "public"."points_transaction" ADD CONSTRAINT "chk_user_type" CHECK ((user_type = ANY (ARRAY['单位用户'::text, '个人用户'::text])));
ALTER TABLE "public"."points_transaction" ADD CONSTRAINT "chk_trans_deleted" CHECK ((deleted = ANY (ARRAY[0, 1])));

-- ----------------------------
-- Primary Key structure for table points_transaction
-- ----------------------------
ALTER TABLE "public"."points_transaction" ADD CONSTRAINT "points_transaction_pkey" PRIMARY KEY ("id");

-- ----------------------------
-- Indexes structure for table product
-- ----------------------------
CREATE INDEX "idx_product_provider_id" ON "public"."product" USING btree (
  "provider_id" "pg_catalog"."int8_ops" ASC NULLS LAST
);
CREATE INDEX "idx_product_status" ON "public"."product" USING btree (
  "status" COLLATE "pg_catalog"."default" "pg_catalog"."text_ops" ASC NULLS LAST
);

-- ----------------------------
-- Uniques structure for table product
-- ----------------------------
ALTER TABLE "public"."product" ADD CONSTRAINT "product_product_code_key" UNIQUE ("product_code");

-- ----------------------------
-- Checks structure for table product
-- ----------------------------
ALTER TABLE "public"."product" ADD CONSTRAINT "product_provider_type_check" CHECK ((provider_type = ANY (ARRAY['企业'::text, '个人'::text])));
ALTER TABLE "public"."product" ADD CONSTRAINT "product_status_check" CHECK ((status = ANY (ARRAY['上架'::text, '下架'::text, '审核中'::text, '已下架'::text])));
ALTER TABLE "public"."product" ADD CONSTRAINT "product_audit_status_check" CHECK ((audit_status = ANY (ARRAY['待审核'::text, '审核通过'::text, '审核驳回'::text])));
ALTER TABLE "public"."product" ADD CONSTRAINT "product_deleted_check" CHECK ((deleted = ANY (ARRAY[0, 1])));

-- ----------------------------
-- Primary Key structure for table product
-- ----------------------------
ALTER TABLE "public"."product" ADD CONSTRAINT "product_pkey" PRIMARY KEY ("id");

-- ----------------------------
-- Indexes structure for table product_pricing
-- ----------------------------
CREATE INDEX "idx_product_pricing_product_id" ON "public"."product_pricing" USING btree (
  "product_id" "pg_catalog"."int8_ops" ASC NULLS LAST
);
CREATE INDEX "idx_product_pricing_status" ON "public"."product_pricing" USING btree (
  "is_active" "pg_catalog"."bool_ops" ASC NULLS LAST
);

-- ----------------------------
-- Checks structure for table product_pricing
-- ----------------------------
ALTER TABLE "public"."product_pricing" ADD CONSTRAINT "product_pricing_customer_type_check" CHECK ((customer_type = ANY (ARRAY['企业'::text, '个人'::text, '项目部'::text])));
ALTER TABLE "public"."product_pricing" ADD CONSTRAINT "product_pricing_price_type_check" CHECK ((price_type = ANY (ARRAY['积分'::text, '协议'::text, '货币'::text, '免费'::text])));
ALTER TABLE "public"."product_pricing" ADD CONSTRAINT "product_pricing_price_unit_check" CHECK ((price_unit = ANY (ARRAY['套'::text, '套/年'::text, '年'::text, '个'::text, '次'::text])));
ALTER TABLE "public"."product_pricing" ADD CONSTRAINT "product_pricing_deleted_check" CHECK ((deleted = ANY (ARRAY[0, 1])));
ALTER TABLE "public"."product_pricing" ADD CONSTRAINT "product_pricing_sales_form_check" CHECK ((sales_form = ANY (ARRAY['买断'::text, '租赁'::text, '私有增包量'::text, '公有增包量'::text, 'OTA服务'::text, '资源包'::text, '个人'::text])));

-- ----------------------------
-- Primary Key structure for table product_pricing
-- ----------------------------
ALTER TABLE "public"."product_pricing" ADD CONSTRAINT "product_pricing_pkey" PRIMARY KEY ("id");

-- ----------------------------
-- Uniques structure for table unit
-- ----------------------------
ALTER TABLE "public"."unit" ADD CONSTRAINT "unit_unit_code_key" UNIQUE ("unit_code");

-- ----------------------------
-- Checks structure for table unit
-- ----------------------------
ALTER TABLE "public"."unit" ADD CONSTRAINT "unit_status_check" CHECK ((status = ANY (ARRAY['正常'::text, '冻结'::text, '注销'::text])));
ALTER TABLE "public"."unit" ADD CONSTRAINT "unit_deleted_check" CHECK ((deleted = ANY (ARRAY[0, 1])));

-- ----------------------------
-- Primary Key structure for table unit
-- ----------------------------
ALTER TABLE "public"."unit" ADD CONSTRAINT "unit_pkey" PRIMARY KEY ("id");

-- ----------------------------
-- Indexes structure for table user_points
-- ----------------------------
CREATE INDEX "idx_user_points_unit_id" ON "public"."user_points" USING btree (
  "unit_id" "pg_catalog"."int8_ops" ASC NULLS LAST
);
CREATE INDEX "idx_user_points_user_id" ON "public"."user_points" USING btree (
  "user_id" "pg_catalog"."int8_ops" ASC NULLS LAST
);

-- ----------------------------
-- Primary Key structure for table user_points
-- ----------------------------
ALTER TABLE "public"."user_points" ADD CONSTRAINT "user_points_pkey" PRIMARY KEY ("id");

-- ----------------------------
-- Indexes structure for table users
-- ----------------------------
CREATE INDEX "idx_users_status" ON "public"."users" USING btree (
  "status" COLLATE "pg_catalog"."default" "pg_catalog"."text_ops" ASC NULLS LAST
);
CREATE INDEX "idx_users_unit_id" ON "public"."users" USING btree (
  "unit_id" "pg_catalog"."int8_ops" ASC NULLS LAST
);

-- ----------------------------
-- Uniques structure for table users
-- ----------------------------
ALTER TABLE "public"."users" ADD CONSTRAINT "users_username_key" UNIQUE ("username");

-- ----------------------------
-- Checks structure for table users
-- ----------------------------
ALTER TABLE "public"."users" ADD CONSTRAINT "users_user_type_check" CHECK ((user_type = ANY (ARRAY['个人用户'::text, '单位用户'::text])));
ALTER TABLE "public"."users" ADD CONSTRAINT "users_status_check" CHECK ((status = ANY (ARRAY['正常'::text, '冻结'::text, '注销'::text])));
ALTER TABLE "public"."users" ADD CONSTRAINT "users_deleted_check" CHECK ((deleted = ANY (ARRAY[0, 1])));

-- ----------------------------
-- Primary Key structure for table users
-- ----------------------------
ALTER TABLE "public"."users" ADD CONSTRAINT "users_pkey" PRIMARY KEY ("id");

-- ----------------------------
-- Foreign Keys structure for table cart
-- ----------------------------
ALTER TABLE "public"."cart" ADD CONSTRAINT "cart_pricing_id_fkey" FOREIGN KEY ("pricing_id") REFERENCES "public"."product_pricing" ("id") ON DELETE NO ACTION ON UPDATE NO ACTION;
ALTER TABLE "public"."cart" ADD CONSTRAINT "cart_product_id_fkey" FOREIGN KEY ("product_id") REFERENCES "public"."product" ("id") ON DELETE NO ACTION ON UPDATE NO ACTION;
ALTER TABLE "public"."cart" ADD CONSTRAINT "cart_provider_id_fkey" FOREIGN KEY ("provider_id") REFERENCES "public"."users" ("id") ON DELETE NO ACTION ON UPDATE NO ACTION;
ALTER TABLE "public"."cart" ADD CONSTRAINT "cart_unit_id_fkey" FOREIGN KEY ("unit_id") REFERENCES "public"."unit" ("id") ON DELETE NO ACTION ON UPDATE NO ACTION;
ALTER TABLE "public"."cart" ADD CONSTRAINT "cart_user_id_fkey" FOREIGN KEY ("user_id") REFERENCES "public"."users" ("id") ON DELETE NO ACTION ON UPDATE NO ACTION;

-- ----------------------------
-- Foreign Keys structure for table order_approval
-- ----------------------------
ALTER TABLE "public"."order_approval" ADD CONSTRAINT "order_approval_approver_id_fkey" FOREIGN KEY ("approver_id") REFERENCES "public"."users" ("id") ON DELETE NO ACTION ON UPDATE NO ACTION;
ALTER TABLE "public"."order_approval" ADD CONSTRAINT "order_approval_next_approver_id_fkey" FOREIGN KEY ("next_approver_id") REFERENCES "public"."users" ("id") ON DELETE NO ACTION ON UPDATE NO ACTION;
ALTER TABLE "public"."order_approval" ADD CONSTRAINT "order_approval_order_id_fkey" FOREIGN KEY ("order_id") REFERENCES "public"."order_info" ("order_id") ON DELETE NO ACTION ON UPDATE NO ACTION;

-- ----------------------------
-- Foreign Keys structure for table order_attachment
-- ----------------------------
ALTER TABLE "public"."order_attachment" ADD CONSTRAINT "order_attachment_order_id_fkey" FOREIGN KEY ("order_id") REFERENCES "public"."order_info" ("order_id") ON DELETE NO ACTION ON UPDATE NO ACTION;
ALTER TABLE "public"."order_attachment" ADD CONSTRAINT "order_attachment_upload_user_id_fkey" FOREIGN KEY ("upload_user_id") REFERENCES "public"."users" ("id") ON DELETE NO ACTION ON UPDATE NO ACTION;

-- ----------------------------
-- Foreign Keys structure for table order_detail
-- ----------------------------
ALTER TABLE "public"."order_detail" ADD CONSTRAINT "order_detail_order_id_fkey" FOREIGN KEY ("order_id") REFERENCES "public"."order_info" ("order_id") ON DELETE NO ACTION ON UPDATE NO ACTION;
ALTER TABLE "public"."order_detail" ADD CONSTRAINT "order_detail_pricing_id_fkey" FOREIGN KEY ("pricing_id") REFERENCES "public"."product_pricing" ("id") ON DELETE NO ACTION ON UPDATE NO ACTION;
ALTER TABLE "public"."order_detail" ADD CONSTRAINT "order_detail_product_id_fkey" FOREIGN KEY ("product_id") REFERENCES "public"."product" ("id") ON DELETE NO ACTION ON UPDATE NO ACTION;
ALTER TABLE "public"."order_detail" ADD CONSTRAINT "order_detail_provider_id_fkey" FOREIGN KEY ("provider_id") REFERENCES "public"."users" ("id") ON DELETE NO ACTION ON UPDATE NO ACTION;

-- ----------------------------
-- Foreign Keys structure for table order_evaluation
-- ----------------------------
ALTER TABLE "public"."order_evaluation" ADD CONSTRAINT "order_evaluation_evaluator_id_fkey" FOREIGN KEY ("evaluator_id") REFERENCES "public"."users" ("id") ON DELETE NO ACTION ON UPDATE NO ACTION;
ALTER TABLE "public"."order_evaluation" ADD CONSTRAINT "order_evaluation_order_id_fkey" FOREIGN KEY ("order_id") REFERENCES "public"."order_info" ("order_id") ON DELETE NO ACTION ON UPDATE NO ACTION;
ALTER TABLE "public"."order_evaluation" ADD CONSTRAINT "order_evaluation_reply_user_id_fkey" FOREIGN KEY ("reply_user_id") REFERENCES "public"."users" ("id") ON DELETE NO ACTION ON UPDATE NO ACTION;

-- ----------------------------
-- Foreign Keys structure for table order_info
-- ----------------------------
ALTER TABLE "public"."order_info" ADD CONSTRAINT "order_info_product_id_fkey" FOREIGN KEY ("product_id") REFERENCES "public"."product" ("id") ON DELETE NO ACTION ON UPDATE NO ACTION;
ALTER TABLE "public"."order_info" ADD CONSTRAINT "order_info_provider_id_fkey" FOREIGN KEY ("provider_id") REFERENCES "public"."users" ("id") ON DELETE NO ACTION ON UPDATE NO ACTION;
ALTER TABLE "public"."order_info" ADD CONSTRAINT "order_info_unit_id_fkey" FOREIGN KEY ("unit_id") REFERENCES "public"."unit" ("id") ON DELETE NO ACTION ON UPDATE NO ACTION;
ALTER TABLE "public"."order_info" ADD CONSTRAINT "order_info_user_id_fkey" FOREIGN KEY ("user_id") REFERENCES "public"."users" ("id") ON DELETE NO ACTION ON UPDATE NO ACTION;

-- ----------------------------
-- Foreign Keys structure for table points_rule
-- ----------------------------
ALTER TABLE "public"."points_rule" ADD CONSTRAINT "fk_points" FOREIGN KEY ("points_id") REFERENCES "public"."points" ("id") ON DELETE NO ACTION ON UPDATE NO ACTION;

-- ----------------------------
-- Foreign Keys structure for table points_rule_detail
-- ----------------------------
ALTER TABLE "public"."points_rule_detail" ADD CONSTRAINT "fk_detail_points" FOREIGN KEY ("points_id") REFERENCES "public"."points" ("id") ON DELETE NO ACTION ON UPDATE NO ACTION;
ALTER TABLE "public"."points_rule_detail" ADD CONSTRAINT "fk_rule" FOREIGN KEY ("rule_id") REFERENCES "public"."points_rule" ("id") ON DELETE NO ACTION ON UPDATE NO ACTION;

-- ----------------------------
-- Foreign Keys structure for table points_transaction
-- ----------------------------
ALTER TABLE "public"."points_transaction" ADD CONSTRAINT "fk_detail_id" FOREIGN KEY ("detail_id") REFERENCES "public"."points_rule_detail" ("id") ON DELETE NO ACTION ON UPDATE NO ACTION;
ALTER TABLE "public"."points_transaction" ADD CONSTRAINT "fk_rule_id" FOREIGN KEY ("rule_id") REFERENCES "public"."points_rule" ("id") ON DELETE NO ACTION ON UPDATE NO ACTION;

-- ----------------------------
-- Foreign Keys structure for table product
-- ----------------------------
ALTER TABLE "public"."product" ADD CONSTRAINT "product_created_by_fkey" FOREIGN KEY ("created_by") REFERENCES "public"."users" ("id") ON DELETE NO ACTION ON UPDATE NO ACTION;
ALTER TABLE "public"."product" ADD CONSTRAINT "product_provider_id_fkey" FOREIGN KEY ("provider_id") REFERENCES "public"."users" ("id") ON DELETE NO ACTION ON UPDATE NO ACTION;
ALTER TABLE "public"."product" ADD CONSTRAINT "product_updated_by_fkey" FOREIGN KEY ("updated_by") REFERENCES "public"."users" ("id") ON DELETE NO ACTION ON UPDATE NO ACTION;

-- ----------------------------
-- Foreign Keys structure for table product_pricing
-- ----------------------------
ALTER TABLE "public"."product_pricing" ADD CONSTRAINT "product_pricing_created_by_fkey" FOREIGN KEY ("created_by") REFERENCES "public"."users" ("id") ON DELETE NO ACTION ON UPDATE NO ACTION;
ALTER TABLE "public"."product_pricing" ADD CONSTRAINT "product_pricing_product_id_fkey" FOREIGN KEY ("product_id") REFERENCES "public"."product" ("id") ON DELETE NO ACTION ON UPDATE NO ACTION;
ALTER TABLE "public"."product_pricing" ADD CONSTRAINT "product_pricing_provider_id_fkey" FOREIGN KEY ("provider_id") REFERENCES "public"."users" ("id") ON DELETE NO ACTION ON UPDATE NO ACTION;
ALTER TABLE "public"."product_pricing" ADD CONSTRAINT "product_pricing_updated_by_fkey" FOREIGN KEY ("updated_by") REFERENCES "public"."users" ("id") ON DELETE NO ACTION ON UPDATE NO ACTION;

-- ----------------------------
-- Foreign Keys structure for table users
-- ----------------------------
ALTER TABLE "public"."users" ADD CONSTRAINT "users_unit_id_fkey" FOREIGN KEY ("unit_id") REFERENCES "public"."unit" ("id") ON DELETE NO ACTION ON UPDATE NO ACTION;
