mirror of
https://gitee.com/qqtt-ah/ecom-dmb.git
synced 2026-11-24 17:09:19 +08:00
refactor: 调整拼多多模块位置
This commit is contained in:
@@ -0,0 +1,485 @@
|
||||
-- ========================================
|
||||
-- 电商数据中台数据库设计
|
||||
-- 生成时间:2026-03-29
|
||||
-- ========================================
|
||||
|
||||
-- ========================================
|
||||
-- 刷单记录表
|
||||
-- ========================================
|
||||
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 NULL DEFAULT NULL COMMENT '商品ID(可选)',
|
||||
`product_spec_id` bigint UNSIGNED NULL DEFAULT NULL COMMENT '商品规格ID(可选)',
|
||||
`brush_amount` decimal(10, 2) NOT NULL DEFAULT 0.00 COMMENT '刷单金额',
|
||||
`brush_time` timestamp NOT NULL COMMENT '刷单时间',
|
||||
`quantity` int NULL DEFAULT 1 COMMENT '刷单数量',
|
||||
`remark` varchar(500) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL 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 NULL DEFAULT NULL COMMENT '创建人ID',
|
||||
`update_by` bigint UNSIGNED NULL DEFAULT NULL COMMENT '更新人ID',
|
||||
PRIMARY KEY (`id`) USING BTREE,
|
||||
INDEX `idx_company_id`(`company_id` ASC) USING BTREE,
|
||||
INDEX `idx_shop_id`(`shop_id` ASC) USING BTREE,
|
||||
INDEX `idx_product_id`(`product_id` ASC) USING BTREE,
|
||||
INDEX `idx_product_spec_id`(`product_spec_id` ASC) USING BTREE,
|
||||
INDEX `idx_brush_time`(`brush_time` ASC) USING BTREE,
|
||||
INDEX `idx_company_shop_time`(`company_id` ASC, `shop_id` ASC, `brush_time` ASC) USING BTREE,
|
||||
INDEX `fk_ec_brush_order_creator`(`create_by` ASC) USING BTREE,
|
||||
INDEX `fk_ec_brush_order_updater`(`update_by` ASC) USING BTREE,
|
||||
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 CHARACTER SET = utf8mb4 COLLATE = utf8mb4_0900_ai_ci COMMENT = '电商-刷单记录表' ROW_FORMAT = Dynamic;
|
||||
|
||||
-- ----------------------------
|
||||
-- 导入字段定义表
|
||||
-- ----------------------------
|
||||
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') CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL COMMENT '导入类型(product-商品 order-订单)',
|
||||
`field_name` varchar(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL COMMENT '数据库字段名,如 name',
|
||||
`field_label` varchar(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL COMMENT '中文字段名,如 商品名称',
|
||||
`file_field_name` varchar(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT '文件字段名,如 商品名称',
|
||||
`required` tinyint(1) NULL DEFAULT 0 COMMENT '是否必填',
|
||||
`sort` int UNSIGNED NULL DEFAULT 0 COMMENT '排序',
|
||||
`data_type` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL 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`) USING BTREE,
|
||||
UNIQUE INDEX `uniq_type_field`(`type` ASC, `field_name` ASC) USING BTREE
|
||||
) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_0900_ai_ci COMMENT = '电商-导入字段定义表' ;
|
||||
|
||||
-- ----------------------------
|
||||
-- 导入映射表
|
||||
-- ----------------------------
|
||||
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', 'PROMOTION_FEE') CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL COMMENT '导入类型(PRODUCT-商品 ORDER-订单 ORDER_STATUS-订单状态 PROMOTION_FEE-推广费)',
|
||||
`name` varchar(20) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci 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 NULL DEFAULT NULL COMMENT '创建人ID',
|
||||
`update_by` bigint UNSIGNED NULL DEFAULT NULL COMMENT '更新人ID',
|
||||
PRIMARY KEY (`id`) USING BTREE,
|
||||
UNIQUE INDEX `uniq_company_type_name`(`company_id` ASC, `type` ASC, `name` ASC) USING BTREE,
|
||||
INDEX `fk_import_mapping_creator`(`create_by` ASC) USING BTREE,
|
||||
INDEX `fk_import_mapping_updater`(`update_by` ASC) USING BTREE,
|
||||
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 CHARACTER SET = utf8mb4 COLLATE = utf8mb4_0900_ai_ci COMMENT = '电商-导入映射表' ;
|
||||
|
||||
-- ----------------------------
|
||||
-- 导入任务表
|
||||
-- ----------------------------
|
||||
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 NULL DEFAULT NULL COMMENT '所属店铺ID',
|
||||
`type` enum('product','order', 'promotion_record') CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL COMMENT '导入类型(product-商品 order-订单 promotion_record-推广记录)',
|
||||
`task_name` varchar(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT '任务名称',
|
||||
`file_name` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL COMMENT '原始文件名',
|
||||
`file_id` bigint UNSIGNED NULL DEFAULT NULL COMMENT '关联文件ID',
|
||||
`status` enum('pending','processing','success','failed') CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL DEFAULT 'pending' COMMENT '任务状态(pending-待处理 processing-处理中 success-成功 failed-失败)',
|
||||
`total_count` int UNSIGNED NULL DEFAULT 0 COMMENT '总行数',
|
||||
`success_count` int UNSIGNED NULL DEFAULT 0 COMMENT '成功行数',
|
||||
`fail_count` int UNSIGNED NULL DEFAULT 0 COMMENT '失败行数',
|
||||
`mapping` json NULL COMMENT '字段映射记录',
|
||||
`message` text CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL COMMENT '错误信息或备注',
|
||||
`started_at` datetime NULL DEFAULT NULL COMMENT '开始处理时间',
|
||||
`last_heartbeat_at` datetime NULL DEFAULT NULL COMMENT '最后心跳时间',
|
||||
`worker_id` varchar(128) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT '处理实例标识',
|
||||
`redis_stream_key` varchar(128) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT '入队 Stream Key',
|
||||
`redis_message_id` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT 'Redis Stream 消息ID',
|
||||
`enqueue_status` enum('pending_enqueue','enqueued','enqueue_failed') CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL DEFAULT 'pending_enqueue' 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 NULL DEFAULT NULL COMMENT '创建人ID',
|
||||
`update_by` bigint UNSIGNED NULL DEFAULT NULL COMMENT '更新人ID',
|
||||
PRIMARY KEY (`id`) USING BTREE,
|
||||
INDEX `idx_company_id`(`company_id` ASC) USING BTREE,
|
||||
INDEX `idx_create_by`(`create_by` ASC) USING BTREE,
|
||||
INDEX `idx_update_by`(`update_by` ASC) USING BTREE,
|
||||
INDEX `idx_file_id`(`file_id` ASC) USING BTREE,
|
||||
INDEX `idx_import_task_dispatch`(`status` ASC, `type` ASC, `id` ASC) USING BTREE,
|
||||
INDEX `idx_import_task_recover`(`status` ASC, `last_heartbeat_at` ASC) USING BTREE,
|
||||
INDEX `idx_import_task_enqueue`(`enqueue_status` ASC, `status` ASC) USING BTREE,
|
||||
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 CHARACTER SET = utf8mb4 COLLATE = utf8mb4_0900_ai_ci COMMENT = '电商-导入任务表' ;
|
||||
|
||||
-- ----------------------------
|
||||
-- 订单表
|
||||
-- ----------------------------
|
||||
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_spec_id` bigint UNSIGNED NULL DEFAULT NULL COMMENT '商品规格ID',
|
||||
`spec_code` varchar(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT '规格编码(冗余,便于查询)',
|
||||
`status_id` bigint UNSIGNED NOT NULL COMMENT '订单状态ID',
|
||||
`platform_order_no` varchar(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT '平台订单号',
|
||||
`link_product_name` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL COMMENT '链接商品名称',
|
||||
`link_spec_name` varchar(200) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL 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) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT '备注',
|
||||
`import_task_id` bigint UNSIGNED NULL 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 NULL DEFAULT NULL COMMENT '创建人ID',
|
||||
`update_by` bigint UNSIGNED NULL DEFAULT NULL COMMENT '更新人ID',
|
||||
PRIMARY KEY (`id`) USING BTREE,
|
||||
INDEX `idx_company_shop_time`(`company_id` ASC, `shop_id` ASC, `order_time` ASC) USING BTREE,
|
||||
INDEX `idx_company_order_time`(`company_id` ASC, `order_time` ASC) USING BTREE COMMENT '覆盖概览/工作台按公司+时间范围查询',
|
||||
INDEX `idx_company_order_time_status`(`company_id` ASC, `order_time` ASC, `status_id` ASC) USING BTREE COMMENT '覆盖概览/工作台按公司+时间范围+状态查询',
|
||||
INDEX `idx_status_id`(`status_id` ASC) USING BTREE,
|
||||
INDEX `idx_platform_order_no`(`platform_order_no` ASC) USING BTREE,
|
||||
INDEX `idx_product_spec_id`(`product_spec_id` ASC) USING BTREE,
|
||||
INDEX `idx_spec_code`(`spec_code` ASC) USING BTREE,
|
||||
INDEX `idx_import_task_id`(`import_task_id` ASC) USING BTREE,
|
||||
INDEX `idx_confirm`(`confirm` ASC) USING BTREE,
|
||||
INDEX `fk_ec_order_creator`(`create_by` ASC) USING BTREE,
|
||||
INDEX `fk_ec_order_updater`(`update_by` ASC) USING BTREE,
|
||||
INDEX `fk_ec_order_shop`(`shop_id` ASC) USING BTREE,
|
||||
UNIQUE INDEX `uk_company_platform`(`company_id` ASC, `platform_order_no` ASC) USING BTREE,
|
||||
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_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 CHARACTER SET = utf8mb4 COLLATE = utf8mb4_0900_ai_ci COMMENT = '电商-订单表(含商品明细)' ;
|
||||
|
||||
-- ----------------------------
|
||||
-- 订单状态表
|
||||
-- 说明:各统计维度独立开关(0否 1是),替代原 auto_statistics / is_refund。
|
||||
-- 概览、导出等按维度筛选订单状态时分别读取对应字段;任一为 1 的状态会进入「待拉取订单」并集。
|
||||
-- ----------------------------
|
||||
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) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL COMMENT '状态名称(中文)',
|
||||
`description` varchar(200) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT '状态描述',
|
||||
`color` varchar(20) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT '状态颜色(十六进制)',
|
||||
`sort_order` int NOT NULL DEFAULT 0 COMMENT '排序',
|
||||
`include_sales_amount` tinyint NOT NULL DEFAULT 0 COMMENT '是否计入销售额/单量等统计 0否 1是',
|
||||
`include_product_cost` tinyint NOT NULL DEFAULT 0 COMMENT '是否计入商品成本统计 0否 1是',
|
||||
`include_freight_cost` tinyint NOT NULL DEFAULT 0 COMMENT '是否计入运费成本统计 0否 1是',
|
||||
`include_other_cost` tinyint NOT NULL DEFAULT 0 COMMENT '是否计入其他成本统计 0否 1是',
|
||||
`include_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 NULL DEFAULT NULL COMMENT '创建人ID',
|
||||
`update_by` bigint UNSIGNED NULL DEFAULT NULL COMMENT '更新人ID',
|
||||
PRIMARY KEY (`id`) USING BTREE,
|
||||
UNIQUE INDEX `uk_company_status_name`(`company_id` ASC, `status_name` ASC) USING BTREE,
|
||||
INDEX `idx_company_id`(`company_id` ASC) USING BTREE,
|
||||
INDEX `idx_sort_order`(`sort_order` ASC) USING BTREE,
|
||||
INDEX `fk_ec_order_status_creator`(`create_by` ASC) USING BTREE,
|
||||
INDEX `fk_ec_order_status_updater`(`update_by` ASC) USING BTREE,
|
||||
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 CHARACTER SET = utf8mb4 COLLATE = utf8mb4_0900_ai_ci COMMENT = '电商-订单状态表' ;
|
||||
|
||||
-- ----------------------------
|
||||
-- 商品类目表
|
||||
-- ----------------------------
|
||||
DROP TABLE IF EXISTS `ec_category`;
|
||||
CREATE TABLE `ec_category` (
|
||||
`id` bigint UNSIGNED NOT NULL AUTO_INCREMENT COMMENT '类目ID',
|
||||
`company_id` bigint UNSIGNED NOT NULL COMMENT '公司ID',
|
||||
`parent_id` bigint UNSIGNED NULL DEFAULT NULL COMMENT '父级类目ID',
|
||||
`name` varchar(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL COMMENT '类目名称',
|
||||
`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 NULL DEFAULT NULL COMMENT '创建人ID',
|
||||
`update_by` bigint UNSIGNED NULL DEFAULT NULL COMMENT '更新人ID',
|
||||
PRIMARY KEY (`id`) USING BTREE,
|
||||
INDEX `idx_company_id`(`company_id` ASC) USING BTREE,
|
||||
INDEX `idx_parent_id`(`parent_id` ASC) USING BTREE,
|
||||
INDEX `idx_sort_order`(`sort_order` ASC) USING BTREE,
|
||||
INDEX `fk_ec_category_creator`(`create_by` ASC) USING BTREE,
|
||||
INDEX `fk_ec_category_updater`(`update_by` ASC) USING BTREE,
|
||||
CONSTRAINT `fk_ec_category_company` FOREIGN KEY (`company_id`) REFERENCES `org_company` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
|
||||
CONSTRAINT `fk_ec_category_creator` FOREIGN KEY (`create_by`) REFERENCES `sys_user` (`id`) ON DELETE SET NULL ON UPDATE CASCADE,
|
||||
CONSTRAINT `fk_ec_category_parent` FOREIGN KEY (`parent_id`) REFERENCES `ec_category` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
|
||||
CONSTRAINT `fk_ec_category_updater` FOREIGN KEY (`update_by`) REFERENCES `sys_user` (`id`) ON DELETE SET NULL ON UPDATE CASCADE
|
||||
) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_0900_ai_ci COMMENT = '电商-商品类目表' ;
|
||||
|
||||
-- ----------------------------
|
||||
-- 商品表
|
||||
-- ----------------------------
|
||||
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',
|
||||
`category_id` bigint UNSIGNED NULL DEFAULT NULL COMMENT '类目ID',
|
||||
`name` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL COMMENT '商品名称',
|
||||
`product_code` varchar(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL DEFAULT '' COMMENT '商品编码',
|
||||
`main_image_id` bigint UNSIGNED NULL 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 NULL DEFAULT NULL COMMENT '创建人ID',
|
||||
`update_by` bigint UNSIGNED NULL DEFAULT NULL COMMENT '更新人ID',
|
||||
PRIMARY KEY (`id`) USING BTREE,
|
||||
UNIQUE INDEX `uk_company_code_name`(`company_id` ASC, `product_code` ASC, `name` ASC) USING BTREE,
|
||||
INDEX `idx_company_id`(`company_id` ASC) USING BTREE,
|
||||
INDEX `idx_category_id`(`category_id` ASC) USING BTREE,
|
||||
INDEX `fk_ec_product_main_image`(`main_image_id` ASC) USING BTREE,
|
||||
INDEX `fk_ec_product_creator`(`create_by` ASC) USING BTREE,
|
||||
INDEX `fk_ec_product_updater`(`update_by` ASC) USING BTREE,
|
||||
CONSTRAINT `fk_ec_product_category` FOREIGN KEY (`category_id`) REFERENCES `ec_category` (`id`) ON DELETE SET NULL ON UPDATE CASCADE,
|
||||
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 CHARACTER SET = utf8mb4 COLLATE = utf8mb4_0900_ai_ci COMMENT = '电商-商品表(含成本价)' ;
|
||||
|
||||
-- ----------------------------
|
||||
-- 商品规格表
|
||||
-- ----------------------------
|
||||
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) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL COMMENT '规格名称',
|
||||
`spec_code` varchar(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT 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) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL 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 NULL DEFAULT NULL COMMENT '创建人ID',
|
||||
`update_by` bigint UNSIGNED NULL DEFAULT NULL COMMENT '更新人ID',
|
||||
PRIMARY KEY (`id`) USING BTREE,
|
||||
INDEX `idx_company_id`(`company_id` ASC) USING BTREE,
|
||||
INDEX `idx_product_id`(`product_id` ASC) USING BTREE,
|
||||
UNIQUE INDEX `uk_company_spec_code`(`company_id` ASC, `spec_code` ASC) USING BTREE,
|
||||
INDEX `fk_ec_spec_creator`(`create_by` ASC) USING BTREE,
|
||||
INDEX `fk_ec_spec_updater`(`update_by` ASC) USING BTREE,
|
||||
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 CHARACTER SET = utf8mb4 COLLATE = utf8mb4_0900_ai_ci COMMENT = '电商-规格表' ;
|
||||
|
||||
-- ----------------------------
|
||||
-- 推广费记录表
|
||||
-- ----------------------------
|
||||
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',
|
||||
`category_id` bigint UNSIGNED NULL DEFAULT NULL COMMENT '类目ID(可选,无商品时可用于类目级推广费)',
|
||||
`product_id` bigint UNSIGNED NULL DEFAULT NULL COMMENT '商品ID(可选)',
|
||||
`fee_type_id` bigint UNSIGNED NOT NULL COMMENT '推广费类型ID',
|
||||
`campaign_name` varchar(200) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT '推广活动名称',
|
||||
`fee_amount` decimal(10, 2) NOT NULL DEFAULT 0.00 COMMENT '推广费金额',
|
||||
`fee_date` date NOT NULL COMMENT '推广费发生日期',
|
||||
`remark` varchar(500) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL 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 NULL DEFAULT NULL COMMENT '创建人ID',
|
||||
`update_by` bigint UNSIGNED NULL DEFAULT NULL COMMENT '更新人ID',
|
||||
PRIMARY KEY (`id`) USING BTREE,
|
||||
INDEX `idx_company_id`(`company_id` ASC) USING BTREE,
|
||||
INDEX `idx_shop_id`(`shop_id` ASC) USING BTREE,
|
||||
INDEX `idx_category_id`(`category_id` ASC) USING BTREE,
|
||||
INDEX `idx_product_id`(`product_id` ASC) USING BTREE,
|
||||
INDEX `idx_fee_type_id`(`fee_type_id` ASC) USING BTREE,
|
||||
INDEX `idx_fee_date`(`fee_date` ASC) USING BTREE,
|
||||
INDEX `fk_ec_promotion_fee_creator`(`create_by` ASC) USING BTREE,
|
||||
INDEX `fk_ec_promotion_fee_updater`(`update_by` ASC) USING BTREE,
|
||||
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_category` FOREIGN KEY (`category_id`) REFERENCES `ec_category` (`id`) ON DELETE SET NULL ON UPDATE CASCADE,
|
||||
CONSTRAINT `fk_ec_promotion_fee_product` FOREIGN KEY (`product_id`) REFERENCES `ec_product` (`id`) ON DELETE SET NULL 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 CHARACTER SET = utf8mb4 COLLATE = utf8mb4_0900_ai_ci COMMENT = '电商-推广费记录表' ;
|
||||
|
||||
-- ----------------------------
|
||||
-- 推广费类型表
|
||||
-- ----------------------------
|
||||
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) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL COMMENT '类型名称',
|
||||
`description` varchar(200) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL 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 NULL DEFAULT NULL COMMENT '创建人ID',
|
||||
`update_by` bigint UNSIGNED NULL DEFAULT NULL COMMENT '更新人ID',
|
||||
PRIMARY KEY (`id`) USING BTREE,
|
||||
UNIQUE INDEX `uk_company_type_name`(`company_id` ASC, `type_name` ASC) USING BTREE,
|
||||
INDEX `idx_company_id`(`company_id` ASC) USING BTREE,
|
||||
INDEX `idx_sort_order`(`sort_order` ASC) USING BTREE,
|
||||
INDEX `idx_is_active`(`is_active` ASC) USING BTREE,
|
||||
INDEX `fk_ec_promotion_fee_type_creator`(`create_by` ASC) USING BTREE,
|
||||
INDEX `fk_ec_promotion_fee_type_updater`(`update_by` ASC) USING BTREE,
|
||||
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 CHARACTER SET = utf8mb4 COLLATE = utf8mb4_0900_ai_ci COMMENT = '电商-推广费类型表' ;
|
||||
|
||||
-- ----------------------------
|
||||
-- 平台表
|
||||
-- ----------------------------
|
||||
DROP TABLE IF EXISTS `ec_platform`;
|
||||
CREATE TABLE `ec_platform` (
|
||||
`id` bigint UNSIGNED NOT NULL AUTO_INCREMENT COMMENT '平台ID',
|
||||
`company_id` bigint UNSIGNED NOT NULL COMMENT '所属公司ID',
|
||||
`platform_name` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL COMMENT '平台名称(如淘宝、京东、拼多多、抖音)',
|
||||
`platform_code` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL COMMENT '平台代码(如 taobao、jd、pdd、douyin)',
|
||||
`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 NULL DEFAULT NULL COMMENT '创建人ID',
|
||||
`update_by` bigint UNSIGNED NULL DEFAULT NULL COMMENT '更新人ID',
|
||||
PRIMARY KEY (`id`) USING BTREE,
|
||||
INDEX `idx_company_id`(`company_id` ASC) USING BTREE,
|
||||
INDEX `idx_sort_order`(`sort_order` ASC) USING BTREE,
|
||||
INDEX `idx_is_active`(`is_active` ASC) USING BTREE,
|
||||
INDEX `fk_ec_platform_company`(`company_id` ASC) USING BTREE,
|
||||
INDEX `fk_ec_platform_creator`(`create_by` ASC) USING BTREE,
|
||||
INDEX `fk_ec_platform_updater`(`update_by` ASC) USING BTREE,
|
||||
CONSTRAINT `fk_ec_platform_company` FOREIGN KEY (`company_id`) REFERENCES `org_company` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
|
||||
CONSTRAINT `fk_ec_platform_creator` FOREIGN KEY (`create_by`) REFERENCES `sys_user` (`id`) ON DELETE SET NULL ON UPDATE CASCADE,
|
||||
CONSTRAINT `fk_ec_platform_updater` FOREIGN KEY (`update_by`) REFERENCES `sys_user` (`id`) ON DELETE SET NULL ON UPDATE CASCADE
|
||||
) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_0900_ai_ci COMMENT = '电商-平台表' ;
|
||||
|
||||
-- ----------------------------
|
||||
-- 平台数据初始化
|
||||
-- ----------------------------
|
||||
INSERT INTO `ec_platform` (`platform_name`, `platform_code`, `sort_order`, `is_active`) VALUES
|
||||
('淘宝', 'taobao', 1, 1),
|
||||
('京东', 'jd', 2, 1),
|
||||
('拼多多', 'pdd', 3, 1),
|
||||
('抖音', 'douyin', 4, 1),
|
||||
('快手', 'kuaishou', 5, 1),
|
||||
('小红书', 'xiaohongshu', 6, 1),
|
||||
('天猫', 'tmall', 7, 1),
|
||||
('唯品会', 'vip', 8, 1),
|
||||
('苏宁', 'suning', 9, 1),
|
||||
('1688', '1688', 10, 1);
|
||||
|
||||
-- ----------------------------
|
||||
-- 店铺表
|
||||
-- ----------------------------
|
||||
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) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL COMMENT '店铺名称',
|
||||
`logo_image_id` bigint UNSIGNED NULL DEFAULT NULL COMMENT 'logo图片ID',
|
||||
`platform_id` bigint UNSIGNED NULL 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 NULL DEFAULT NULL COMMENT '创建人ID',
|
||||
`update_by` bigint UNSIGNED NULL DEFAULT NULL COMMENT '更新人ID',
|
||||
PRIMARY KEY (`id`) USING BTREE,
|
||||
INDEX `idx_company_id`(`company_id` ASC) USING BTREE,
|
||||
INDEX `idx_platform_id`(`platform_id` ASC) USING BTREE,
|
||||
INDEX `fk_ec_shop_logo_image`(`logo_image_id` ASC) USING BTREE,
|
||||
INDEX `fk_ec_shop_creator`(`create_by` ASC) USING BTREE,
|
||||
INDEX `fk_ec_shop_updater`(`update_by` ASC) USING BTREE,
|
||||
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_platform` FOREIGN KEY (`platform_id`) REFERENCES `ec_platform` (`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 CHARACTER SET = utf8mb4 COLLATE = utf8mb4_0900_ai_ci COMMENT = '电商-店铺表' ;
|
||||
|
||||
-- ----------------------------
|
||||
-- 店铺月销量目标表
|
||||
-- ----------------------------
|
||||
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) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL 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 NULL DEFAULT NULL COMMENT '创建人ID',
|
||||
`update_by` bigint UNSIGNED NULL DEFAULT NULL COMMENT '更新人ID',
|
||||
PRIMARY KEY (`id`) USING BTREE,
|
||||
UNIQUE INDEX `uk_shop_month`(`shop_id` ASC, `target_month` ASC) USING BTREE,
|
||||
INDEX `idx_company_id`(`company_id` ASC) USING BTREE,
|
||||
INDEX `idx_shop_id`(`shop_id` ASC) USING BTREE,
|
||||
INDEX `idx_target_month`(`target_month` ASC) USING BTREE,
|
||||
INDEX `idx_company_shop_month`(`company_id` ASC, `shop_id` ASC, `target_month` ASC) USING BTREE,
|
||||
INDEX `fk_ec_shop_monthly_target_creator`(`create_by` ASC) USING BTREE,
|
||||
INDEX `fk_ec_shop_monthly_target_updater`(`update_by` ASC) USING BTREE,
|
||||
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 CHARACTER SET = utf8mb4 COLLATE = utf8mb4_0900_ai_ci COMMENT = '电商-店铺月销量目标表' ;
|
||||
|
||||
-- ----------------------------
|
||||
-- 店铺商品关联表
|
||||
-- ----------------------------
|
||||
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 NULL DEFAULT NULL COMMENT '创建人ID',
|
||||
`update_by` bigint UNSIGNED NULL DEFAULT NULL COMMENT '更新人ID',
|
||||
PRIMARY KEY (`id`) USING BTREE,
|
||||
UNIQUE INDEX `uk_shop_product`(`shop_id` ASC, `product_id` ASC) USING BTREE,
|
||||
INDEX `idx_company_id`(`company_id` ASC) USING BTREE,
|
||||
INDEX `idx_shop_id`(`shop_id` ASC) USING BTREE,
|
||||
INDEX `idx_product_id`(`product_id` ASC) USING BTREE,
|
||||
INDEX `idx_sort_order`(`sort_order` ASC) USING BTREE,
|
||||
INDEX `fk_ec_shop_product_creator`(`create_by` ASC) USING BTREE,
|
||||
INDEX `fk_ec_shop_product_updater`(`update_by` ASC) USING BTREE,
|
||||
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 CHARACTER SET = utf8mb4 COLLATE = utf8mb4_0900_ai_ci COMMENT = '电商-店铺商品关联表' ;
|
||||
@@ -0,0 +1,564 @@
|
||||
-- =============================================================================
|
||||
-- 订单统计读模型:日 / 月 / 年 聚合表设计
|
||||
-- =============================================================================
|
||||
-- 目标:支撑 1 天~5 年(1825 天)区间查询与导出,避免在线扫 ec_order 明细。
|
||||
-- 口径:与 OrderStatusStatSets + OrderStatAggMapper 一致(成本/退款五维度 + KPI 双三角)。
|
||||
-- 写入:ec_order 变更 / 导入完成后,按 (company, shop, stat_date) 重算日表,再 rollup 月/年。
|
||||
-- 详细方案见:docs/订单统计读模型方案.md
|
||||
--
|
||||
-- 【读路径路由建议】
|
||||
-- ≤ 90 天 → 日表(趋势、KPI、四维汇总)
|
||||
-- 91~1095 天 → 店铺/平台 KPI、趋势按月:月表;商品/品类明细:月表
|
||||
-- > 3 年 或整年对比 → 年表(KPI/平台);商品 TopN 仍走月表
|
||||
-- 推广费/刷单 → ec_promotion_fee_stat_* / ec_brush_fee_stat_*(小表,与日表同策略)
|
||||
--
|
||||
-- 【容量估算 · 单公司 · 50 店 · 5000 SKU · 日 10 万单】
|
||||
-- daily_shop 50 × 1825 ≈ 9.1 万行/5年
|
||||
-- daily_product 活跃维度 × 1825(全量 SKU 约数百万,按店×品×日)
|
||||
-- monthly_shop 50 × 60 ≈ 3 千行/5年
|
||||
-- yearly_shop 50 × 5 ≈ 250 行/5年
|
||||
-- 5 年全店 KPI 读 yearly_shop:1 条 SUM,毫秒级
|
||||
-- =============================================================================
|
||||
|
||||
|
||||
-- -----------------------------------------------------------------------------
|
||||
-- 一、公共指标列说明(日 / 月 / 年 同维度表字段一致,仅时间键 stat_date/stat_month/stat_year 不同)
|
||||
-- -----------------------------------------------------------------------------
|
||||
-- 【KPI · 实际销售口径】salesStatusIds(订单状态 includeSalesAmount=1)
|
||||
-- sales_amount 实际销售额:SUM(received_amount)
|
||||
-- sales_order_count 实际销售单量:符合条件的订单笔数
|
||||
-- sales_quantity_sum 实际销量件数:SUM(qty),qty=IFNULL(NULLIF(quantity,0),1)
|
||||
--
|
||||
-- 【KPI · GMV 口径】全订单状态(不按 status_id 过滤)
|
||||
-- gmv_amount 总 GMV:SUM(received_amount)
|
||||
-- gmv_order_count GMV 单量:COUNT(*) 订单笔数
|
||||
-- gmv_quantity_sum GMV 销量件数:SUM(qty) 全状态
|
||||
--
|
||||
-- 【利润相关】仍按 OrderStatusStatSets 分维度
|
||||
-- refund_amount 计入退款的 received_amount(refundStatusIds)
|
||||
-- product_cost 商品成本 × qty(productCostStatusIds)
|
||||
-- freight_cost 运费成本 × qty(freightCostStatusIds)
|
||||
-- other_cost 其他成本 × qty(otherCostStatusIds)
|
||||
--
|
||||
-- 【各层落表范围】
|
||||
-- 店铺 shop :KPI 双三角(6 列)+ 利润相关 → 工作台 KPI / 趋势主读
|
||||
-- 商品 product:KPI 双三角(6 列)+ 利润相关 → 多维排行 / 品类商品表
|
||||
-- 规格 spec :KPI 双三角(6 列)+ 利润相关 → 商品概览 spec 块
|
||||
--
|
||||
-- stat_version 重算批次号,状态配置 rebuild 时递增
|
||||
-- 存量库升级见:migration/V20260607__ec_order_stat_kpi_quantity_columns.sql
|
||||
-- -----------------------------------------------------------------------------
|
||||
|
||||
|
||||
-- =============================================================================
|
||||
-- 二、店铺维度(KPI / 趋势 / 店铺表 / 平台 rollup 主读表)
|
||||
-- =============================================================================
|
||||
|
||||
DROP TABLE IF EXISTS `ec_order_stat_daily_shop`;
|
||||
CREATE TABLE `ec_order_stat_daily_shop` (
|
||||
`id` bigint UNSIGNED NOT NULL AUTO_INCREMENT COMMENT '主键',
|
||||
`company_id` bigint UNSIGNED NOT NULL COMMENT '公司ID',
|
||||
`shop_id` bigint UNSIGNED NOT NULL COMMENT '店铺ID',
|
||||
`platform_id` bigint UNSIGNED NULL DEFAULT NULL COMMENT '平台ID(写入时快照 ec_shop.platform_id)',
|
||||
`stat_date` date NOT NULL COMMENT '自然日(Asia/Shanghai,与 order_time 的 DATE 一致)',
|
||||
|
||||
`sales_amount` decimal(16, 2) NOT NULL DEFAULT 0.00 COMMENT '实际销售额',
|
||||
`sales_order_count` int NOT NULL DEFAULT 0 COMMENT '实际销售单量',
|
||||
`sales_quantity_sum` int NOT NULL DEFAULT 0 COMMENT '实际销量件数',
|
||||
`gmv_amount` decimal(16, 2) NOT NULL DEFAULT 0.00 COMMENT '总GMV(全状态商家实收)',
|
||||
`gmv_order_count` int NOT NULL DEFAULT 0 COMMENT 'GMV单量',
|
||||
`gmv_quantity_sum` int NOT NULL DEFAULT 0 COMMENT 'GMV销量件数',
|
||||
`refund_amount` decimal(16, 2) NOT NULL DEFAULT 0.00 COMMENT '退款金额',
|
||||
`product_cost` decimal(16, 2) NOT NULL DEFAULT 0.00 COMMENT '商品成本',
|
||||
`freight_cost` decimal(16, 2) NOT NULL DEFAULT 0.00 COMMENT '运费成本',
|
||||
`other_cost` decimal(16, 2) NOT NULL DEFAULT 0.00 COMMENT '其他成本',
|
||||
|
||||
`stat_version` 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 '更新时间',
|
||||
|
||||
PRIMARY KEY (`id`) USING BTREE,
|
||||
UNIQUE KEY `uk_company_shop_date` (`company_id`, `shop_id`, `stat_date`) USING BTREE,
|
||||
INDEX `idx_company_date` (`company_id`, `stat_date`) USING BTREE,
|
||||
INDEX `idx_company_platform_date` (`company_id`, `platform_id`, `stat_date`) USING BTREE,
|
||||
INDEX `idx_shop_date` (`shop_id`, `stat_date`) USING BTREE,
|
||||
CONSTRAINT `fk_oss_daily_shop_company` FOREIGN KEY (`company_id`) REFERENCES `org_company` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
|
||||
CONSTRAINT `fk_oss_daily_shop_shop` FOREIGN KEY (`shop_id`) REFERENCES `ec_shop` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
|
||||
) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_0900_ai_ci COMMENT = '订单统计-店铺-日汇总';
|
||||
|
||||
|
||||
DROP TABLE IF EXISTS `ec_order_stat_monthly_shop`;
|
||||
CREATE TABLE `ec_order_stat_monthly_shop` (
|
||||
`id` bigint UNSIGNED NOT NULL AUTO_INCREMENT COMMENT '主键',
|
||||
`company_id` bigint UNSIGNED NOT NULL COMMENT '公司ID',
|
||||
`shop_id` bigint UNSIGNED NOT NULL COMMENT '店铺ID',
|
||||
`platform_id` bigint UNSIGNED NULL DEFAULT NULL COMMENT '平台ID(月 rollup 时取当月最后写入快照)',
|
||||
`stat_month` date NOT NULL COMMENT '自然月首日,如 2024-03-01',
|
||||
|
||||
`sales_amount` decimal(16, 2) NOT NULL DEFAULT 0.00 COMMENT '实际销售额',
|
||||
`sales_order_count` int NOT NULL DEFAULT 0 COMMENT '实际销售单量',
|
||||
`sales_quantity_sum` int NOT NULL DEFAULT 0 COMMENT '实际销量件数',
|
||||
`gmv_amount` decimal(16, 2) NOT NULL DEFAULT 0.00 COMMENT '总GMV',
|
||||
`gmv_order_count` int NOT NULL DEFAULT 0 COMMENT 'GMV单量',
|
||||
`gmv_quantity_sum` int NOT NULL DEFAULT 0 COMMENT 'GMV销量件数',
|
||||
`refund_amount` decimal(16, 2) NOT NULL DEFAULT 0.00 COMMENT '退款金额',
|
||||
`product_cost` decimal(16, 2) NOT NULL DEFAULT 0.00 COMMENT '商品成本',
|
||||
`freight_cost` decimal(16, 2) NOT NULL DEFAULT 0.00 COMMENT '运费成本',
|
||||
`other_cost` decimal(16, 2) NOT NULL DEFAULT 0.00 COMMENT '其他成本',
|
||||
|
||||
`stat_version` 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 '更新时间',
|
||||
|
||||
PRIMARY KEY (`id`) USING BTREE,
|
||||
UNIQUE KEY `uk_company_shop_month` (`company_id`, `shop_id`, `stat_month`) USING BTREE,
|
||||
INDEX `idx_company_month` (`company_id`, `stat_month`) USING BTREE,
|
||||
INDEX `idx_company_platform_month` (`company_id`, `platform_id`, `stat_month`) USING BTREE,
|
||||
CONSTRAINT `fk_oss_monthly_shop_company` FOREIGN KEY (`company_id`) REFERENCES `org_company` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
|
||||
CONSTRAINT `fk_oss_monthly_shop_shop` FOREIGN KEY (`shop_id`) REFERENCES `ec_shop` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
|
||||
) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_0900_ai_ci COMMENT = '订单统计-店铺-月汇总(由日表 SUM 或订单直算)';
|
||||
|
||||
|
||||
DROP TABLE IF EXISTS `ec_order_stat_yearly_shop`;
|
||||
CREATE TABLE `ec_order_stat_yearly_shop` (
|
||||
`id` bigint UNSIGNED NOT NULL AUTO_INCREMENT COMMENT '主键',
|
||||
`company_id` bigint UNSIGNED NOT NULL COMMENT '公司ID',
|
||||
`shop_id` bigint UNSIGNED NOT NULL COMMENT '店铺ID',
|
||||
`platform_id` bigint UNSIGNED NULL DEFAULT NULL COMMENT '平台ID',
|
||||
`stat_year` smallint NOT NULL COMMENT '自然年,如 2024',
|
||||
|
||||
`sales_amount` decimal(16, 2) NOT NULL DEFAULT 0.00 COMMENT '实际销售额',
|
||||
`sales_order_count` int NOT NULL DEFAULT 0 COMMENT '实际销售单量',
|
||||
`sales_quantity_sum` int NOT NULL DEFAULT 0 COMMENT '实际销量件数',
|
||||
`gmv_amount` decimal(16, 2) NOT NULL DEFAULT 0.00 COMMENT '总GMV',
|
||||
`gmv_order_count` int NOT NULL DEFAULT 0 COMMENT 'GMV单量',
|
||||
`gmv_quantity_sum` int NOT NULL DEFAULT 0 COMMENT 'GMV销量件数',
|
||||
`refund_amount` decimal(16, 2) NOT NULL DEFAULT 0.00 COMMENT '退款金额',
|
||||
`product_cost` decimal(16, 2) NOT NULL DEFAULT 0.00 COMMENT '商品成本',
|
||||
`freight_cost` decimal(16, 2) NOT NULL DEFAULT 0.00 COMMENT '运费成本',
|
||||
`other_cost` decimal(16, 2) NOT NULL DEFAULT 0.00 COMMENT '其他成本',
|
||||
|
||||
`stat_version` 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 '更新时间',
|
||||
|
||||
PRIMARY KEY (`id`) USING BTREE,
|
||||
UNIQUE KEY `uk_company_shop_year` (`company_id`, `shop_id`, `stat_year`) USING BTREE,
|
||||
INDEX `idx_company_year` (`company_id`, `stat_year`) USING BTREE,
|
||||
INDEX `idx_company_platform_year` (`company_id`, `platform_id`, `stat_year`) USING BTREE,
|
||||
CONSTRAINT `fk_oss_yearly_shop_company` FOREIGN KEY (`company_id`) REFERENCES `org_company` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
|
||||
CONSTRAINT `fk_oss_yearly_shop_shop` FOREIGN KEY (`shop_id`) REFERENCES `ec_shop` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
|
||||
) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_0900_ai_ci COMMENT = '订单统计-店铺-年汇总(3~5 年 KPI / 平台占比主读表)';
|
||||
|
||||
|
||||
-- =============================================================================
|
||||
-- 三、商品维度(品类 / 商品 / 排行 / 工作台底表)
|
||||
-- product_id = 0 表示未匹配商品;category_id 为订单写入时快照,商品改类目不回算历史
|
||||
-- =============================================================================
|
||||
|
||||
DROP TABLE IF EXISTS `ec_order_stat_daily_product`;
|
||||
CREATE TABLE `ec_order_stat_daily_product` (
|
||||
`id` bigint UNSIGNED NOT NULL AUTO_INCREMENT COMMENT '主键',
|
||||
`company_id` bigint UNSIGNED NOT NULL COMMENT '公司ID',
|
||||
`shop_id` bigint UNSIGNED NOT NULL COMMENT '店铺ID',
|
||||
`product_id` bigint NOT NULL DEFAULT 0 COMMENT '商品ID,0=未匹配',
|
||||
`category_id` bigint NOT NULL DEFAULT 0 COMMENT '品类ID,0=未分类',
|
||||
`stat_date` date NOT NULL COMMENT '自然日',
|
||||
|
||||
`sales_amount` decimal(16, 2) NOT NULL DEFAULT 0.00 COMMENT '实际销售额',
|
||||
`sales_order_count` int NOT NULL DEFAULT 0 COMMENT '实际销售单量',
|
||||
`sales_quantity_sum` int NOT NULL DEFAULT 0 COMMENT '实际销量件数',
|
||||
`gmv_amount` decimal(16, 2) NOT NULL DEFAULT 0.00 COMMENT '总GMV',
|
||||
`gmv_order_count` int NOT NULL DEFAULT 0 COMMENT 'GMV单量',
|
||||
`gmv_quantity_sum` int NOT NULL DEFAULT 0 COMMENT 'GMV销量件数',
|
||||
`refund_amount` decimal(16, 2) NOT NULL DEFAULT 0.00 COMMENT '退款金额',
|
||||
`product_cost` decimal(16, 2) NOT NULL DEFAULT 0.00 COMMENT '商品成本',
|
||||
`freight_cost` decimal(16, 2) NOT NULL DEFAULT 0.00 COMMENT '运费成本',
|
||||
`other_cost` decimal(16, 2) NOT NULL DEFAULT 0.00 COMMENT '其他成本',
|
||||
|
||||
`stat_version` 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 '更新时间',
|
||||
|
||||
PRIMARY KEY (`id`) USING BTREE,
|
||||
UNIQUE KEY `uk_company_shop_prod_cat_date` (`company_id`, `shop_id`, `product_id`, `category_id`, `stat_date`) USING BTREE,
|
||||
INDEX `idx_company_date` (`company_id`, `stat_date`) USING BTREE,
|
||||
INDEX `idx_company_cat_date` (`company_id`, `category_id`, `stat_date`) USING BTREE,
|
||||
INDEX `idx_company_prod_date` (`company_id`, `product_id`, `stat_date`) USING BTREE,
|
||||
INDEX `idx_shop_prod_date` (`shop_id`, `product_id`, `stat_date`) USING BTREE,
|
||||
CONSTRAINT `fk_oss_daily_product_company` FOREIGN KEY (`company_id`) REFERENCES `org_company` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
|
||||
CONSTRAINT `fk_oss_daily_product_shop` FOREIGN KEY (`shop_id`) REFERENCES `ec_shop` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
|
||||
) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_0900_ai_ci COMMENT = '订单统计-商品-日汇总';
|
||||
|
||||
|
||||
DROP TABLE IF EXISTS `ec_order_stat_monthly_product`;
|
||||
CREATE TABLE `ec_order_stat_monthly_product` (
|
||||
`id` bigint UNSIGNED NOT NULL AUTO_INCREMENT COMMENT '主键',
|
||||
`company_id` bigint UNSIGNED NOT NULL COMMENT '公司ID',
|
||||
`shop_id` bigint UNSIGNED NOT NULL COMMENT '店铺ID',
|
||||
`product_id` bigint NOT NULL DEFAULT 0 COMMENT '商品ID',
|
||||
`category_id` bigint NOT NULL DEFAULT 0 COMMENT '品类ID',
|
||||
`stat_month` date NOT NULL COMMENT '自然月首日',
|
||||
|
||||
`sales_amount` decimal(16, 2) NOT NULL DEFAULT 0.00 COMMENT '实际销售额',
|
||||
`sales_order_count` int NOT NULL DEFAULT 0 COMMENT '实际销售单量',
|
||||
`sales_quantity_sum` int NOT NULL DEFAULT 0 COMMENT '实际销量件数',
|
||||
`gmv_amount` decimal(16, 2) NOT NULL DEFAULT 0.00 COMMENT '总GMV',
|
||||
`gmv_order_count` int NOT NULL DEFAULT 0 COMMENT 'GMV单量',
|
||||
`gmv_quantity_sum` int NOT NULL DEFAULT 0 COMMENT 'GMV销量件数',
|
||||
`refund_amount` decimal(16, 2) NOT NULL DEFAULT 0.00 COMMENT '退款金额',
|
||||
`product_cost` decimal(16, 2) NOT NULL DEFAULT 0.00 COMMENT '商品成本',
|
||||
`freight_cost` decimal(16, 2) NOT NULL DEFAULT 0.00 COMMENT '运费成本',
|
||||
`other_cost` decimal(16, 2) NOT NULL DEFAULT 0.00 COMMENT '其他成本',
|
||||
|
||||
`stat_version` 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 '更新时间',
|
||||
|
||||
PRIMARY KEY (`id`) USING BTREE,
|
||||
UNIQUE KEY `uk_company_shop_prod_cat_month` (`company_id`, `shop_id`, `product_id`, `category_id`, `stat_month`) USING BTREE,
|
||||
INDEX `idx_company_month` (`company_id`, `stat_month`) USING BTREE,
|
||||
INDEX `idx_company_cat_month` (`company_id`, `category_id`, `stat_month`) USING BTREE,
|
||||
INDEX `idx_company_prod_month` (`company_id`, `product_id`, `stat_month`) USING BTREE,
|
||||
CONSTRAINT `fk_oss_monthly_product_company` FOREIGN KEY (`company_id`) REFERENCES `org_company` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
|
||||
CONSTRAINT `fk_oss_monthly_product_shop` FOREIGN KEY (`shop_id`) REFERENCES `ec_shop` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
|
||||
) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_0900_ai_ci COMMENT = '订单统计-商品-月汇总(跨月~3年品类/商品明细主读表)';
|
||||
|
||||
|
||||
DROP TABLE IF EXISTS `ec_order_stat_yearly_product`;
|
||||
CREATE TABLE `ec_order_stat_yearly_product` (
|
||||
`id` bigint UNSIGNED NOT NULL AUTO_INCREMENT COMMENT '主键',
|
||||
`company_id` bigint UNSIGNED NOT NULL COMMENT '公司ID',
|
||||
`shop_id` bigint UNSIGNED NOT NULL COMMENT '店铺ID',
|
||||
`product_id` bigint NOT NULL DEFAULT 0 COMMENT '商品ID',
|
||||
`category_id` bigint NOT NULL DEFAULT 0 COMMENT '品类ID',
|
||||
`stat_year` smallint NOT NULL COMMENT '自然年',
|
||||
|
||||
`sales_amount` decimal(16, 2) NOT NULL DEFAULT 0.00 COMMENT '实际销售额',
|
||||
`sales_order_count` int NOT NULL DEFAULT 0 COMMENT '实际销售单量',
|
||||
`sales_quantity_sum` int NOT NULL DEFAULT 0 COMMENT '实际销量件数',
|
||||
`gmv_amount` decimal(16, 2) NOT NULL DEFAULT 0.00 COMMENT '总GMV',
|
||||
`gmv_order_count` int NOT NULL DEFAULT 0 COMMENT 'GMV单量',
|
||||
`gmv_quantity_sum` int NOT NULL DEFAULT 0 COMMENT 'GMV销量件数',
|
||||
`refund_amount` decimal(16, 2) NOT NULL DEFAULT 0.00 COMMENT '退款金额',
|
||||
`product_cost` decimal(16, 2) NOT NULL DEFAULT 0.00 COMMENT '商品成本',
|
||||
`freight_cost` decimal(16, 2) NOT NULL DEFAULT 0.00 COMMENT '运费成本',
|
||||
`other_cost` decimal(16, 2) NOT NULL DEFAULT 0.00 COMMENT '其他成本',
|
||||
|
||||
`stat_version` 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 '更新时间',
|
||||
|
||||
PRIMARY KEY (`id`) USING BTREE,
|
||||
UNIQUE KEY `uk_company_shop_prod_cat_year` (`company_id`, `shop_id`, `product_id`, `category_id`, `stat_year`) USING BTREE,
|
||||
INDEX `idx_company_year` (`company_id`, `stat_year`) USING BTREE,
|
||||
INDEX `idx_company_cat_year` (`company_id`, `category_id`, `stat_year`) USING BTREE,
|
||||
INDEX `idx_company_prod_year` (`company_id`, `product_id`, `stat_year`) USING BTREE,
|
||||
CONSTRAINT `fk_oss_yearly_product_company` FOREIGN KEY (`company_id`) REFERENCES `org_company` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
|
||||
CONSTRAINT `fk_oss_yearly_product_shop` FOREIGN KEY (`shop_id`) REFERENCES `ec_shop` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
|
||||
) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_0900_ai_ci COMMENT = '订单统计-商品-年汇总(3~5 年商品/品类排行)';
|
||||
|
||||
|
||||
-- =============================================================================
|
||||
-- 四、规格维度(商品概览 spec 块专用)
|
||||
-- =============================================================================
|
||||
|
||||
DROP TABLE IF EXISTS `ec_order_stat_daily_spec`;
|
||||
CREATE TABLE `ec_order_stat_daily_spec` (
|
||||
`id` bigint UNSIGNED NOT NULL AUTO_INCREMENT COMMENT '主键',
|
||||
`company_id` bigint UNSIGNED NOT NULL COMMENT '公司ID',
|
||||
`shop_id` bigint UNSIGNED NOT NULL COMMENT '店铺ID',
|
||||
`product_id` bigint UNSIGNED NOT NULL DEFAULT 0 COMMENT '商品ID',
|
||||
`product_spec_id` bigint UNSIGNED NOT NULL DEFAULT 0 COMMENT '规格ID,0=未绑定',
|
||||
`stat_date` date NOT NULL COMMENT '自然日',
|
||||
|
||||
`sales_amount` decimal(16, 2) NOT NULL DEFAULT 0.00 COMMENT '实际销售额',
|
||||
`sales_order_count` int NOT NULL DEFAULT 0 COMMENT '实际销售单量',
|
||||
`sales_quantity_sum` int NOT NULL DEFAULT 0 COMMENT '实际销量件数',
|
||||
`gmv_amount` decimal(16, 2) NOT NULL DEFAULT 0.00 COMMENT '总GMV',
|
||||
`gmv_order_count` int NOT NULL DEFAULT 0 COMMENT 'GMV单量',
|
||||
`gmv_quantity_sum` int NOT NULL DEFAULT 0 COMMENT 'GMV销量件数',
|
||||
`refund_amount` decimal(16, 2) NOT NULL DEFAULT 0.00 COMMENT '退款金额',
|
||||
`product_cost` decimal(16, 2) NOT NULL DEFAULT 0.00 COMMENT '商品成本',
|
||||
`freight_cost` decimal(16, 2) NOT NULL DEFAULT 0.00 COMMENT '运费成本',
|
||||
`other_cost` decimal(16, 2) NOT NULL DEFAULT 0.00 COMMENT '其他成本',
|
||||
|
||||
`stat_version` 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 '更新时间',
|
||||
|
||||
PRIMARY KEY (`id`) USING BTREE,
|
||||
UNIQUE KEY `uk_company_shop_spec_date` (`company_id`, `shop_id`, `product_spec_id`, `stat_date`) USING BTREE,
|
||||
INDEX `idx_company_prod_date` (`company_id`, `product_id`, `stat_date`) USING BTREE,
|
||||
INDEX `idx_company_date` (`company_id`, `stat_date`) USING BTREE,
|
||||
CONSTRAINT `fk_oss_daily_spec_company` FOREIGN KEY (`company_id`) REFERENCES `org_company` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
|
||||
CONSTRAINT `fk_oss_daily_spec_shop` FOREIGN KEY (`shop_id`) REFERENCES `ec_shop` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
|
||||
) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_0900_ai_ci COMMENT = '订单统计-规格-日汇总';
|
||||
|
||||
|
||||
DROP TABLE IF EXISTS `ec_order_stat_monthly_spec`;
|
||||
CREATE TABLE `ec_order_stat_monthly_spec` (
|
||||
`id` bigint UNSIGNED NOT NULL AUTO_INCREMENT COMMENT '主键',
|
||||
`company_id` bigint UNSIGNED NOT NULL COMMENT '公司ID',
|
||||
`shop_id` bigint UNSIGNED NOT NULL COMMENT '店铺ID',
|
||||
`product_id` bigint UNSIGNED NOT NULL DEFAULT 0 COMMENT '商品ID',
|
||||
`product_spec_id` bigint UNSIGNED NOT NULL DEFAULT 0 COMMENT '规格ID',
|
||||
`stat_month` date NOT NULL COMMENT '自然月首日',
|
||||
|
||||
`sales_amount` decimal(16, 2) NOT NULL DEFAULT 0.00 COMMENT '实际销售额',
|
||||
`sales_order_count` int NOT NULL DEFAULT 0 COMMENT '实际销售单量',
|
||||
`sales_quantity_sum` int NOT NULL DEFAULT 0 COMMENT '实际销量件数',
|
||||
`gmv_amount` decimal(16, 2) NOT NULL DEFAULT 0.00 COMMENT '总GMV',
|
||||
`gmv_order_count` int NOT NULL DEFAULT 0 COMMENT 'GMV单量',
|
||||
`gmv_quantity_sum` int NOT NULL DEFAULT 0 COMMENT 'GMV销量件数',
|
||||
`refund_amount` decimal(16, 2) NOT NULL DEFAULT 0.00 COMMENT '退款金额',
|
||||
`product_cost` decimal(16, 2) NOT NULL DEFAULT 0.00 COMMENT '商品成本',
|
||||
`freight_cost` decimal(16, 2) NOT NULL DEFAULT 0.00 COMMENT '运费成本',
|
||||
`other_cost` decimal(16, 2) NOT NULL DEFAULT 0.00 COMMENT '其他成本',
|
||||
|
||||
`stat_version` 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 '更新时间',
|
||||
|
||||
PRIMARY KEY (`id`) USING BTREE,
|
||||
UNIQUE KEY `uk_company_shop_spec_month` (`company_id`, `shop_id`, `product_spec_id`, `stat_month`) USING BTREE,
|
||||
INDEX `idx_company_prod_month` (`company_id`, `product_id`, `stat_month`) USING BTREE,
|
||||
CONSTRAINT `fk_oss_monthly_spec_company` FOREIGN KEY (`company_id`) REFERENCES `org_company` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
|
||||
CONSTRAINT `fk_oss_monthly_spec_shop` FOREIGN KEY (`shop_id`) REFERENCES `ec_shop` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
|
||||
) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_0900_ai_ci COMMENT = '订单统计-规格-月汇总';
|
||||
|
||||
|
||||
DROP TABLE IF EXISTS `ec_order_stat_yearly_spec`;
|
||||
CREATE TABLE `ec_order_stat_yearly_spec` (
|
||||
`id` bigint UNSIGNED NOT NULL AUTO_INCREMENT COMMENT '主键',
|
||||
`company_id` bigint UNSIGNED NOT NULL COMMENT '公司ID',
|
||||
`shop_id` bigint UNSIGNED NOT NULL COMMENT '店铺ID',
|
||||
`product_id` bigint UNSIGNED NOT NULL DEFAULT 0 COMMENT '商品ID',
|
||||
`product_spec_id` bigint UNSIGNED NOT NULL DEFAULT 0 COMMENT '规格ID',
|
||||
`stat_year` smallint NOT NULL COMMENT '自然年',
|
||||
|
||||
`sales_amount` decimal(16, 2) NOT NULL DEFAULT 0.00 COMMENT '实际销售额',
|
||||
`sales_order_count` int NOT NULL DEFAULT 0 COMMENT '实际销售单量',
|
||||
`sales_quantity_sum` int NOT NULL DEFAULT 0 COMMENT '实际销量件数',
|
||||
`gmv_amount` decimal(16, 2) NOT NULL DEFAULT 0.00 COMMENT '总GMV',
|
||||
`gmv_order_count` int NOT NULL DEFAULT 0 COMMENT 'GMV单量',
|
||||
`gmv_quantity_sum` int NOT NULL DEFAULT 0 COMMENT 'GMV销量件数',
|
||||
`refund_amount` decimal(16, 2) NOT NULL DEFAULT 0.00 COMMENT '退款金额',
|
||||
`product_cost` decimal(16, 2) NOT NULL DEFAULT 0.00 COMMENT '商品成本',
|
||||
`freight_cost` decimal(16, 2) NOT NULL DEFAULT 0.00 COMMENT '运费成本',
|
||||
`other_cost` decimal(16, 2) NOT NULL DEFAULT 0.00 COMMENT '其他成本',
|
||||
|
||||
`stat_version` 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 '更新时间',
|
||||
|
||||
PRIMARY KEY (`id`) USING BTREE,
|
||||
UNIQUE KEY `uk_company_shop_spec_year` (`company_id`, `shop_id`, `product_spec_id`, `stat_year`) USING BTREE,
|
||||
INDEX `idx_company_prod_year` (`company_id`, `product_id`, `stat_year`) USING BTREE,
|
||||
CONSTRAINT `fk_oss_yearly_spec_company` FOREIGN KEY (`company_id`) REFERENCES `org_company` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
|
||||
CONSTRAINT `fk_oss_yearly_spec_shop` FOREIGN KEY (`shop_id`) REFERENCES `ec_shop` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
|
||||
) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_0900_ai_ci COMMENT = '订单统计-规格-年汇总';
|
||||
|
||||
|
||||
-- =============================================================================
|
||||
-- 五、推广费 / 刷单费 聚合(跨年区间 SUM 推广/刷单小表仍可能扫大量行,预聚合更稳)
|
||||
-- 粒度与 ec_promotion_fee 一致:shop + 可选 product_id / category_id
|
||||
-- =============================================================================
|
||||
|
||||
DROP TABLE IF EXISTS `ec_promotion_fee_stat_daily`;
|
||||
CREATE TABLE `ec_promotion_fee_stat_daily` (
|
||||
`id` bigint UNSIGNED NOT NULL AUTO_INCREMENT COMMENT '主键',
|
||||
`company_id` bigint UNSIGNED NOT NULL COMMENT '公司ID',
|
||||
`shop_id` bigint UNSIGNED NOT NULL COMMENT '店铺ID',
|
||||
`product_id` bigint UNSIGNED NOT NULL DEFAULT 0 COMMENT '商品ID,0=非商品级',
|
||||
`category_id` bigint UNSIGNED NOT NULL DEFAULT 0 COMMENT '品类ID,0=非品类级',
|
||||
`stat_date` date NOT NULL COMMENT '自然日(fee_date)',
|
||||
|
||||
`fee_amount` decimal(16, 2) NOT NULL DEFAULT 0.00 COMMENT '推广费合计',
|
||||
|
||||
`create_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
|
||||
`update_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
|
||||
|
||||
PRIMARY KEY (`id`) USING BTREE,
|
||||
UNIQUE KEY `uk_company_shop_dims_date` (`company_id`, `shop_id`, `product_id`, `category_id`, `stat_date`) USING BTREE,
|
||||
INDEX `idx_company_date` (`company_id`, `stat_date`) USING BTREE,
|
||||
CONSTRAINT `fk_pfs_daily_company` FOREIGN KEY (`company_id`) REFERENCES `org_company` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
|
||||
CONSTRAINT `fk_pfs_daily_shop` FOREIGN KEY (`shop_id`) REFERENCES `ec_shop` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
|
||||
) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_0900_ai_ci COMMENT = '推广费-日汇总';
|
||||
|
||||
|
||||
DROP TABLE IF EXISTS `ec_promotion_fee_stat_monthly`;
|
||||
CREATE TABLE `ec_promotion_fee_stat_monthly` (
|
||||
`id` bigint UNSIGNED NOT NULL AUTO_INCREMENT COMMENT '主键',
|
||||
`company_id` bigint UNSIGNED NOT NULL COMMENT '公司ID',
|
||||
`shop_id` bigint UNSIGNED NOT NULL COMMENT '店铺ID',
|
||||
`product_id` bigint UNSIGNED NOT NULL DEFAULT 0 COMMENT '商品ID,0=非商品级',
|
||||
`category_id` bigint UNSIGNED NOT NULL DEFAULT 0 COMMENT '品类ID,0=非品类级',
|
||||
`stat_month` date NOT NULL COMMENT '自然月首日',
|
||||
|
||||
`fee_amount` decimal(16, 2) NOT NULL DEFAULT 0.00 COMMENT '推广费合计',
|
||||
|
||||
`create_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
|
||||
`update_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
|
||||
|
||||
PRIMARY KEY (`id`) USING BTREE,
|
||||
UNIQUE KEY `uk_company_shop_dims_month` (`company_id`, `shop_id`, `product_id`, `category_id`, `stat_month`) USING BTREE,
|
||||
INDEX `idx_company_month` (`company_id`, `stat_month`) USING BTREE,
|
||||
CONSTRAINT `fk_pfs_monthly_company` FOREIGN KEY (`company_id`) REFERENCES `org_company` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
|
||||
CONSTRAINT `fk_pfs_monthly_shop` FOREIGN KEY (`shop_id`) REFERENCES `ec_shop` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
|
||||
) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_0900_ai_ci COMMENT = '推广费-月汇总';
|
||||
|
||||
|
||||
DROP TABLE IF EXISTS `ec_promotion_fee_stat_yearly`;
|
||||
CREATE TABLE `ec_promotion_fee_stat_yearly` (
|
||||
`id` bigint UNSIGNED NOT NULL AUTO_INCREMENT COMMENT '主键',
|
||||
`company_id` bigint UNSIGNED NOT NULL COMMENT '公司ID',
|
||||
`shop_id` bigint UNSIGNED NOT NULL COMMENT '店铺ID',
|
||||
`product_id` bigint UNSIGNED NOT NULL DEFAULT 0 COMMENT '商品ID,0=非商品级',
|
||||
`category_id` bigint UNSIGNED NOT NULL DEFAULT 0 COMMENT '品类ID,0=非品类级',
|
||||
`stat_year` smallint NOT NULL COMMENT '自然年',
|
||||
|
||||
`fee_amount` decimal(16, 2) NOT NULL DEFAULT 0.00 COMMENT '推广费合计',
|
||||
|
||||
`create_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
|
||||
`update_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
|
||||
|
||||
PRIMARY KEY (`id`) USING BTREE,
|
||||
UNIQUE KEY `uk_company_shop_dims_year` (`company_id`, `shop_id`, `product_id`, `category_id`, `stat_year`) USING BTREE,
|
||||
INDEX `idx_company_year` (`company_id`, `stat_year`) USING BTREE,
|
||||
CONSTRAINT `fk_pfs_yearly_company` FOREIGN KEY (`company_id`) REFERENCES `org_company` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
|
||||
CONSTRAINT `fk_pfs_yearly_shop` FOREIGN KEY (`shop_id`) REFERENCES `ec_shop` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
|
||||
) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_0900_ai_ci COMMENT = '推广费-年汇总';
|
||||
|
||||
|
||||
DROP TABLE IF EXISTS `ec_brush_fee_stat_daily`;
|
||||
CREATE TABLE `ec_brush_fee_stat_daily` (
|
||||
`id` bigint UNSIGNED NOT NULL AUTO_INCREMENT COMMENT '主键',
|
||||
`company_id` bigint UNSIGNED NOT NULL COMMENT '公司ID',
|
||||
`shop_id` bigint UNSIGNED NOT NULL COMMENT '店铺ID',
|
||||
`stat_date` date NOT NULL COMMENT '自然日',
|
||||
|
||||
`brush_amount` decimal(16, 2) NOT NULL DEFAULT 0.00 COMMENT '刷单费合计',
|
||||
|
||||
`create_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
|
||||
`update_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
|
||||
|
||||
PRIMARY KEY (`id`) USING BTREE,
|
||||
UNIQUE KEY `uk_company_shop_date` (`company_id`, `shop_id`, `stat_date`) USING BTREE,
|
||||
INDEX `idx_company_date` (`company_id`, `stat_date`) USING BTREE,
|
||||
CONSTRAINT `fk_bfs_daily_company` FOREIGN KEY (`company_id`) REFERENCES `org_company` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
|
||||
CONSTRAINT `fk_bfs_daily_shop` FOREIGN KEY (`shop_id`) REFERENCES `ec_shop` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
|
||||
) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_0900_ai_ci COMMENT = '刷单费-日汇总';
|
||||
|
||||
|
||||
DROP TABLE IF EXISTS `ec_brush_fee_stat_monthly`;
|
||||
CREATE TABLE `ec_brush_fee_stat_monthly` (
|
||||
`id` bigint UNSIGNED NOT NULL AUTO_INCREMENT COMMENT '主键',
|
||||
`company_id` bigint UNSIGNED NOT NULL COMMENT '公司ID',
|
||||
`shop_id` bigint UNSIGNED NOT NULL COMMENT '店铺ID',
|
||||
`stat_month` date NOT NULL COMMENT '自然月首日',
|
||||
|
||||
`brush_amount` decimal(16, 2) NOT NULL DEFAULT 0.00 COMMENT '刷单费合计',
|
||||
|
||||
`create_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
|
||||
`update_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
|
||||
|
||||
PRIMARY KEY (`id`) USING BTREE,
|
||||
UNIQUE KEY `uk_company_shop_month` (`company_id`, `shop_id`, `stat_month`) USING BTREE,
|
||||
INDEX `idx_company_month` (`company_id`, `stat_month`) USING BTREE,
|
||||
CONSTRAINT `fk_bfs_monthly_company` FOREIGN KEY (`company_id`) REFERENCES `org_company` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
|
||||
CONSTRAINT `fk_bfs_monthly_shop` FOREIGN KEY (`shop_id`) REFERENCES `ec_shop` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
|
||||
) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_0900_ai_ci COMMENT = '刷单费-月汇总';
|
||||
|
||||
|
||||
DROP TABLE IF EXISTS `ec_brush_fee_stat_yearly`;
|
||||
CREATE TABLE `ec_brush_fee_stat_yearly` (
|
||||
`id` bigint UNSIGNED NOT NULL AUTO_INCREMENT COMMENT '主键',
|
||||
`company_id` bigint UNSIGNED NOT NULL COMMENT '公司ID',
|
||||
`shop_id` bigint UNSIGNED NOT NULL COMMENT '店铺ID',
|
||||
`stat_year` smallint NOT NULL COMMENT '自然年',
|
||||
|
||||
`brush_amount` decimal(16, 2) NOT NULL DEFAULT 0.00 COMMENT '刷单费合计',
|
||||
|
||||
`create_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
|
||||
`update_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
|
||||
|
||||
PRIMARY KEY (`id`) USING BTREE,
|
||||
UNIQUE KEY `uk_company_shop_year` (`company_id`, `shop_id`, `stat_year`) USING BTREE,
|
||||
INDEX `idx_company_year` (`company_id`, `stat_year`) USING BTREE,
|
||||
CONSTRAINT `fk_bfs_yearly_company` FOREIGN KEY (`company_id`) REFERENCES `org_company` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
|
||||
CONSTRAINT `fk_bfs_yearly_shop` FOREIGN KEY (`shop_id`) REFERENCES `ec_shop` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
|
||||
) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_0900_ai_ci COMMENT = '刷单费-年汇总';
|
||||
|
||||
|
||||
-- =============================================================================
|
||||
-- 六、刷新 / 重建任务(Backfill、导入后异步、状态配置变更全量 rebuild)
|
||||
-- =============================================================================
|
||||
|
||||
DROP TABLE IF EXISTS `ec_order_stat_rebuild_task`;
|
||||
CREATE TABLE `ec_order_stat_rebuild_task` (
|
||||
`id` bigint UNSIGNED NOT NULL AUTO_INCREMENT COMMENT '主键',
|
||||
`company_id` bigint UNSIGNED NOT NULL COMMENT '公司ID',
|
||||
`shop_id` bigint UNSIGNED NULL DEFAULT NULL COMMENT '店铺ID,NULL=全店',
|
||||
`start_date` date NOT NULL COMMENT '重建起始日',
|
||||
`end_date` date NOT NULL COMMENT '重建结束日',
|
||||
`granularity` varchar(16) NOT NULL DEFAULT 'all' COMMENT 'daily/monthly/yearly/all',
|
||||
`status` varchar(20) NOT NULL DEFAULT 'pending' COMMENT 'pending/running/done/failed',
|
||||
`progress_date` date NULL DEFAULT NULL COMMENT '已处理到的日期(断点续跑)',
|
||||
`error_message` text NULL COMMENT '失败原因',
|
||||
`create_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
|
||||
`update_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
|
||||
|
||||
PRIMARY KEY (`id`) USING BTREE,
|
||||
INDEX `idx_company_status` (`company_id`, `status`) USING BTREE,
|
||||
CONSTRAINT `fk_osrt_company` FOREIGN KEY (`company_id`) REFERENCES `org_company` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
|
||||
) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_0900_ai_ci COMMENT = '订单统计重建任务';
|
||||
|
||||
|
||||
DROP TABLE IF EXISTS `ec_order_stat_refresh_queue`;
|
||||
CREATE TABLE `ec_order_stat_refresh_queue` (
|
||||
`id` bigint UNSIGNED NOT NULL AUTO_INCREMENT COMMENT '主键',
|
||||
`company_id` bigint UNSIGNED NOT NULL COMMENT '公司ID',
|
||||
`shop_id` bigint UNSIGNED NOT NULL COMMENT '店铺ID',
|
||||
`stat_date` date NOT NULL COMMENT '待刷新自然日',
|
||||
`source` varchar(32) NOT NULL COMMENT 'import/crud/status_change/manual',
|
||||
`status` varchar(20) NOT NULL DEFAULT 'pending' COMMENT 'pending/running/done/failed',
|
||||
`retry_count` 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 '更新时间',
|
||||
|
||||
PRIMARY KEY (`id`) USING BTREE,
|
||||
UNIQUE KEY `uk_company_shop_date_pending` (`company_id`, `shop_id`, `stat_date`, `status`) USING BTREE,
|
||||
INDEX `idx_status_ctime` (`status`, `create_time`) USING BTREE,
|
||||
CONSTRAINT `fk_osrq_company` FOREIGN KEY (`company_id`) REFERENCES `org_company` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
|
||||
CONSTRAINT `fk_osrq_shop` FOREIGN KEY (`shop_id`) REFERENCES `ec_shop` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
|
||||
) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_0900_ai_ci COMMENT = '订单统计日汇总待刷新队列';
|
||||
|
||||
|
||||
-- =============================================================================
|
||||
-- 七、Rollup 示例(写入侧 Job 参考,不在应用启动时执行)
|
||||
-- =============================================================================
|
||||
--
|
||||
-- 月表 ← 日表(店铺):
|
||||
-- INSERT INTO ec_order_stat_monthly_shop (...)
|
||||
-- SELECT company_id, shop_id, MAX(platform_id),
|
||||
-- DATE_FORMAT(stat_date, '%Y-%m-01'),
|
||||
-- SUM(sales_amount), SUM(sales_order_count), SUM(sales_quantity_sum),
|
||||
-- SUM(gmv_amount), SUM(gmv_order_count), SUM(gmv_quantity_sum),
|
||||
-- SUM(refund_amount), SUM(product_cost), SUM(freight_cost), SUM(other_cost)
|
||||
-- FROM ec_order_stat_daily_shop
|
||||
-- WHERE company_id=? AND shop_id=? AND stat_date BETWEEN ? AND ?
|
||||
-- GROUP BY company_id, shop_id, DATE_FORMAT(stat_date, '%Y-%m-01')
|
||||
-- ON DUPLICATE KEY UPDATE sales_amount=VALUES(sales_amount), ...;
|
||||
--
|
||||
-- 年表 ← 月表(店铺):
|
||||
-- INSERT INTO ec_order_stat_yearly_shop (...)
|
||||
-- SELECT company_id, shop_id, MAX(platform_id), YEAR(stat_month),
|
||||
-- SUM(sales_amount), ...
|
||||
-- FROM ec_order_stat_monthly_shop
|
||||
-- WHERE company_id=? AND stat_year BETWEEN ? AND ?
|
||||
-- GROUP BY company_id, shop_id, YEAR(stat_month)
|
||||
-- ON DUPLICATE KEY UPDATE ...;
|
||||
--
|
||||
-- 单日 refresh 顺序:ec_order → daily_* → 触达 stat_month/stat_year 边界时 rollup 对应月/年行
|
||||
-- =============================================================================
|
||||
@@ -0,0 +1,70 @@
|
||||
-- ========================================
|
||||
-- 拼多多商品对接数据库设计
|
||||
-- 数据来源:pdd.goods.list.get → goods_list_get_response.goods_list
|
||||
-- 设计原则:
|
||||
-- 1. 与 ec_product / ec_product_spec(内部成本分析商品)分离,存平台同步数据
|
||||
-- 2. SPU 主表 + SKU 明细表,spec_details 存入 SKU 行 JSON
|
||||
-- 3. 后续可通过 outer_id / outer_goods_id 映射到 ec_product_spec
|
||||
-- ========================================
|
||||
|
||||
-- ========================================
|
||||
-- 拼多多商品主表(SPU)
|
||||
-- ========================================
|
||||
DROP TABLE IF EXISTS `ec_pdd_goods_sku`;
|
||||
DROP TABLE IF EXISTS `ec_pdd_goods`;
|
||||
CREATE TABLE `ec_pdd_goods` (
|
||||
`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(ec_shop.id)',
|
||||
`pdd_auth_id` bigint UNSIGNED NULL DEFAULT NULL COMMENT '拼多多授权ID(open_pdd_auth.id)',
|
||||
`goods_id` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL COMMENT '拼多多商品ID(goods_id)',
|
||||
`goods_name` varchar(500) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL COMMENT '商品名称(goods_name)',
|
||||
`goods_quantity` int NOT NULL DEFAULT 0 COMMENT '商品总库存(goods_quantity)',
|
||||
`goods_reserve_quantity` int NOT NULL DEFAULT 0 COMMENT '商品预扣库存(goods_reserve_quantity)',
|
||||
`image_url` varchar(500) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT '商品主图(image_url)',
|
||||
`thumb_url` varchar(500) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT '商品缩略图(thumb_url)',
|
||||
`is_more_sku` tinyint NOT NULL DEFAULT 0 COMMENT '是否多SKU 0否 1是(is_more_sku)',
|
||||
`is_onsale` tinyint NOT NULL DEFAULT 0 COMMENT '是否在架 0否 1是(is_onsale)',
|
||||
`pdd_created_at` datetime NULL DEFAULT NULL COMMENT '拼多多创建时间(created_at)',
|
||||
`raw_response` json NULL COMMENT '商品完整 JSON(含未结构化扩展字段)',
|
||||
`last_sync_time` datetime 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 '更新时间',
|
||||
PRIMARY KEY (`id`) USING BTREE,
|
||||
UNIQUE INDEX `uk_ec_pdd_goods_company_goods`(`company_id` ASC, `goods_id` ASC) USING BTREE,
|
||||
INDEX `idx_ec_pdd_goods_shop`(`shop_id` ASC) USING BTREE,
|
||||
INDEX `idx_ec_pdd_goods_onsale`(`is_onsale` ASC) USING BTREE,
|
||||
INDEX `idx_ec_pdd_goods_auth`(`pdd_auth_id` ASC) USING BTREE,
|
||||
INDEX `idx_ec_pdd_goods_sync`(`last_sync_time` ASC) USING BTREE,
|
||||
CONSTRAINT `fk_ec_pdd_goods_company` FOREIGN KEY (`company_id`) REFERENCES `org_company` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
|
||||
CONSTRAINT `fk_ec_pdd_goods_shop` FOREIGN KEY (`shop_id`) REFERENCES `ec_shop` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
|
||||
CONSTRAINT `fk_ec_pdd_goods_auth` FOREIGN KEY (`pdd_auth_id`) REFERENCES `open_pdd_auth` (`id`) ON DELETE SET NULL ON UPDATE CASCADE
|
||||
) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_0900_ai_ci COMMENT = '拼多多-商品主表(SPU)' ROW_FORMAT = Dynamic;
|
||||
|
||||
-- ========================================
|
||||
-- 拼多多商品 SKU 明细表(对应 sku_list)
|
||||
-- ========================================
|
||||
CREATE TABLE `ec_pdd_goods_sku` (
|
||||
`id` bigint UNSIGNED NOT NULL AUTO_INCREMENT COMMENT '主键ID',
|
||||
`goods_row_id` bigint UNSIGNED NOT NULL COMMENT '商品主表ID(ec_pdd_goods.id)',
|
||||
`company_id` bigint UNSIGNED NOT NULL COMMENT '公司ID(冗余)',
|
||||
`goods_id` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL COMMENT '拼多多商品ID(冗余)',
|
||||
`sku_id` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL COMMENT '拼多多SKU ID(sku_id)',
|
||||
`spec` varchar(500) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT '规格描述(spec)',
|
||||
`spec_details` json NULL COMMENT '规格明细(spec_details JSON 数组)',
|
||||
`sku_quantity` int NOT NULL DEFAULT 0 COMMENT 'SKU库存(sku_quantity)',
|
||||
`reserve_quantity` int NOT NULL DEFAULT 0 COMMENT 'SKU预扣库存(reserve_quantity)',
|
||||
`is_sku_onsale` tinyint NOT NULL DEFAULT 0 COMMENT 'SKU是否在架 0否 1是(is_sku_onsale)',
|
||||
`outer_goods_id` varchar(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT '商家外部商品编码(outer_goods_id)',
|
||||
`outer_id` varchar(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT '商家外部SKU编码(outer_id),可映射 ec_product_spec.spec_code',
|
||||
`create_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
|
||||
`update_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
|
||||
PRIMARY KEY (`id`) USING BTREE,
|
||||
UNIQUE INDEX `uk_ec_pdd_goods_sku`(`company_id` ASC, `sku_id` ASC) USING BTREE,
|
||||
UNIQUE INDEX `uk_ec_pdd_goods_sku_line`(`goods_row_id` ASC, `sku_id` ASC) USING BTREE,
|
||||
INDEX `idx_ec_pdd_goods_sku_goods`(`goods_id` ASC) USING BTREE,
|
||||
INDEX `idx_ec_pdd_goods_sku_outer`(`outer_id` ASC) USING BTREE,
|
||||
INDEX `idx_ec_pdd_goods_sku_onsale`(`is_sku_onsale` ASC) USING BTREE,
|
||||
CONSTRAINT `fk_ec_pdd_goods_sku_goods` FOREIGN KEY (`goods_row_id`) REFERENCES `ec_pdd_goods` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
|
||||
CONSTRAINT `fk_ec_pdd_goods_sku_company` FOREIGN KEY (`company_id`) REFERENCES `org_company` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
|
||||
) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_0900_ai_ci COMMENT = '拼多多-商品SKU明细表' ROW_FORMAT = Dynamic;
|
||||
@@ -0,0 +1,95 @@
|
||||
-- ========================================
|
||||
-- 拼多多订单对接数据库设计
|
||||
-- 数据来源:pdd.order.list.get → order_list_get_response.order_list
|
||||
-- 设计原则:
|
||||
-- 1. 与 ec_order(内部经营分析订单)分离,本模块存平台原始同步数据
|
||||
-- 2. 主表 + 明细表覆盖列表查询、对账、物流、状态同步等核心场景
|
||||
-- 3. gift_list、promotion_detail_list、order_tag_list 等嵌套结构存入 raw_response
|
||||
-- ========================================
|
||||
|
||||
-- ========================================
|
||||
-- 拼多多订单主表
|
||||
-- ========================================
|
||||
DROP TABLE IF EXISTS `ec_pdd_order_item`;
|
||||
DROP TABLE IF EXISTS `ec_pdd_order`;
|
||||
CREATE TABLE `ec_pdd_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(ec_shop.id)',
|
||||
`pdd_auth_id` bigint UNSIGNED NULL DEFAULT NULL COMMENT '拼多多授权ID(open_pdd_auth.id)',
|
||||
`order_sn` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL COMMENT '拼多多订单号',
|
||||
`order_status` int NOT NULL COMMENT '订单状态(order_status 1:待发货,2:已发货待签收,3:已签收)',
|
||||
`refund_status` int NULL DEFAULT NULL COMMENT '退款状态(refund_status 1:无售后或售后关闭,2:售后处理中,3:退款中,4: 退款成功)',
|
||||
`after_sales_status` int NULL DEFAULT NULL COMMENT '售后状态(after_sales_status 0:无售后 2:买家申请退款,待商家处理 3:退货退款,待商家处理 4:商家同意退款,退款中 5:平台同意退款,退款中 6:驳回退款,待买家处理 7:已同意退货退款,待用户发货 8:平台处理中 9:平台拒绝退款,退款关闭 10:退款成功 11:买家撤销 12:买家逾期未处理,退款失败 13:买家逾期,超过有效期 14:换货补寄待商家处理 15:换货补寄待用户处理 16:换货补寄成功 17:换货补寄失败 18:换货补寄待用户确认完成 21:待商家同意维修 22:待用户确认发货 24:维修关闭 25:维修成功 27:待用户确认收货 31:已同意拒收退款,待用户拒收 32:补寄待商家发货 33:同意召回后退款,待商家召回)',
|
||||
`confirm_status` int NULL DEFAULT NULL COMMENT '成交状态(confirm_status)',
|
||||
`pay_amount` decimal(12, 2) NOT NULL DEFAULT 0.00 COMMENT '实付金额(pay_amount)',
|
||||
`goods_amount` decimal(12, 2) NOT NULL DEFAULT 0.00 COMMENT '商品金额(goods_amount)',
|
||||
`discount_amount` decimal(12, 2) NOT NULL DEFAULT 0.00 COMMENT '折扣金额(discount_amount)',
|
||||
`postage` decimal(12, 2) NOT NULL DEFAULT 0.00 COMMENT '邮费(postage)',
|
||||
`platform_discount` decimal(12, 2) NOT NULL DEFAULT 0.00 COMMENT '平台优惠(platform_discount)',
|
||||
`seller_discount` decimal(12, 2) NOT NULL DEFAULT 0.00 COMMENT '商家优惠(seller_discount)',
|
||||
`logistics_id` bigint NULL DEFAULT NULL COMMENT '快递公司编码(logistics_id)',
|
||||
`tracking_number` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT '快递运单号(tracking_number)',
|
||||
`created_time` datetime NOT NULL COMMENT '下单时间(created_time)',
|
||||
`pay_time` datetime NULL DEFAULT NULL COMMENT '支付时间(pay_time)',
|
||||
`confirm_time` datetime NULL DEFAULT NULL COMMENT '成交时间(confirm_time)',
|
||||
`shipping_time` datetime NULL DEFAULT NULL COMMENT '发货时间(shipping_time)',
|
||||
`receive_time` datetime NULL DEFAULT NULL COMMENT '签收时间(receive_time)',
|
||||
`last_ship_time` datetime NULL DEFAULT NULL COMMENT '承诺发货时间(last_ship_time)',
|
||||
`pdd_updated_at` datetime NULL DEFAULT NULL COMMENT '拼多多订单更新时间(updated_at)',
|
||||
`province` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT '省份',
|
||||
`city` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT '城市',
|
||||
`town` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT '区县',
|
||||
`receiver_name_mask` varchar(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT '收件人姓名脱敏(receiver_name_mask)',
|
||||
`receiver_phone_mask` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT '收件人手机脱敏(receiver_phone_mask)',
|
||||
`receiver_address_mask` varchar(500) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT '收件地址脱敏(receiver_address_mask)',
|
||||
`buyer_memo` varchar(500) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT '买家留言(buyer_memo)',
|
||||
`remark` varchar(500) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT '商家备注(remark)',
|
||||
`trade_type` int NULL DEFAULT NULL COMMENT '交易类型(trade_type)',
|
||||
`is_pre_sale` tinyint NULL DEFAULT NULL COMMENT '是否预售 0否 1是',
|
||||
`group_status` int NULL DEFAULT NULL COMMENT '拼团状态(group_status)',
|
||||
`raw_response` json NULL COMMENT '订单完整 JSON(含 gift_list、promotion_detail_list 等扩展字段)',
|
||||
`last_sync_time` datetime 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 '更新时间',
|
||||
PRIMARY KEY (`id`) USING BTREE,
|
||||
UNIQUE INDEX `uk_ec_pdd_order_company_sn`(`company_id` ASC, `order_sn` ASC) USING BTREE,
|
||||
INDEX `idx_ec_pdd_order_shop_created`(`shop_id` ASC, `created_time` ASC) USING BTREE,
|
||||
INDEX `idx_ec_pdd_order_company_created`(`company_id` ASC, `created_time` ASC) USING BTREE,
|
||||
INDEX `idx_ec_pdd_order_status`(`order_status` ASC) USING BTREE,
|
||||
INDEX `idx_ec_pdd_order_pay_time`(`pay_time` ASC) USING BTREE,
|
||||
INDEX `idx_ec_pdd_order_pdd_updated`(`pdd_updated_at` ASC) USING BTREE COMMENT '增量同步游标',
|
||||
INDEX `idx_ec_pdd_order_auth`(`pdd_auth_id` ASC) USING BTREE,
|
||||
CONSTRAINT `fk_ec_pdd_order_company` FOREIGN KEY (`company_id`) REFERENCES `org_company` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
|
||||
CONSTRAINT `fk_ec_pdd_order_shop` FOREIGN KEY (`shop_id`) REFERENCES `ec_shop` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
|
||||
CONSTRAINT `fk_ec_pdd_order_auth` FOREIGN KEY (`pdd_auth_id`) REFERENCES `open_pdd_auth` (`id`) ON DELETE SET NULL ON UPDATE CASCADE
|
||||
) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_0900_ai_ci COMMENT = '拼多多-订单主表' ROW_FORMAT = Dynamic;
|
||||
|
||||
-- ========================================
|
||||
-- 拼多多订单商品明细表(对应 item_list)
|
||||
-- ========================================
|
||||
CREATE TABLE `ec_pdd_order_item` (
|
||||
`id` bigint UNSIGNED NOT NULL AUTO_INCREMENT COMMENT '主键ID',
|
||||
`order_id` bigint UNSIGNED NOT NULL COMMENT '订单ID(ec_pdd_order.id)',
|
||||
`company_id` bigint UNSIGNED NOT NULL COMMENT '公司ID(冗余,便于查询)',
|
||||
`order_sn` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL COMMENT '拼多多订单号(冗余)',
|
||||
`goods_id` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL COMMENT '拼多多商品ID(goods_id)',
|
||||
`sku_id` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL COMMENT '拼多多SKU ID(sku_id)',
|
||||
`goods_name` varchar(500) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL COMMENT '商品名称(goods_name)',
|
||||
`goods_spec` varchar(500) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT '商品规格(goods_spec)',
|
||||
`goods_img` varchar(500) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT '商品图片(goods_img)',
|
||||
`goods_count` int NOT NULL DEFAULT 1 COMMENT '商品数量(goods_count)',
|
||||
`goods_price` decimal(12, 2) NOT NULL DEFAULT 0.00 COMMENT '商品单价(goods_price)',
|
||||
`outer_goods_id` varchar(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT '商家外部商品编码(outer_goods_id)',
|
||||
`outer_id` varchar(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT '商家外部SKU编码(outer_id)',
|
||||
`create_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
|
||||
`update_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
|
||||
PRIMARY KEY (`id`) USING BTREE,
|
||||
UNIQUE INDEX `uk_ec_pdd_order_item_line`(`order_id` ASC, `sku_id` ASC) USING BTREE,
|
||||
INDEX `idx_ec_pdd_order_item_company`(`company_id` ASC) USING BTREE,
|
||||
INDEX `idx_ec_pdd_order_item_order_sn`(`order_sn` ASC) USING BTREE,
|
||||
INDEX `idx_ec_pdd_order_item_goods`(`goods_id` ASC) USING BTREE,
|
||||
INDEX `idx_ec_pdd_order_item_outer`(`outer_id` ASC) USING BTREE COMMENT '关联内部商品规格',
|
||||
CONSTRAINT `fk_ec_pdd_order_item_order` FOREIGN KEY (`order_id`) REFERENCES `ec_pdd_order` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
|
||||
CONSTRAINT `fk_ec_pdd_order_item_company` FOREIGN KEY (`company_id`) REFERENCES `org_company` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
|
||||
) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_0900_ai_ci COMMENT = '拼多多-订单商品明细表' ROW_FORMAT = Dynamic;
|
||||
@@ -0,0 +1,31 @@
|
||||
-- ========================================
|
||||
-- 拼多多店铺对接数据库设计
|
||||
-- 数据来源:pdd.mall.info.get → mall_info_get_response
|
||||
-- 设计原则:
|
||||
-- 1. 与 ec_shop(内部店铺)分离,存拼多多平台店铺信息
|
||||
-- 2. 授权后可拉取店铺信息写入本表,并回写绑定 ec_shop / open_pdd_auth
|
||||
-- ========================================
|
||||
|
||||
DROP TABLE IF EXISTS `ec_pdd_shop`;
|
||||
CREATE TABLE `ec_pdd_shop` (
|
||||
`id` bigint UNSIGNED NOT NULL AUTO_INCREMENT COMMENT '主键ID',
|
||||
`company_id` bigint UNSIGNED NOT NULL COMMENT '公司ID',
|
||||
`shop_id` bigint UNSIGNED NULL DEFAULT NULL COMMENT '内部店铺ID(ec_shop.id),绑定后填写',
|
||||
`pdd_auth_id` bigint UNSIGNED NULL DEFAULT NULL COMMENT '拼多多授权ID(open_pdd_auth.id)',
|
||||
`mall_id` bigint UNSIGNED NOT NULL COMMENT '拼多多店铺ID(mall_id)',
|
||||
`mall_name` varchar(200) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL COMMENT '店铺名称(mall_name)',
|
||||
`logo` varchar(500) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT '店铺logo(logo)',
|
||||
`mall_desc` varchar(1000) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT '店铺描述(mall_desc)',
|
||||
`merchant_type` tinyint NOT NULL COMMENT '店铺类型(merchant_type):1个人 2企业 3旗舰店 4专卖店 5专营店 6普通店',
|
||||
`mall_character` tinyint NOT NULL DEFAULT 2 COMMENT '店铺身份(mall_character):0厂商 1分销商 2都不是 3都是',
|
||||
`last_sync_time` datetime 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 '更新时间',
|
||||
PRIMARY KEY (`id`) USING BTREE,
|
||||
UNIQUE INDEX `uk_ec_pdd_shop_company_mall`(`company_id` ASC, `mall_id` ASC) USING BTREE,
|
||||
UNIQUE INDEX `uk_ec_pdd_shop_auth`(`pdd_auth_id` ASC) USING BTREE COMMENT '一个授权对应一个拼多多店铺',
|
||||
INDEX `idx_ec_pdd_shop_shop`(`shop_id` ASC) USING BTREE,
|
||||
CONSTRAINT `fk_ec_pdd_shop_company` FOREIGN KEY (`company_id`) REFERENCES `org_company` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
|
||||
CONSTRAINT `fk_ec_pdd_shop_ec_shop` FOREIGN KEY (`shop_id`) REFERENCES `ec_shop` (`id`) ON DELETE SET NULL ON UPDATE CASCADE,
|
||||
CONSTRAINT `fk_ec_pdd_shop_auth` FOREIGN KEY (`pdd_auth_id`) REFERENCES `open_pdd_auth` (`id`) ON DELETE SET NULL ON UPDATE CASCADE
|
||||
) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_0900_ai_ci COMMENT = '拼多多-店铺信息表' ROW_FORMAT = Dynamic;
|
||||
Reference in New Issue
Block a user