product_management/mysql.ddl.sql
yumoqing 4fd136bf53 refactor: reseller org_id isolation for product_management module
- product_category: org_id scoped tree, product_table_name -> product_type
- product: org_id scoped, added extra_json for custom attributes, product_type field
- product_type_config: org_id + operator_id dual isolation, unique key on (org_id, operator_id, category_id, config_name)
- All 18 API endpoints enforce org_id filtering via ServerEnv
- core.py: all methods accept optional org_id, default to current user's org
- CRUD definitions: logined_userorgid set to org_id on all lists
- init/data.json: removed hardcoded global categories (managed per reseller)
- Rebuilt mysql.ddl.sql and all CRUD UI files
2026-05-25 17:03:08 +08:00

131 lines
4.6 KiB
SQL
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

-- ./product_category.json
-- 建库时请用以下语句支持emoji字符
-- CREATE DATABASE mydb CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
drop table if exists product_category;
CREATE TABLE product_category
(
`id` VARCHAR(32) NOT NULL comment '主键ID',
`parent_id` VARCHAR(32) DEFAULT '0' comment '父类别ID',
`name` VARCHAR(255) NOT NULL comment '类别名称',
`description` longtext CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci comment '类别描述',
`has_product` CHAR(1) DEFAULT '0' comment '是否可挂产品',
`product_type` VARCHAR(64) comment '产品类型标识',
`product_type_title` VARCHAR(255) comment '产品类型显示名',
`sort_order` int DEFAULT '0' comment '排序序号',
`icon` VARCHAR(255) comment '图标',
`status` CHAR(1) DEFAULT '1' comment '状态',
`org_id` VARCHAR(32) DEFAULT '0' comment '所属机构ID',
`created_by` VARCHAR(32) comment '创建人',
`created_at` datetime NOT NULL comment '创建时间',
`updated_at` datetime NOT NULL comment '更新时间'
,primary key(id)
)
CHARACTER SET utf8mb4
COLLATE utf8mb4_unicode_ci
engine=innodb
comment '产品类别树'
;
CREATE INDEX product_category_idx_pc_org_parent ON product_category(org_id,parent_id);
CREATE INDEX product_category_idx_pc_org_status ON product_category(org_id,status);
CREATE INDEX product_category_idx_pc_org_type ON product_category(org_id,product_type);
-- ./product.json
-- 建库时请用以下语句支持emoji字符
-- CREATE DATABASE mydb CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
drop table if exists product;
CREATE TABLE product
(
`id` VARCHAR(32) NOT NULL comment '主键ID',
`category_id` VARCHAR(32) NOT NULL comment '类别ID',
`product_code` VARCHAR(64) NOT NULL comment '产品编码',
`product_name` VARCHAR(255) NOT NULL comment '产品名称',
`product_type` VARCHAR(64) NOT NULL comment '产品类型标识',
`brief_intro` longtext CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci comment '产品简介',
`detail_intro` longtext CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci comment '产品详情',
`extra_json` longtext CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci comment '扩展属性',
`enabled_date` date comment '启用日期',
`expired_date` date comment '失效日期',
`status` CHAR(1) DEFAULT '1' comment '状态',
`price_type` CHAR(1) DEFAULT '1' comment '价格类型',
`price` double(15,2) DEFAULT '0.00' comment '价格',
`currency` CHAR(8) DEFAULT 'CNY' comment '货币',
`sort_order` int DEFAULT '0' comment '排序序号',
`org_id` VARCHAR(32) DEFAULT '0' comment '所属机构ID',
`created_by` VARCHAR(32) comment '创建人',
`created_at` datetime NOT NULL comment '创建时间',
`updated_at` datetime NOT NULL comment '更新时间'
,primary key(id)
)
CHARACTER SET utf8mb4
COLLATE utf8mb4_unicode_ci
engine=innodb
comment '产品注册表'
;
CREATE INDEX product_idx_product_org_category ON product(org_id,category_id);
CREATE UNIQUE INDEX product_idx_product_org_code ON product(org_id,product_code);
CREATE INDEX product_idx_product_org_type ON product(org_id,product_type);
CREATE INDEX product_idx_product_status ON product(status);
CREATE INDEX product_idx_product_enabled_expired ON product(enabled_date,expired_date);
-- ./product_type_config.json
-- 建库时请用以下语句支持emoji字符
-- CREATE DATABASE mydb CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
drop table if exists product_type_config;
CREATE TABLE product_type_config
(
`id` VARCHAR(32) NOT NULL comment '主键ID',
`operator_id` VARCHAR(32) NOT NULL comment '运营商用户ID',
`org_id` VARCHAR(32) NOT NULL comment '所属机构ID',
`category_id` VARCHAR(32) NOT NULL comment '产品类别ID',
`config_name` VARCHAR(255) NOT NULL comment '配置名称',
`config_json` longtext CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci comment '配置内容',
`enabled_flg` CHAR(1) DEFAULT '1' comment '是否启用',
`created_by` VARCHAR(32) comment '创建人',
`created_at` datetime NOT NULL comment '创建时间',
`updated_at` datetime NOT NULL comment '更新时间'
,primary key(id)
)
CHARACTER SET utf8mb4
COLLATE utf8mb4_unicode_ci
engine=innodb
comment '运营商产品类型配置'
;
CREATE INDEX product_type_config_idx_ptc_org_opr ON product_type_config(org_id,operator_id);
CREATE UNIQUE INDEX product_type_config_idx_ptc_org_cat ON product_type_config(org_id,operator_id,category_id,config_name);
CREATE INDEX product_type_config_idx_ptc_enabled ON product_type_config(enabled_flg);