feat: database design v2.0 - fix 15 defects, add 6 new tables

fixes:
- as_platform_type/platform: add status/del_flag/timestamps, sort_order varchar->int
- as_sub_plan: platform_id varchar->bigint, capacity varchar->int
- as_sub_payroll: rename sub_plans->sub_plan_id, add duration_months/original_price/is_active
- as_sub_product: fix Tags->tags naming bug, add platform_id/cover_image/status/total_capacity, type fields Long->tinyint
- as_sub_account: 4 int->bigint fields, passwd_salt int->varchar(64), add encrypt_type/status
- as_user_sub: remark int->varchar(bug fix), int->bigint fields, add product_id/status/expire_time, rename user_id->host_user_id/main_account->account_id
- as_sub_product_comment: add order_id/is_anonymous/reply_id/del_flag

new tables:
- as_user_sub_member: individual subscription record (critical missing table)
- as_order: full order table with state machine
- as_wallet: user wallet with optimistic lock
- as_wallet_log: balance transaction log
- as_invite: invitation relationship
- as_notification: system notifications
This commit is contained in:
阿米狗
2026-02-17 19:36:55 +08:00
parent d6af71ec14
commit 0192fc3523
2 changed files with 797 additions and 0 deletions

370
db/ishare_schema_v2.sql Normal file
View File

