Files
ecom-dmb/ecom-dmb-backend/sql/ec_design.sql
T
小蟑螂 50db11b15a chore: 移除废弃的 media_image 模块相关设计
- ec_design.sql: 移除 media_image 表定义
- org_design.sql: 移除 org_company.logo_image_id 字段及外键约束
- V20260331__sync_design_and_db.sql: 同步更新
2026-03-31 21:41:45 +08:00

405 lines
27 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.
-- ========================================
-- 电商数据中台数据库设计
-- 生成时间:2026-03-29
-- ========================================
-- ========================================
-- EC_BRUSH_ORDER
-- ========================================
DROP TABLE IF EXISTS `ec_brush_order`;
CREATE TABLE `ec_brush_order` (
`id` bigint unsigned NOT NULL AUTO_INCREMENT COMMENT '刷单记录ID',
`company_id` bigint unsigned NOT NULL COMMENT '公司ID',
`shop_id` bigint unsigned NOT NULL COMMENT '店铺ID',
`product_id` bigint unsigned DEFAULT NULL COMMENT '商品ID(可选)',
`product_spec_id` bigint unsigned DEFAULT NULL COMMENT '商品规格ID(可选)',
`brush_amount` decimal(10,2) NOT NULL DEFAULT '0.00' COMMENT '刷单金额',
`brush_time` timestamp NOT NULL COMMENT '刷单时间',
`platform_order_no` varchar(100) DEFAULT NULL COMMENT '平台订单号(可选)',
`quantity` int DEFAULT '1' COMMENT '刷单数量',
`remark` varchar(500) DEFAULT NULL COMMENT '备注',
`create_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
`update_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
`create_by` bigint unsigned DEFAULT NULL COMMENT '创建人ID',
`update_by` bigint unsigned DEFAULT NULL COMMENT '更新人ID',
PRIMARY KEY (`id`),
KEY `idx_company_id` (`company_id`),
KEY `idx_shop_id` (`shop_id`),
KEY `idx_product_id` (`product_id`),
KEY `idx_product_spec_id` (`product_spec_id`),
KEY `idx_brush_time` (`brush_time`),
KEY `idx_platform_order_no` (`platform_order_no`),
KEY `idx_company_shop_time` (`company_id`,`shop_id`,`brush_time`),
KEY `fk_ec_brush_order_creator` (`create_by`),
KEY `fk_ec_brush_order_updater` (`update_by`),
CONSTRAINT `fk_ec_brush_order_company` FOREIGN KEY (`company_id`) REFERENCES `org_company` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
CONSTRAINT `fk_ec_brush_order_creator` FOREIGN KEY (`create_by`) REFERENCES `sys_user` (`id`) ON DELETE SET NULL ON UPDATE CASCADE,
CONSTRAINT `fk_ec_brush_order_product` FOREIGN KEY (`product_id`) REFERENCES `ec_product` (`id`) ON DELETE SET NULL ON UPDATE CASCADE,
CONSTRAINT `fk_ec_brush_order_product_spec` FOREIGN KEY (`product_spec_id`) REFERENCES `ec_product_spec` (`id`) ON DELETE SET NULL ON UPDATE CASCADE,
CONSTRAINT `fk_ec_brush_order_shop` FOREIGN KEY (`shop_id`) REFERENCES `ec_shop` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
CONSTRAINT `fk_ec_brush_order_updater` FOREIGN KEY (`update_by`) REFERENCES `sys_user` (`id`) ON DELETE SET NULL ON UPDATE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='电商-刷单记录表'
-- ========================================
-- EC_IMPORT_FIELD_DEFS
-- ========================================
DROP TABLE IF EXISTS `ec_import_field_defs`;
CREATE TABLE `ec_import_field_defs` (
`id` bigint unsigned NOT NULL AUTO_INCREMENT COMMENT '字段定义ID',
`type` enum('product','order') NOT NULL COMMENT '导入类型(product-商品 order-订单)',
`field_name` varchar(100) NOT NULL COMMENT '数据库字段名,如 name',
`field_label` varchar(100) NOT NULL COMMENT '中文字段名,如 商品名称',
`file_field_name` varchar(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci DEFAULT NULL COMMENT '文件字段名,如 商品名称',
`required` tinyint(1) DEFAULT '0' COMMENT '是否必填',
`sort` int unsigned DEFAULT '0' COMMENT '排序',
`data_type` varchar(50) DEFAULT 'string' COMMENT 'string, number, date等',
`created_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP,
`updated_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
PRIMARY KEY (`id`),
UNIQUE KEY `uniq_type_field` (`type`,`field_name`)
) ENGINE=InnoDB AUTO_INCREMENT=19 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='电商-导入字段定义表'
-- ========================================
-- EC_IMPORT_MAPPINGS
-- ========================================
DROP TABLE IF EXISTS `ec_import_mappings`;
CREATE TABLE `ec_import_mappings` (
`id` bigint unsigned NOT NULL AUTO_INCREMENT COMMENT '映射ID',
`company_id` bigint unsigned NOT NULL COMMENT '所属公司ID',
`type` enum('PRODUCT','ORDER','ORDER_STATUS') NOT NULL COMMENT '导入类型(PRODUCT-商品 ORDER-订单 ORDER_STATUS-订单状态)',
`name` varchar(20) NOT NULL COMMENT '映射名称',
`mapping` json NOT NULL COMMENT '映射JSON',
`create_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
`update_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
`create_by` bigint unsigned DEFAULT NULL COMMENT '创建人ID',
`update_by` bigint unsigned DEFAULT NULL COMMENT '更新人ID',
PRIMARY KEY (`id`),
UNIQUE KEY `uniq_company_type_name` (`company_id`,`type`,`name`),
KEY `fk_import_mapping_creator` (`create_by`),
KEY `fk_import_mapping_updater` (`update_by`),
CONSTRAINT `fk_import_mapping_company` FOREIGN KEY (`company_id`) REFERENCES `org_company` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
CONSTRAINT `fk_import_mapping_creator` FOREIGN KEY (`create_by`) REFERENCES `sys_user` (`id`) ON DELETE SET NULL ON UPDATE CASCADE,
CONSTRAINT `fk_import_mapping_updater` FOREIGN KEY (`update_by`) REFERENCES `sys_user` (`id`) ON DELETE SET NULL ON UPDATE CASCADE
) ENGINE=InnoDB AUTO_INCREMENT=5 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='电商-导入映射表'
-- ========================================
-- EC_IMPORT_TASKS
-- ========================================
DROP TABLE IF EXISTS `ec_import_tasks`;
CREATE TABLE `ec_import_tasks` (
`id` bigint unsigned NOT NULL AUTO_INCREMENT COMMENT '主键ID',
`company_id` bigint unsigned NOT NULL COMMENT '所属公司ID',
`shop_id` bigint unsigned DEFAULT NULL COMMENT '所属店铺ID',
`type` enum('product','order') NOT NULL COMMENT '导入类型(product-商品 order-订单)',
`task_name` varchar(100) DEFAULT NULL COMMENT '任务名称',
`file_name` varchar(255) NOT NULL COMMENT '原始文件名',
`file_id` bigint unsigned DEFAULT NULL COMMENT '关联文件ID(外键到sys_file)',
`status` enum('pending','processing','success','failed') NOT NULL DEFAULT 'pending' COMMENT '任务状态(pending-待处理 processing-处理中 success-成功 failed-失败)',
`total_count` int unsigned DEFAULT '0' COMMENT '总行数',
`success_count` int unsigned DEFAULT '0' COMMENT '成功行数',
`fail_count` int unsigned DEFAULT '0' COMMENT '失败行数',
`mapping` json DEFAULT NULL COMMENT '字段映射记录',
`message` text COMMENT '错误信息或备注',
`create_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
`update_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
`create_by` bigint unsigned DEFAULT NULL COMMENT '创建人ID',
`update_by` bigint unsigned DEFAULT NULL COMMENT '更新人ID',
PRIMARY KEY (`id`),
KEY `idx_company_id` (`company_id`),
KEY `idx_create_by` (`create_by`),
KEY `idx_update_by` (`update_by`),
KEY `idx_file_id` (`file_id`),
CONSTRAINT `fk_import_task_company` FOREIGN KEY (`company_id`) REFERENCES `org_company` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
CONSTRAINT `fk_import_task_creator` FOREIGN KEY (`create_by`) REFERENCES `sys_user` (`id`) ON DELETE SET NULL ON UPDATE CASCADE,
CONSTRAINT `fk_import_task_updater` FOREIGN KEY (`update_by`) REFERENCES `sys_user` (`id`) ON DELETE SET NULL ON UPDATE CASCADE,
CONSTRAINT `fk_import_task_file` FOREIGN KEY (`file_id`) REFERENCES `sys_file` (`id`) ON DELETE SET NULL ON UPDATE CASCADE
) ENGINE=InnoDB AUTO_INCREMENT=174 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='电商-导入任务表'
-- ========================================
-- EC_ORDER
-- ========================================
DROP TABLE IF EXISTS `ec_order`;
CREATE TABLE `ec_order` (
`id` bigint unsigned NOT NULL AUTO_INCREMENT COMMENT '订单ID',
`company_id` bigint unsigned NOT NULL COMMENT '公司ID',
`shop_id` bigint unsigned NOT NULL COMMENT '店铺ID',
`product_id` bigint unsigned NOT NULL COMMENT '商品ID',
`product_spec_id` bigint unsigned DEFAULT NULL COMMENT '商品规格ID',
`status_id` bigint unsigned NOT NULL COMMENT '订单状态ID',
`platform_order_no` varchar(100) DEFAULT NULL COMMENT '平台订单号',
`link_product_name` varchar(255) NOT NULL COMMENT '链接商品名称',
`link_spec_name` varchar(200) DEFAULT NULL COMMENT '链接规格名称',
`received_amount` decimal(10,2) NOT NULL DEFAULT '0.00' COMMENT '商家实收金额',
`quantity` int NOT NULL DEFAULT '1' COMMENT '数量',
`unit_price` decimal(10,2) NOT NULL DEFAULT '0.00' COMMENT '销售单价',
`product_cost` decimal(10,2) NOT NULL DEFAULT '0.00' COMMENT '单件商品成本(下单时快照)',
`shipping_cost` decimal(10,2) NOT NULL DEFAULT '0.00' COMMENT '单件运费成本(下单时快照)',
`other_cost` decimal(10,2) NOT NULL DEFAULT '0.00' COMMENT '单件其他成本(下单时快照)',
`remark` varchar(500) DEFAULT NULL COMMENT '备注',
`import_task_id` bigint unsigned DEFAULT NULL COMMENT '导入任务ID',
`confirm` tinyint NOT NULL DEFAULT '1' COMMENT '确认(0-否 1-是)',
`order_time` timestamp NOT NULL COMMENT '下单时间',
`create_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
`update_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
`create_by` bigint unsigned DEFAULT NULL COMMENT '创建人ID',
`update_by` bigint unsigned DEFAULT NULL COMMENT '更新人ID',
PRIMARY KEY (`id`),
UNIQUE KEY `uk_company_shop_platform` (`company_id`, `shop_id`, `platform_order_no`),
KEY `idx_company_shop_time` (`company_id`,`shop_id`,`order_time`),
KEY `idx_status_id` (`status_id`),
KEY `idx_platform_order_no` (`platform_order_no`),
KEY `idx_product_id` (`product_id`),
KEY `idx_product_spec_id` (`product_spec_id`),
KEY `idx_import_task_id` (`import_task_id`),
KEY `idx_confirm` (`confirm`),
KEY `fk_ec_order_creator` (`create_by`),
KEY `fk_ec_order_updater` (`update_by`),
KEY `fk_ec_order_shop` (`shop_id`),
CONSTRAINT `fk_ec_order_company` FOREIGN KEY (`company_id`) REFERENCES `org_company` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
CONSTRAINT `fk_ec_order_creator` FOREIGN KEY (`create_by`) REFERENCES `sys_user` (`id`) ON DELETE SET NULL ON UPDATE CASCADE,
CONSTRAINT `fk_ec_order_import_task` FOREIGN KEY (`import_task_id`) REFERENCES `ec_import_tasks` (`id`) ON DELETE SET NULL ON UPDATE CASCADE,
CONSTRAINT `fk_ec_order_product` FOREIGN KEY (`product_id`) REFERENCES `ec_product` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
CONSTRAINT `fk_ec_order_product_spec` FOREIGN KEY (`product_spec_id`) REFERENCES `ec_product_spec` (`id`) ON DELETE SET NULL ON UPDATE CASCADE,
CONSTRAINT `fk_ec_order_shop` FOREIGN KEY (`shop_id`) REFERENCES `ec_shop` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
CONSTRAINT `fk_ec_order_status` FOREIGN KEY (`status_id`) REFERENCES `ec_order_status` (`id`) ON DELETE RESTRICT ON UPDATE CASCADE,
CONSTRAINT `fk_ec_order_updater` FOREIGN KEY (`update_by`) REFERENCES `sys_user` (`id`) ON DELETE SET NULL ON UPDATE CASCADE
) ENGINE=InnoDB AUTO_INCREMENT=1351 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='电商-订单表(含商品明细)'
-- ========================================
-- EC_ORDER_STATUS
-- ========================================
DROP TABLE IF EXISTS `ec_order_status`;
CREATE TABLE `ec_order_status` (
`id` bigint unsigned NOT NULL AUTO_INCREMENT COMMENT '订单状态ID',
`company_id` bigint unsigned NOT NULL COMMENT '公司ID',
`status_name` varchar(100) NOT NULL COMMENT '状态名称(中文)',
`description` varchar(200) DEFAULT NULL COMMENT '状态描述',
`color` varchar(20) DEFAULT NULL COMMENT '状态颜色(十六进制)',
`sort_order` int NOT NULL DEFAULT '0' COMMENT '排序',
`auto_statistics` tinyint NOT NULL DEFAULT '1' COMMENT '是否自动参与统计 0不参与 1参与',
`is_refund` tinyint NOT NULL DEFAULT '0' COMMENT '是否为退款状态 0否 1是',
`create_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
`update_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
`create_by` bigint unsigned DEFAULT NULL COMMENT '创建人ID',
`update_by` bigint unsigned DEFAULT NULL COMMENT '更新人ID',
PRIMARY KEY (`id`),
UNIQUE KEY `uk_company_status_name` (`company_id`,`status_name`),
KEY `idx_company_id` (`company_id`),
KEY `idx_sort_order` (`sort_order`),
KEY `idx_auto_statistics` (`auto_statistics`),
KEY `fk_ec_order_status_creator` (`create_by`),
KEY `fk_ec_order_status_updater` (`update_by`),
KEY `idx_is_refund` (`is_refund`),
CONSTRAINT `fk_ec_order_status_company` FOREIGN KEY (`company_id`) REFERENCES `org_company` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
CONSTRAINT `fk_ec_order_status_creator` FOREIGN KEY (`create_by`) REFERENCES `sys_user` (`id`) ON DELETE SET NULL ON UPDATE CASCADE,
CONSTRAINT `fk_ec_order_status_updater` FOREIGN KEY (`update_by`) REFERENCES `sys_user` (`id`) ON DELETE SET NULL ON UPDATE CASCADE
) ENGINE=InnoDB AUTO_INCREMENT=8 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='电商-订单状态表'
-- ========================================
-- EC_PRODUCT
-- ========================================
DROP TABLE IF EXISTS `ec_product`;
CREATE TABLE `ec_product` (
`id` bigint unsigned NOT NULL AUTO_INCREMENT COMMENT '商品ID',
`company_id` bigint unsigned NOT NULL COMMENT '公司ID',
`name` varchar(255) NOT NULL COMMENT '商品名称',
`product_code` varchar(100) DEFAULT NULL COMMENT '商品编码',
`main_image_id` bigint unsigned DEFAULT NULL COMMENT '主图图片ID',
`create_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
`update_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
`create_by` bigint unsigned DEFAULT NULL COMMENT '创建人ID',
`update_by` bigint unsigned DEFAULT NULL COMMENT '更新人ID',
PRIMARY KEY (`id`),
UNIQUE KEY `uk_product_code` (`product_code`),
KEY `idx_company_id` (`company_id`),
KEY `fk_ec_product_main_image` (`main_image_id`),
KEY `fk_ec_product_creator` (`create_by`),
KEY `fk_ec_product_updater` (`update_by`),
CONSTRAINT `fk_ec_product_company` FOREIGN KEY (`company_id`) REFERENCES `org_company` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
CONSTRAINT `fk_ec_product_creator` FOREIGN KEY (`create_by`) REFERENCES `sys_user` (`id`) ON DELETE SET NULL ON UPDATE CASCADE,
CONSTRAINT `fk_ec_product_main_image` FOREIGN KEY (`main_image_id`) REFERENCES `sys_file` (`id`) ON DELETE SET NULL ON UPDATE CASCADE,
CONSTRAINT `fk_ec_product_updater` FOREIGN KEY (`update_by`) REFERENCES `sys_user` (`id`) ON DELETE SET NULL ON UPDATE CASCADE
) ENGINE=InnoDB AUTO_INCREMENT=10 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='电商-商品表(含成本价)'
-- ========================================
-- EC_PRODUCT_SPEC
-- ========================================
DROP TABLE IF EXISTS `ec_product_spec`;
CREATE TABLE `ec_product_spec` (
`id` bigint unsigned NOT NULL AUTO_INCREMENT COMMENT '规格ID',
`company_id` bigint unsigned NOT NULL COMMENT '公司ID',
`product_id` bigint unsigned NOT NULL COMMENT '商品ID',
`name` varchar(200) NOT NULL COMMENT '规格名称',
`spec_code` varchar(100) DEFAULT NULL COMMENT '规格编码',
`product_cost` decimal(10,2) NOT NULL DEFAULT '0.00' COMMENT '商品成本',
`shipping_cost` decimal(10,2) NOT NULL DEFAULT '0.00' COMMENT '运费成本',
`other_cost` decimal(10,2) NOT NULL DEFAULT '0.00' COMMENT '其他成本',
`remark` varchar(500) DEFAULT NULL COMMENT '备注',
`create_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
`update_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
`create_by` bigint unsigned DEFAULT NULL COMMENT '创建人ID',
`update_by` bigint unsigned DEFAULT NULL COMMENT '更新人ID',
PRIMARY KEY (`id`),
KEY `idx_company_id` (`company_id`),
KEY `idx_product_id` (`product_id`),
KEY `idx_spec_code` (`spec_code`),
KEY `fk_ec_spec_creator` (`create_by`),
KEY `fk_ec_spec_updater` (`update_by`),
CONSTRAINT `fk_ec_spec_company` FOREIGN KEY (`company_id`) REFERENCES `org_company` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
CONSTRAINT `fk_ec_spec_creator` FOREIGN KEY (`create_by`) REFERENCES `sys_user` (`id`) ON DELETE SET NULL ON UPDATE CASCADE,
CONSTRAINT `fk_ec_spec_product` FOREIGN KEY (`product_id`) REFERENCES `ec_product` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
CONSTRAINT `fk_ec_spec_updater` FOREIGN KEY (`update_by`) REFERENCES `sys_user` (`id`) ON DELETE SET NULL ON UPDATE CASCADE
) ENGINE=InnoDB AUTO_INCREMENT=107 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='电商-规格表'
-- ========================================
-- EC_PROMOTION_FEE
-- ========================================
DROP TABLE IF EXISTS `ec_promotion_fee`;
CREATE TABLE `ec_promotion_fee` (
`id` bigint unsigned NOT NULL AUTO_INCREMENT COMMENT '推广费记录ID',
`company_id` bigint unsigned NOT NULL COMMENT '公司ID',
`shop_id` bigint unsigned NOT NULL COMMENT '店铺ID',
`fee_type_id` bigint unsigned NOT NULL COMMENT '推广费类型ID',
`fee_name` varchar(200) NOT NULL COMMENT '推广费名称',
`platform` varchar(50) DEFAULT NULL COMMENT '平台(淘宝、京东、拼多多等)',
`campaign_name` varchar(200) DEFAULT NULL COMMENT '推广活动名称',
`fee_amount` decimal(10,2) NOT NULL DEFAULT '0.00' COMMENT '推广费金额',
`base_amount` decimal(10,2) DEFAULT NULL COMMENT '基础金额(用于按比例计算)',
`fee_rate` decimal(5,4) DEFAULT NULL COMMENT '费率(用于按比例计算)',
`click_count` int DEFAULT NULL COMMENT '点击次数',
`impression_count` int DEFAULT NULL COMMENT '展示次数',
`conversion_count` int DEFAULT NULL COMMENT '转化次数',
`fee_date` date NOT NULL COMMENT '推广费发生日期',
`remark` varchar(500) DEFAULT NULL COMMENT '备注',
`create_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
`update_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
`create_by` bigint unsigned DEFAULT NULL COMMENT '创建人ID',
`update_by` bigint unsigned DEFAULT NULL COMMENT '更新人ID',
PRIMARY KEY (`id`),
KEY `idx_company_id` (`company_id`),
KEY `idx_shop_id` (`shop_id`),
KEY `idx_fee_type_id` (`fee_type_id`),
KEY `idx_fee_date` (`fee_date`),
KEY `idx_platform` (`platform`),
KEY `fk_ec_promotion_fee_creator` (`create_by`),
KEY `fk_ec_promotion_fee_updater` (`update_by`),
CONSTRAINT `fk_ec_promotion_fee_company` FOREIGN KEY (`company_id`) REFERENCES `org_company` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
CONSTRAINT `fk_ec_promotion_fee_creator` FOREIGN KEY (`create_by`) REFERENCES `sys_user` (`id`) ON DELETE SET NULL ON UPDATE CASCADE,
CONSTRAINT `fk_ec_promotion_fee_shop` FOREIGN KEY (`shop_id`) REFERENCES `ec_shop` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
CONSTRAINT `fk_ec_promotion_fee_type` FOREIGN KEY (`fee_type_id`) REFERENCES `ec_promotion_fee_type` (`id`) ON DELETE RESTRICT ON UPDATE CASCADE,
CONSTRAINT `fk_ec_promotion_fee_updater` FOREIGN KEY (`update_by`) REFERENCES `sys_user` (`id`) ON DELETE SET NULL ON UPDATE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='电商-推广费记录表'
-- ========================================
-- EC_PROMOTION_FEE_TYPE
-- ========================================
DROP TABLE IF EXISTS `ec_promotion_fee_type`;
CREATE TABLE `ec_promotion_fee_type` (
`id` bigint unsigned NOT NULL AUTO_INCREMENT COMMENT '推广费类型ID',
`company_id` bigint unsigned NOT NULL COMMENT '公司ID',
`type_name` varchar(100) NOT NULL COMMENT '类型名称',
`description` varchar(200) DEFAULT NULL COMMENT '类型描述',
`calculation_method` tinyint NOT NULL DEFAULT '1' COMMENT '计算方式 1固定金额 2按比例 3按点击 4按展示',
`sort_order` int NOT NULL DEFAULT '0' COMMENT '排序',
`is_active` tinyint NOT NULL DEFAULT '1' COMMENT '是否启用 0禁用 1启用',
`create_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
`update_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
`create_by` bigint unsigned DEFAULT NULL COMMENT '创建人ID',
`update_by` bigint unsigned DEFAULT NULL COMMENT '更新人ID',
PRIMARY KEY (`id`),
UNIQUE KEY `uk_company_type_name` (`company_id`,`type_name`),
KEY `idx_company_id` (`company_id`),
KEY `idx_sort_order` (`sort_order`),
KEY `idx_is_active` (`is_active`),
KEY `fk_ec_promotion_fee_type_creator` (`create_by`),
KEY `fk_ec_promotion_fee_type_updater` (`update_by`),
CONSTRAINT `fk_ec_promotion_fee_type_company` FOREIGN KEY (`company_id`) REFERENCES `org_company` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
CONSTRAINT `fk_ec_promotion_fee_type_creator` FOREIGN KEY (`create_by`) REFERENCES `sys_user` (`id`) ON DELETE SET NULL ON UPDATE CASCADE,
CONSTRAINT `fk_ec_promotion_fee_type_updater` FOREIGN KEY (`update_by`) REFERENCES `sys_user` (`id`) ON DELETE SET NULL ON UPDATE CASCADE
) ENGINE=InnoDB AUTO_INCREMENT=35 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='电商-推广费类型表'
-- ========================================
-- EC_SHOP
-- ========================================
DROP TABLE IF EXISTS `ec_shop`;
CREATE TABLE `ec_shop` (
`id` bigint unsigned NOT NULL AUTO_INCREMENT COMMENT '店铺ID',
`company_id` bigint unsigned NOT NULL COMMENT '所属公司ID',
`name` varchar(200) NOT NULL COMMENT '店铺名称',
`logo_image_id` bigint unsigned DEFAULT NULL COMMENT 'logo图片ID',
`platform` varchar(50) DEFAULT NULL COMMENT '平台(如淘宝、京东、拼多多)',
`create_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
`update_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
`create_by` bigint unsigned DEFAULT NULL COMMENT '创建人ID',
`update_by` bigint unsigned DEFAULT NULL COMMENT '更新人ID',
PRIMARY KEY (`id`),
KEY `idx_company_id` (`company_id`),
KEY `fk_ec_shop_logo_image` (`logo_image_id`),
KEY `fk_ec_shop_creator` (`create_by`),
KEY `fk_ec_shop_updater` (`update_by`),
CONSTRAINT `fk_ec_shop_company` FOREIGN KEY (`company_id`) REFERENCES `org_company` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
CONSTRAINT `fk_ec_shop_creator` FOREIGN KEY (`create_by`) REFERENCES `sys_user` (`id`) ON DELETE SET NULL ON UPDATE CASCADE,
CONSTRAINT `fk_ec_shop_logo_image` FOREIGN KEY (`logo_image_id`) REFERENCES `sys_file` (`id`) ON DELETE SET NULL ON UPDATE CASCADE,
CONSTRAINT `fk_ec_shop_updater` FOREIGN KEY (`update_by`) REFERENCES `sys_user` (`id`) ON DELETE SET NULL ON UPDATE CASCADE
) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='电商-店铺表'
-- ========================================
-- EC_SHOP_MONTHLY_TARGET
-- ========================================
DROP TABLE IF EXISTS `ec_shop_monthly_target`;
CREATE TABLE `ec_shop_monthly_target` (
`id` bigint unsigned NOT NULL AUTO_INCREMENT COMMENT '目标ID',
`company_id` bigint unsigned NOT NULL COMMENT '公司ID',
`shop_id` bigint unsigned NOT NULL COMMENT '店铺ID',
`target_month` date NOT NULL COMMENT '目标月份(格式:YYYY-MM-01)',
`target_amount` decimal(10,2) NOT NULL DEFAULT '0.00' COMMENT '目标销售额',
`target_order_count` int NOT NULL DEFAULT '0' COMMENT '目标订单数',
`remark` varchar(500) DEFAULT NULL COMMENT '备注',
`create_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
`update_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
`create_by` bigint unsigned DEFAULT NULL COMMENT '创建人ID',
`update_by` bigint unsigned DEFAULT NULL COMMENT '更新人ID',
PRIMARY KEY (`id`),
UNIQUE KEY `uk_shop_month` (`shop_id`,`target_month`),
KEY `idx_company_id` (`company_id`),
KEY `idx_shop_id` (`shop_id`),
KEY `idx_target_month` (`target_month`),
KEY `idx_company_shop_month` (`company_id`,`shop_id`,`target_month`),
KEY `fk_ec_shop_monthly_target_creator` (`create_by`),
KEY `fk_ec_shop_monthly_target_updater` (`update_by`),
CONSTRAINT `fk_ec_shop_monthly_target_company` FOREIGN KEY (`company_id`) REFERENCES `org_company` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
CONSTRAINT `fk_ec_shop_monthly_target_creator` FOREIGN KEY (`create_by`) REFERENCES `sys_user` (`id`) ON DELETE SET NULL ON UPDATE CASCADE,
CONSTRAINT `fk_ec_shop_monthly_target_shop` FOREIGN KEY (`shop_id`) REFERENCES `ec_shop` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
CONSTRAINT `fk_ec_shop_monthly_target_updater` FOREIGN KEY (`update_by`) REFERENCES `sys_user` (`id`) ON DELETE SET NULL ON UPDATE CASCADE
) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='电商-店铺月销量目标表'
-- ========================================
-- EC_SHOP_PRODUCT_RELATION
-- ========================================
DROP TABLE IF EXISTS `ec_shop_product_relation`;
CREATE TABLE `ec_shop_product_relation` (
`id` bigint unsigned NOT NULL AUTO_INCREMENT COMMENT '关联ID',
`company_id` bigint unsigned NOT NULL COMMENT '公司ID',
`shop_id` bigint unsigned NOT NULL COMMENT '店铺ID',
`product_id` bigint unsigned NOT NULL COMMENT '商品ID',
`sort_order` int NOT NULL DEFAULT '0' COMMENT '排序',
`create_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
`update_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
`create_by` bigint unsigned DEFAULT NULL COMMENT '创建人ID',
`update_by` bigint unsigned DEFAULT NULL COMMENT '更新人ID',
PRIMARY KEY (`id`),
UNIQUE KEY `uk_shop_product` (`shop_id`,`product_id`),
KEY `idx_company_id` (`company_id`),
KEY `idx_shop_id` (`shop_id`),
KEY `idx_product_id` (`product_id`),
KEY `idx_sort_order` (`sort_order`),
KEY `fk_ec_shop_product_creator` (`create_by`),
KEY `fk_ec_shop_product_updater` (`update_by`),
CONSTRAINT `fk_ec_shop_product_company` FOREIGN KEY (`company_id`) REFERENCES `org_company` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
CONSTRAINT `fk_ec_shop_product_creator` FOREIGN KEY (`create_by`) REFERENCES `sys_user` (`id`) ON DELETE SET NULL ON UPDATE CASCADE,
CONSTRAINT `fk_ec_shop_product_product` FOREIGN KEY (`product_id`) REFERENCES `ec_product` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
CONSTRAINT `fk_ec_shop_product_shop` FOREIGN KEY (`shop_id`) REFERENCES `ec_shop` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
CONSTRAINT `fk_ec_shop_product_updater` FOREIGN KEY (`update_by`) REFERENCES `sys_user` (`id`) ON DELETE SET NULL ON UPDATE CASCADE
) ENGINE=InnoDB AUTO_INCREMENT=129 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='电商-店铺商品关联表'