Files
ecom-dmb/sql/sub_design.sql
T

87 lines
6.1 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
-- ========================================
-- ========================================
-- SUB_PLAN
-- ========================================
DROP TABLE IF EXISTS `sub_plan`;
CREATE TABLE `sub_plan` (
`id` bigint unsigned NOT NULL AUTO_INCREMENT COMMENT '套餐ID',
`name` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL COMMENT '套餐名称',
`user_limit` int DEFAULT NULL COMMENT '用户数量限制,NULL 表示不限',
`is_trial` tinyint NOT NULL DEFAULT '0' COMMENT '是否为试用套餐 (1-是 0-否)',
`trial_days` int DEFAULT NULL COMMENT '试用天数,仅 is_trial = 1 时有效',
`status` tinyint NOT NULL DEFAULT '1' COMMENT '状态:(1-可购买 0-下架)',
`remark` text CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci 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`) USING BTREE,
KEY `fk_sub_plan_creator` (`create_by`) USING BTREE,
KEY `fk_sub_plan_updater` (`update_by`) USING BTREE,
CONSTRAINT `fk_sub_plan_creator` FOREIGN KEY (`create_by`) REFERENCES `sys_user` (`id`) ON DELETE SET NULL ON UPDATE CASCADE,
CONSTRAINT `fk_sub_plan_updater` FOREIGN KEY (`update_by`) REFERENCES `sys_user` (`id`) ON DELETE SET NULL ON UPDATE CASCADE
) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='订阅套餐定义表'
-- ========================================
-- SUB_PLAN_PRICING
-- ========================================
DROP TABLE IF EXISTS `sub_plan_pricing`;
CREATE TABLE `sub_plan_pricing` (
`id` bigint unsigned NOT NULL AUTO_INCREMENT COMMENT '定价ID',
`plan_id` bigint unsigned NOT NULL COMMENT '对应套餐ID',
`price` decimal(10,2) NOT NULL COMMENT '价格(元)',
`duration_months` int NOT NULL DEFAULT '1' COMMENT '订阅时长(月)',
`stauts` tinyint NOT NULL DEFAULT '1' COMMENT '是否启用当前价格(1-启用,0-禁用)',
`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`) USING BTREE,
KEY `idx_plan_id` (`plan_id`) USING BTREE,
KEY `fk_sub_plan_pricing_creator` (`create_by`) USING BTREE,
KEY `fk_sub_plan_pricing_updater` (`update_by`) USING BTREE,
CONSTRAINT `fk_sub_plan_pricing_creator` FOREIGN KEY (`create_by`) REFERENCES `sys_user` (`id`) ON DELETE SET NULL ON UPDATE CASCADE,
CONSTRAINT `fk_sub_plan_pricing_plan` FOREIGN KEY (`plan_id`) REFERENCES `sub_plan` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
CONSTRAINT `fk_sub_plan_pricing_updater` FOREIGN KEY (`update_by`) REFERENCES `sys_user` (`id`) ON DELETE SET NULL ON UPDATE CASCADE
) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='订阅套餐定价表'
-- ========================================
-- SUB_SUBSCRIPTION
-- ========================================
DROP TABLE IF EXISTS `sub_subscription`;
CREATE TABLE `sub_subscription` (
`id` bigint unsigned NOT NULL AUTO_INCREMENT COMMENT '记录ID',
`company_id` bigint unsigned NOT NULL COMMENT '公司ID(关联sys_company)',
`plan_id` bigint unsigned NOT NULL COMMENT '套餐ID(关联sub_plan)',
`start_time` timestamp NOT NULL COMMENT '订阅开始时间',
`end_time` timestamp NOT NULL COMMENT '订阅结束时间',
`status` enum('ACTIVE','PENDING','INACTIVE') CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL DEFAULT 'ACTIVE' COMMENT '生效状态(ACTIVE-生效中,PENDING-待生效,INACTIVE-已失效)',
`paid_amount` decimal(10,2) DEFAULT '0.00' COMMENT '实际支付金额',
`payment_status` enum('UNPAID','PAID','REFUNDED') CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL DEFAULT 'UNPAID' COMMENT '支付状态(UNPAID=未支付,PAID=已支付,REFUNDED=已退款)',
`payment_time` datetime DEFAULT NULL COMMENT '支付时间',
`order_no` varchar(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci DEFAULT NULL COMMENT '第三方支付订单号',
`remark` varchar(200) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci 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 '更新时间',
`delete_time` timestamp NULL DEFAULT NULL COMMENT '删除时间',
`create_by` bigint unsigned DEFAULT NULL COMMENT '创建人 id',
`update_by` bigint unsigned DEFAULT NULL COMMENT '更新人 id',
`delete_by` bigint unsigned DEFAULT NULL COMMENT '删除人 id',
PRIMARY KEY (`id`) USING BTREE,
KEY `fk_sub_subscription_company` (`company_id`) USING BTREE,
KEY `fk_sub_subscription_plan` (`plan_id`) USING BTREE,
KEY `fk_sub_subscription_creator` (`create_by`) USING BTREE,
KEY `fk_sub_subscription_updater` (`update_by`) USING BTREE,
KEY `fk_sub_subscription_deleter` (`delete_by`) USING BTREE,
CONSTRAINT `fk_sub_subscription_company` FOREIGN KEY (`company_id`) REFERENCES `org_company` (`id`) ON DELETE RESTRICT ON UPDATE CASCADE,
CONSTRAINT `fk_sub_subscription_creator` FOREIGN KEY (`create_by`) REFERENCES `sys_user` (`id`) ON DELETE SET NULL ON UPDATE CASCADE,
CONSTRAINT `fk_sub_subscription_deleter` FOREIGN KEY (`delete_by`) REFERENCES `sys_user` (`id`) ON DELETE SET NULL ON UPDATE CASCADE,
CONSTRAINT `fk_sub_subscription_plan` FOREIGN KEY (`plan_id`) REFERENCES `sub_plan` (`id`) ON DELETE RESTRICT ON UPDATE CASCADE,
CONSTRAINT `fk_sub_subscription_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='订阅记录表中间表'