@@ -0,0 +1,370 @@
-- ============================================================
-- iShare 数据库设计 v2.0(修订版)
-- 修订时间: 2026-02-17
-- 修订说明: 修复原版缺陷,补充完整业务字段和新增表
-- 数据库: pigxx_app
-- ============================================================
USE pigxx_app;
SET NAMES utf8mb4;
SET FOREIGN_KEY_CHECKS = 0;
-- ============================================================
-- 一、App 基础表(沿用原版,仅 app_user 追加字段)
-- ============================================================
-- app_user 追加字段ALTER不重建表
ALTER TABLE `app_user`
ADD COLUMN IF NOT EXISTS `invite_code` varchar(16) UNIQUE COMMENT '用户专属邀请码(注册时生成)' AFTER `email`,
ADD COLUMN IF NOT EXISTS `inviter_id` bigint DEFAULT NULL COMMENT '邀请人用户ID' AFTER `invite_code`;
-- ============================================================
-- 二、iShare 核心业务表修订版8 张原表 + 新增 6 张)
-- ============================================================
-- ------------------------------------------------------------
-- 2.1 as_platform_type — 平台类型
-- 修订: 加 status、del_flag、create_time/update_time
-- ------------------------------------------------------------
DROP TABLE IF EXISTS `as_platform_type`;
CREATE TABLE `as_platform_type` (
`id` bigint NOT NULL COMMENT '主键',
`name` varchar(64) NOT NULL COMMENT '类型名称(视频/音乐/AI等',
`platform_type` int NOT NULL DEFAULT 0 COMMENT '类型编号用于分类筛选0=全部',
`sort_order` int NOT NULL DEFAULT 0 COMMENT '排序权重(升序)',
`status` tinyint NOT NULL DEFAULT 1 COMMENT '状态: 0=禁用, 1=启用',
`del_flag` char(1) NOT NULL DEFAULT '0' COMMENT '删除标志: 0=正常, 1=已删除',
`create_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
`update_time` datetime DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
PRIMARY KEY (`id`),
KEY `idx_platform_type` (`platform_type`),
KEY `idx_sort` (`sort_order`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='平台类型表';
-- ------------------------------------------------------------
-- 2.2 as_platform — 流媒体平台
-- 修订: 加 description、status、del_flag、create_time/update_time
-- sort_order 从 varchar 改为 int
-- ------------------------------------------------------------
DROP TABLE IF EXISTS `as_platform`;
CREATE TABLE `as_platform` (
`id` bigint NOT NULL COMMENT '主键',
`platform_name` varchar(128) NOT NULL COMMENT '平台名称',
`platform_type` int NOT NULL DEFAULT 0 COMMENT '平台类型(关联 as_platform_type.platform_type',
`icon` varchar(512) DEFAULT NULL COMMENT '应用图标 URL',
`description` varchar(512) DEFAULT NULL COMMENT '平台简介',
`company` varchar(128) DEFAULT NULL COMMENT '所属公司',
`website` varchar(256) DEFAULT NULL COMMENT '平台官网',
`sort_order` int NOT NULL DEFAULT 0 COMMENT '排序权重(升序)',
`status` tinyint NOT NULL DEFAULT 1 COMMENT '状态: 0=禁用, 1=启用',
`del_flag` char(1) NOT NULL DEFAULT '0' COMMENT '删除标志: 0=正常, 1=已删除',
`create_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
`update_time` datetime DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
PRIMARY KEY (`id`),
KEY `idx_platform_type` (`platform_type`),
KEY `idx_status` (`status`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='流媒体平台表';
-- ------------------------------------------------------------
-- 2.3 as_sub_plan — 订阅计划
-- 修订: platform_id varchar→bigint, capacity varchar→int
-- 加 status、del_flag、create_time/update_time
-- ------------------------------------------------------------
DROP TABLE IF EXISTS `as_sub_plan`;
CREATE TABLE `as_sub_plan` (
`id` bigint NOT NULL COMMENT '计划ID',
`name` varchar(128) NOT NULL COMMENT '计划名称(标准版/高级版等)',
`platform_id` bigint NOT NULL COMMENT '所属平台ID→ as_platform.id',
`capacity` int NOT NULL DEFAULT 1 COMMENT '席位容量(该计划最多可共享人数)',
`remark` varchar(256) DEFAULT NULL COMMENT '备注',
`sort_order` int NOT NULL DEFAULT 0 COMMENT '排序权重(升序)',
`status` tinyint NOT NULL DEFAULT 1 COMMENT '状态: 0=禁用, 1=启用',
`del_flag` char(1) NOT NULL DEFAULT '0' COMMENT '删除标志: 0=正常, 1=已删除',
`create_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
`update_time` datetime DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
PRIMARY KEY (`id`),
KEY `idx_platform_id` (`platform_id`),
KEY `idx_status` (`status`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='订阅计划表';
-- ------------------------------------------------------------
-- 2.4 as_sub_payroll — 付费方案
-- 修订: sub_plans(Long,注释混乱) → sub_plan_id(bigint,明确1:1)
-- 加 duration_months、original_price、is_active
-- del_flag、create_time/update_time
-- ------------------------------------------------------------
DROP TABLE IF EXISTS `as_sub_payroll`;
CREATE TABLE `as_sub_payroll` (
`id` bigint NOT NULL COMMENT '主键',
`sub_plan_id` bigint NOT NULL COMMENT '所属订阅计划ID→ as_sub_plan.id',
`platform_id` bigint NOT NULL COMMENT '平台ID冗余便于查询',
`payroll` tinyint NOT NULL COMMENT '付费周期: 1=月付, 2=季付, 3=年付',
`duration_months` int NOT NULL COMMENT '实际月数: 1/3/12与 payroll 对应)',
`price` decimal(10,2) NOT NULL COMMENT '售价',
`original_price` decimal(10,2) DEFAULT NULL COMMENT '划线价(原价,用于展示折扣)',
`currency` varchar(8) NOT NULL DEFAULT 'CNY' COMMENT '货币单位CNY/USD等',
`region` varchar(64) DEFAULT NULL COMMENT '适用地区',
`is_active` tinyint NOT NULL DEFAULT 1 COMMENT '是否上架: 0=下架, 1=上架',
`del_flag` char(1) NOT NULL DEFAULT '0' COMMENT '删除标志: 0=正常, 1=已删除',
`create_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
`update_time` datetime DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
PRIMARY KEY (`id`),
KEY `idx_sub_plan_id` (`sub_plan_id`),
KEY `idx_platform_id` (`platform_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='付费方案表';
-- ------------------------------------------------------------
-- 2.5 as_sub_product — 订阅产品(合租商品)
-- 修订: Tags→tags(命名修复), 加 platform_id、status、cover_image
-- product_type/sub_type 从 Long 改为 tinyint
-- 加 total_capacity、del_flag、create_by/update_by
-- ------------------------------------------------------------
DROP TABLE IF EXISTS `as_sub_product`;
CREATE TABLE `as_sub_product` (
`id` bigint NOT NULL COMMENT '主键',
`title` varchar(256) NOT NULL COMMENT '产品标题',
`description` varchar(1024) DEFAULT NULL COMMENT '产品描述',
`cover_image` varchar(512) DEFAULT NULL COMMENT '封面图 URL',
`tags` varchar(256) DEFAULT NULL COMMENT '标签(逗号分隔)',
`platform_id` bigint NOT NULL COMMENT '所属平台ID→ as_platform.id冗余加速查询',
`sub_plan_ids` varchar(256) DEFAULT NULL COMMENT '关联订阅计划ID列表逗号分隔',
`product_type` tinyint NOT NULL DEFAULT 1 COMMENT '产品类型: 1=自营, 2=个人',
`sub_type` tinyint NOT NULL DEFAULT 1 COMMENT '订阅类型: 1=单品, 2=多品组合',
`total_capacity` int NOT NULL DEFAULT 1 COMMENT '总席位数(该商品可供多少人购买)',
`amount` decimal(10,2) DEFAULT NULL COMMENT '基准价格(月)',
`star` decimal(3,1) DEFAULT 0.0 COMMENT '综合评分0.0-5.0,由评价聚合更新)',
`status` tinyint NOT NULL DEFAULT 0 COMMENT '状态: 0=草稿, 1=上架, 2=下架, 3=售完',
`user_id` bigint DEFAULT NULL COMMENT '发布者用户ID→ app_user.user_id',
`del_flag` char(1) NOT NULL DEFAULT '0' COMMENT '删除标志: 0=正常, 1=已删除',
`create_by` varchar(64) DEFAULT NULL COMMENT '创建人',
`update_by` varchar(64) DEFAULT NULL COMMENT '修改人',
`create_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
`update_time` datetime DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
PRIMARY KEY (`id`),
KEY `idx_platform_id` (`platform_id`),
KEY `idx_status` (`status`),
KEY `idx_product_type` (`product_type`),
KEY `idx_user_id` (`user_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='订阅产品表(合租商品)';
-- ------------------------------------------------------------
-- 2.6 as_sub_account — 流媒体平台账号凭据
-- 修订: user_id/sub_plan_id/sub_payroll_id/platform_id int→bigint
-- passwd_salt int→varchar(64,存hex/base64)
-- 加 encrypt_type、status、del_flag、create_time/update_time
-- ------------------------------------------------------------
DROP TABLE IF EXISTS `as_sub_account`;
CREATE TABLE `as_sub_account` (
`id` bigint NOT NULL COMMENT '主键',
`product_id` bigint DEFAULT NULL COMMENT '关联产品ID→ as_sub_product.id',
`sub_plan_id` bigint DEFAULT NULL COMMENT '订阅计划ID→ as_sub_plan.id',
`sub_payroll_id` bigint DEFAULT NULL COMMENT '付费方案ID→ as_sub_payroll.id',
`platform_id` bigint NOT NULL COMMENT '平台ID→ as_platform.id',
`user_id` bigint NOT NULL COMMENT '账号持有者用户ID主用户→ app_user.user_id',
`account_name` varchar(256) NOT NULL COMMENT '平台登录用户名/邮箱',
`account_passwd` varchar(512) NOT NULL COMMENT '平台登录密码(加密存储)',
`passwd_salt` varchar(64) NOT NULL COMMENT '加密盐值Base64/Hex16字节随机',
`encrypt_type` tinyint NOT NULL DEFAULT 1 COMMENT '加密算法: 1=AES-256-GCM',
`region` varchar(64) DEFAULT NULL COMMENT '账号所在地区',
`share_type` tinyint DEFAULT NULL COMMENT '分享类型',
`account_type` tinyint DEFAULT NULL COMMENT '账号类型(主账号/子账号等)',
`renew_date` datetime DEFAULT NULL COMMENT '账号在平台的下次续费日',
`status` tinyint NOT NULL DEFAULT 0 COMMENT '账号状态: 0=正常, 1=已失效, 2=异常/被封',
`del_flag` char(1) NOT NULL DEFAULT '0' COMMENT '删除标志: 0=正常, 1=已删除',
`create_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
`update_time` datetime DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
PRIMARY KEY (`id`),
KEY `idx_product_id` (`product_id`),
KEY `idx_platform_id` (`platform_id`),
KEY `idx_user_id` (`user_id`),
KEY `idx_status` (`status`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='流媒体平台账号凭据表';
-- ------------------------------------------------------------
-- 2.7 as_user_sub — 合租槽(共享池)
-- 语义修订: 代表"一个合租位池",不代表个人订阅
-- 修订: remark int→varchar, plan_id/user_id/main_account int→bigint
-- 加 product_id、status、expire_time、del_flag、create_time/update_time
-- ------------------------------------------------------------
DROP TABLE IF EXISTS `as_user_sub`;
CREATE TABLE `as_user_sub` (
`id` bigint NOT NULL COMMENT '主键',
`product_id` bigint NOT NULL COMMENT '关联产品ID→ as_sub_product.id',
`plan_id` bigint NOT NULL COMMENT '订阅计划ID→ as_sub_plan.id',
`platform_id` bigint NOT NULL COMMENT '平台ID冗余加速查询',
`host_user_id` bigint NOT NULL COMMENT '车主用户ID提供账号的一方→ app_user.user_id',
`account_id` bigint DEFAULT NULL COMMENT '关联平台账号ID→ as_sub_account.id',
`capacity` int NOT NULL COMMENT '总席位数(来自 as_sub_plan.capacity',
`capacity_loaded` int NOT NULL DEFAULT 0 COMMENT '已占用席位数',
`region` varchar(64) DEFAULT NULL COMMENT '地区',
`status` tinyint NOT NULL DEFAULT 0 COMMENT '状态: 0=可加入, 1=已满, 2=已到期, 3=已关闭',
`expire_time` datetime DEFAULT NULL COMMENT '该合租槽到期时间(来自最晚成员到期时间)',
`remark` varchar(512) DEFAULT NULL COMMENT '备注(车主说明)',
`del_flag` char(1) NOT NULL DEFAULT '0' COMMENT '删除标志: 0=正常, 1=已删除',
`create_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
`update_time` datetime DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
PRIMARY KEY (`id`),
KEY `idx_product_id` (`product_id`),
KEY `idx_plan_id` (`plan_id`),
KEY `idx_host_user_id` (`host_user_id`),
KEY `idx_status` (`status`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='合租槽表(共享席位池)';
-- ------------------------------------------------------------
-- 2.8 as_sub_product_comment — 产品评价
-- 修订: 加 del_flag、is_anonymous、reply_id支持追评
-- star 字段加注释明确 1-5 范围
-- ------------------------------------------------------------
DROP TABLE IF EXISTS `as_sub_product_comment`;
CREATE TABLE `as_sub_product_comment` (
`id` bigint NOT NULL COMMENT '主键',
`product_id` bigint NOT NULL COMMENT '关联产品ID→ as_sub_product.id',
`user_id` bigint NOT NULL COMMENT '评价用户ID→ app_user.user_id',
`order_id` bigint DEFAULT NULL COMMENT '关联订单ID校验是否已购买',
`star` tinyint NOT NULL COMMENT '评分 1-5服务端校验范围',
`comment` varchar(1024) DEFAULT NULL COMMENT '评价内容',
`is_anonymous` tinyint NOT NULL DEFAULT 0 COMMENT '是否匿名: 0=公开, 1=匿名',
`reply_id` bigint DEFAULT NULL COMMENT '回复的评价ID追评/商家回复NULL=原始评价)',
`del_flag` char(1) NOT NULL DEFAULT '0' COMMENT '删除标志: 0=正常, 1=已删除',
`create_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
`update_time` datetime DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
PRIMARY KEY (`id`),
KEY `idx_product_id` (`product_id`),
KEY `idx_user_id` (`user_id`),
KEY `idx_reply_id` (`reply_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='产品评价表';
-- ============================================================
-- 三、新增表(原版缺失的核心业务表)
-- ============================================================
-- ------------------------------------------------------------
-- 3.1 as_user_sub_member — 个人订阅记录(原版最大缺失)
-- 语义: 某用户购买加入了某合租槽,追踪个人维度
-- ------------------------------------------------------------
CREATE TABLE IF NOT EXISTS `as_user_sub_member` (
`id` bigint NOT NULL COMMENT '主键',
`sub_id` bigint NOT NULL COMMENT '关联合租槽ID→ as_user_sub.id',
`user_id` bigint NOT NULL COMMENT '订阅用户ID→ app_user.user_id',
`order_id` bigint NOT NULL COMMENT '关联订单ID→ as_order.id',
`payroll_id` bigint NOT NULL COMMENT '购买的付费方案ID→ as_sub_payroll.id',
`status` tinyint NOT NULL DEFAULT 0 COMMENT '状态: 0=待激活, 1=使用中, 2=已到期, 3=已退订',
`start_time` datetime NOT NULL COMMENT '订阅开始时间',
`expire_time` datetime NOT NULL COMMENT '订阅到期时间',
`del_flag` char(1) NOT NULL DEFAULT '0' COMMENT '删除标志: 0=正常, 1=已删除',
`create_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
`update_time` datetime DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
PRIMARY KEY (`id`),
UNIQUE KEY `uk_sub_user` (`sub_id`, `user_id`),
KEY `idx_user_id` (`user_id`),
KEY `idx_order_id` (`order_id`),
KEY `idx_status` (`status`),
KEY `idx_expire` (`expire_time`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='个人订阅记录表';
-- ------------------------------------------------------------
-- 3.2 as_order — 订单表
-- ------------------------------------------------------------
CREATE TABLE IF NOT EXISTS `as_order` (
`id` bigint NOT NULL COMMENT '主键',
`order_no` varchar(32) NOT NULL COMMENT '订单号(业务唯一,格式: AS+时间戳+随机)',
`user_id` bigint NOT NULL COMMENT '购买用户ID→ app_user.user_id',
`product_id` bigint NOT NULL COMMENT '商品ID→ as_sub_product.id',
`payroll_id` bigint NOT NULL COMMENT '付费方案ID→ as_sub_payroll.id',
`original_amount` decimal(10,2) NOT NULL COMMENT '原价(快照,防止价格变动)',
`discount_amount` decimal(10,2) NOT NULL DEFAULT 0.00 COMMENT '优惠金额',
`amount` decimal(10,2) NOT NULL COMMENT '实付金额',
`pay_type` tinyint DEFAULT NULL COMMENT '支付方式: 1=余额, 2=支付宝, 3=微信支付',
`pay_no` varchar(64) DEFAULT NULL COMMENT '第三方支付单号',
`status` tinyint NOT NULL DEFAULT 0 COMMENT '状态: 0=待支付, 1=已支付, 2=已完成, 3=已退款, 4=已取消',
`member_id` bigint DEFAULT NULL COMMENT '关联个人订阅记录ID→ as_user_sub_member.id支付成功后填充',
`remark` varchar(256) DEFAULT NULL COMMENT '备注',
`expire_time` datetime NOT NULL COMMENT '订单过期时间(未支付自动取消,默认 +15min',
`pay_time` datetime DEFAULT NULL COMMENT '实际支付时间',
`del_flag` char(1) NOT NULL DEFAULT '0' COMMENT '删除标志: 0=正常, 1=已删除',
`create_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
`update_time` datetime DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
PRIMARY KEY (`id`),
UNIQUE KEY `uk_order_no` (`order_no`),
KEY `idx_user_id` (`user_id`),
KEY `idx_product_id` (`product_id`),
KEY `idx_status` (`status`),
KEY `idx_expire` (`expire_time`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='订单表';
-- ------------------------------------------------------------
-- 3.3 as_wallet — 用户钱包
-- ------------------------------------------------------------
CREATE TABLE IF NOT EXISTS `as_wallet` (
`id` bigint NOT NULL COMMENT '主键',
`user_id` bigint NOT NULL COMMENT '用户ID→ app_user.user_id一人一钱包',
`balance` decimal(10,2) NOT NULL DEFAULT 0.00 COMMENT '可用余额',
`frozen_amount` decimal(10,2) NOT NULL DEFAULT 0.00 COMMENT '冻结金额(退款/提现处理中)',
`total_income` decimal(10,2) NOT NULL DEFAULT 0.00 COMMENT '累计收入',
`total_expense` decimal(10,2) NOT NULL DEFAULT 0.00 COMMENT '累计支出',
`version` int NOT NULL DEFAULT 0 COMMENT '乐观锁版本号(防并发余额错误)',
`create_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
`update_time` datetime DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
PRIMARY KEY (`id`),
UNIQUE KEY `uk_user_id` (`user_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='用户钱包表';
-- ------------------------------------------------------------
-- 3.4 as_wallet_log — 钱包流水
-- ------------------------------------------------------------
CREATE TABLE IF NOT EXISTS `as_wallet_log` (
`id` bigint NOT NULL COMMENT '主键',
`user_id` bigint NOT NULL COMMENT '用户ID→ app_user.user_id',
`amount` decimal(10,2) NOT NULL COMMENT '变动金额(正=收入, 负=支出)',
`type` tinyint NOT NULL COMMENT '类型: 1=充值, 2=消费, 3=退款, 4=邀请返现, 5=提现',
`order_id` bigint DEFAULT NULL COMMENT '关联订单ID→ as_order.id可空',
`balance_after` decimal(10,2) NOT NULL COMMENT '操作后余额(快照,便于对账)',
`remark` varchar(256) DEFAULT NULL COMMENT '说明(如:订阅 Netflix 高级版 3 个月)',
`create_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
PRIMARY KEY (`id`),
KEY `idx_user_id` (`user_id`),
KEY `idx_order_id` (`order_id`),
KEY `idx_type` (`type`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='钱包流水表';
-- ------------------------------------------------------------
-- 3.5 as_invite — 邀请关系
-- ------------------------------------------------------------
CREATE TABLE IF NOT EXISTS `as_invite` (
`id` bigint NOT NULL COMMENT '主键',
`inviter_id` bigint NOT NULL COMMENT '邀请人用户ID→ app_user.user_id',
`invitee_id` bigint NOT NULL COMMENT '被邀请人用户ID→ app_user.user_id',
`invite_code` varchar(16) NOT NULL COMMENT '使用的邀请码',
`reward_amount` decimal(10,2) DEFAULT NULL COMMENT '返现金额(首次购买后确定)',
`reward_status` tinyint NOT NULL DEFAULT 0 COMMENT '返现状态: 0=待发放, 1=已发放, 2=已失效',
`reward_time` datetime DEFAULT NULL COMMENT '返现发放时间',
`create_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间(注册时间)',
PRIMARY KEY (`id`),
UNIQUE KEY `uk_invitee` (`invitee_id`),
KEY `idx_inviter_id` (`inviter_id`),
KEY `idx_invite_code` (`invite_code`),
KEY `idx_reward_status` (`reward_status`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='邀请关系表';
-- ------------------------------------------------------------
-- 3.6 as_notification — 系统通知
-- ------------------------------------------------------------
CREATE TABLE IF NOT EXISTS `as_notification` (
`id` bigint NOT NULL COMMENT '主键',
`user_id` bigint NOT NULL COMMENT '目标用户ID→ app_user.user_id0=全体广播)',
`title` varchar(128) NOT NULL COMMENT '通知标题',
`content` varchar(1024) NOT NULL COMMENT '通知内容',
`type` tinyint NOT NULL COMMENT '类型: 1=续费提醒, 2=订单通知, 3=系统公告, 4=邀请奖励',
`ref_id` bigint DEFAULT NULL COMMENT '关联业务ID订单ID/订阅ID等按 type 解析)',
`is_read` tinyint NOT NULL DEFAULT 0 COMMENT '是否已读: 0=未读, 1=已读',
`create_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
PRIMARY KEY (`id`),
KEY `idx_user_id` (`user_id`),
KEY `idx_is_read` (`is_read`),
KEY `idx_type` (`type`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='系统通知表';
SET FOREIGN_KEY_CHECKS = 1;