# 抽奖盲盒系统数据库设计图 ## 1. 数据库整体ER图 ```mermaid erDiagram %% 用户相关表 USER ||--o{ ORDER : "下单" USER ||--o{ ORDER_LIST : "中奖记录" USER ||--o{ COUPON_RECEIVE : "领取优惠券" USER ||--o{ PROFIT_MONEY : "资金变动" USER ||--o{ PROFIT_INTEGRAL : "积分变动" USER ||--o{ COLLECT : "收藏" USER ||--o{ MARKET : "集市发布" USER ||--o{ MARKET_ORDER : "集市购买" %% 商品相关表 CATEGORY ||--o{ GOODS : "商品分类" GOODS ||--o{ GOODS_LIST : "奖品列表" GOODS ||--o{ ORDER : "被购买" GOODS ||--o{ GOODS_LOCK : "锁箱记录" GOODS_LIST ||--o{ ORDER_LIST : "中奖奖品" %% 订单相关表 ORDER ||--o{ ORDER_LIST : "订单明细" ORDER_LIST ||--o{ ORDER_LIST_SEND : "发货记录" ORDER_LIST ||--o{ ORDER_LIST_RECOVERY : "回收记录" ORDER_LIST ||--o{ MARKET : "集市商品" %% 优惠券相关表 COUPON ||--o{ COUPON_RECEIVE : "用户优惠券" %% 集市相关表 MARKET ||--o{ MARKET_ORDER : "集市订单" %% 管理员相关表 ADMIN ||--o{ ADMIN_LOGIN_LOG : "登录日志" ADMIN ||--o{ ADMIN_OPERATION_LOG : "操作日志" ADMIN_QUANXIAN ||--o{ ADMIN : "权限分配" USER { int id PK "用户ID" string phone "手机号" string nickname "昵称" string avatar "头像" decimal money "余额" decimal integral "积分" decimal money2 "达达卷" int level "等级" int status "状态" int addtime "注册时间" int login_time "最后登录" string openid "微信openid" int share_uid "推荐人ID" } GOODS { int id PK "商品ID" int category_id FK "分类ID" string title "商品名称" string imgurl "封面图" string imgurl_detail "详情图" decimal price "价格" int stock "库存" int sale_stock "销量" int type "类型1一番赏2无限赏3擂台赏4抽卡机5积分赏6全局赏7福利盲盒8领主赏9连击赏" int status "状态1上架2下架3售罄" int sort "排序" int lock_is "锁箱开关" int lock_time "锁箱时间" int coupon_is "发券开关" int coupon_pro "发券概率" int integral_is "发积分开关" int prize_num "抽奖数量" int sale_time "预售时间" int addtime "添加时间" int update_time "更新时间" } GOODS_LIST { int id PK "奖品ID" int goods_id FK "商品ID" int num "第几套" string title "奖品名称" string imgurl "奖品图片" int stock "库存" int surplus_stock "剩余库存" decimal price "奖品价值" decimal money "回收价" decimal sc_money "市场参考价" decimal real_pro "真实概率" int goods_type "奖品类型1现货2预售3货币4宝箱" int sale_time "预售时间" int sort "排序" string shang_id "赏ID" int reward_num "奖励数量" int rank "榜单排名" string prize_code "奖品编号" int addtime "添加时间" } ORDER { int id PK "订单ID" int user_id FK "用户ID" string order_num "订单号" decimal order_total "订单总金额" decimal order_zhe_total "折扣金额" decimal price "微信支付金额" decimal use_money "余额支付" decimal use_integral "积分支付" decimal use_money2 "达达卷支付" decimal use_coupon "优惠券抵扣" int use_draw "抽奖券抵扣" int use_item_card "道具卡抵扣" int goods_id FK "商品ID" int num "第几套" decimal goods_price "商品单价" string goods_title "商品标题" string goods_imgurl "商品图片" int prize_num "抽奖数量" int status "状态0未支付1已支付" int addtime "下单时间" int pay_time "支付时间" int pay_type "支付方式1微信2支付宝" int order_type "订单类型" int coupon_id "优惠券ID" } ORDER_LIST { int id PK "中奖记录ID" int order_id FK "订单ID" int user_id FK "用户ID" string recovery_num "回收订单号" string send_num "发货订单号" int status "状态0待选择1回收2发货3集市" int goods_id FK "商品ID" int num "第几箱" int shang_id "赏ID" int goodslist_id FK "奖品ID" string goodslist_title "奖品名称" string goodslist_imgurl "奖品图片" decimal goodslist_price "奖品价值" decimal goodslist_money "回收价" int goodslist_type "奖品类型" int goodslist_sale_time "预售时间" int addtime "中奖时间" int choice_time "选择时间" int insurance_is "保险柜0否1是" int order_type "订单类型" int luck_no "抽奖序号" string prize_code "奖品编号" int source "来源1抽奖2集市购买" } CATEGORY { int id PK "分类ID" string title "分类名称" int sort "排序" int addtime "添加时间" int update_time "更新时间" } COUPON { int id PK "优惠券ID" int type "类型1新人券2权益券" string title "优惠券名称" int sort "排序" decimal price "减免金额" decimal man_price "满减条件" int effective_day "有效天数" int addtime "添加时间" int status "状态0上架2下架4删除" int ttype "使用限制0不限制1一番赏2无限赏" } COUPON_RECEIVE { int id PK "用户优惠券ID" string title "优惠券名称" decimal price "减免金额" decimal man_price "满减条件" int end_time "过期时间" int addtime "领取时间" int status "状态0未使用1已使用2已过期" int user_id FK "用户ID" int coupon_id FK "优惠券ID" int state "使用限制" } PROFIT_MONEY { int id PK "资金记录ID" int user_id FK "用户ID" decimal change_money "变化金额" decimal money "变化后金额" int type "类型1后台充值2在线充值3消费4回收5推荐奖励" string content "描述" int addtime "添加时间" int share_uid "来源用户ID" string other "其他信息" } PROFIT_INTEGRAL { int id PK "积分记录ID" int user_id FK "用户ID" decimal change_money "变化积分" decimal money "变化后积分" int type "类型1后台充值2消费3开券获得4领主返币5分享欧气券" string content "描述" int addtime "添加时间" int share_uid "来源用户ID" string other "其他信息" } MARKET { int id PK "集市商品ID" int user_id FK "卖家ID" string order_num "挂售单号" decimal price "售价" text order_list_ids "奖品ID列表" int status "状态0在售1已售2已撤回" int stock "库存" int addtime "发布时间" int update_time "更新时间" } MARKET_ORDER { int id PK "集市订单ID" int market_id FK "集市商品ID" int user_id FK "买家ID" string order_num "订单号" decimal price "单价" text order_list_ids "奖品ID列表" int status "状态1未支付2已支付3卡单" int pay_time "支付时间" decimal total "总价" decimal total_price "实际支付" decimal money "余额支付" int addtime "下单时间" int update_time "更新时间" } ADMIN { int id PK "管理员ID" string username "账号" string nickname "姓名" string password "密码" int qid "权限ID" int status "状态0正常1禁用" int get_time "登录刷新时间" string random "token随机数" string token "token" int admin_id "操作人" int addtime "添加时间" int update_time "修改时间" } ADMIN_QUANXIAN { int id PK "权限ID" string title "权限名称" text describe "描述" text quanxian "权限内容" int addtime "添加时间" int update_time "修改时间" int admin_id "操作人" } ``` ## 2. 核心业务表关系图 ```mermaid erDiagram %% 抽奖核心流程 USER ||--o{ ORDER : "用户下单" ORDER ||--|| GOODS : "购买商品" ORDER ||--o{ ORDER_LIST : "生成中奖记录" GOODS ||--o{ GOODS_LIST : "包含奖品" GOODS_LIST ||--|| ORDER_LIST : "中奖奖品" %% 用户选择处理 ORDER_LIST ||--o| ORDER_LIST_SEND : "选择发货" ORDER_LIST ||--o| ORDER_LIST_RECOVERY : "选择回收" ORDER_LIST ||--o| MARKET : "发布集市" %% 集市交易 MARKET ||--o{ MARKET_ORDER : "集市购买" USER ||--o{ MARKET_ORDER : "买家下单" ORDER_LIST { int id PK int order_id FK int user_id FK int goodslist_id FK int status "0待选择1回收2发货3集市" string goodslist_title decimal goodslist_price decimal goodslist_money int addtime } ORDER_LIST_SEND { int id PK int user_id FK string send_num "发货订单号" decimal freight "运费" int status "0待支付1待发货2待收货3已完成" int count "发货数量" string name "收货人" string mobile "电话" string address "地址" string courier_number "快递单号" int addtime } ORDER_LIST_RECOVERY { int id PK int user_id FK string recovery_num "回收订单号" decimal money "回收金额" int count "回收数量" int addtime } ``` ## 3. 用户财务系统表关系图 ```mermaid erDiagram USER ||--o{ PROFIT_MONEY : "余额变动" USER ||--o{ PROFIT_INTEGRAL : "积分变动" USER ||--o{ PROFIT_DRAW : "抽奖券变动" USER ||--o{ COUPON_RECEIVE : "优惠券" COUPON ||--o{ COUPON_RECEIVE : "发放" ORDER ||--|| PROFIT_MONEY : "支付扣款" ORDER_LIST_RECOVERY ||--|| PROFIT_MONEY : "回收入账" USER { int id PK decimal money "余额" decimal integral "积分" decimal money2 "达达卷" int draw_num "抽奖券" } PROFIT_MONEY { int id PK int user_id FK decimal change_money "变化金额" decimal money "变化后余额" int type "1后台充值2在线充值3消费4回收5推荐奖励" string content "描述" int addtime } PROFIT_INTEGRAL { int id PK int user_id FK decimal change_money "变化积分" decimal money "变化后积分" int type "1后台充值2消费3开券获得4领主返币" string content "描述" int addtime } PROFIT_DRAW { int id PK int user_id FK decimal change_money "变化抽奖券" decimal money "变化后抽奖券" int type "变动类型" string content "描述" int addtime } ``` ## 4. 商品管理系统表关系图 ```mermaid erDiagram CATEGORY ||--o{ GOODS : "商品分类" GOODS ||--o{ GOODS_LIST : "奖品配置" GOODS ||--o{ GOODS_LOCK : "锁箱记录" GOODS ||--o{ GOODS_EXTEND : "扩展配置" GOODS_TYPE ||--|| GOODS : "商品类型" GOODS { int id PK int category_id FK string title "商品名称" string imgurl "封面图" decimal price "价格" int stock "库存套数" int type "1一番赏2无限赏3擂台赏等" int status "1上架2下架3售罄" int lock_is "锁箱开关" int coupon_is "发券开关" int integral_is "发积分开关" int prize_num "抽奖数量" int addtime } GOODS_LIST { int id PK int goods_id FK int num "第几套" string title "奖品名称" int stock "奖品库存" int surplus_stock "剩余库存" decimal price "奖品价值" decimal money "回收价" decimal real_pro "中奖概率" int goods_type "1现货2预售3货币4宝箱" string prize_code "奖品编号" int addtime } GOODS_LOCK { int id PK int user_id FK string goods_id_num "商品ID_套数" int endtime "锁箱过期时间" int update_time } GOODS_EXTEND { int id PK int goods_id FK int pay_wechat "微信支付开关" int pay_balance "余额支付开关" int pay_currency "货币支付开关" int pay_coupon "优惠券支付开关" int is_deduction "是否抵扣" } ``` ## 5. 管理后台系统表关系图 ```mermaid erDiagram ADMIN_QUANXIAN ||--o{ ADMIN : "权限分配" ADMIN ||--o{ ADMIN_LOGIN_LOG : "登录日志" ADMIN ||--o{ ADMIN_OPERATION_LOG : "操作日志" ADMIN ||--o{ ADMIN_GOODS_LOG : "商品操作日志" ADMIN { int id PK string username "账号" string nickname "姓名" string password "密码" int qid FK "权限ID" int status "0正常1禁用" string token "登录token" int addtime } ADMIN_QUANXIAN { int id PK string title "权限名称" text describe "权限描述" text quanxian "权限配置JSON" int addtime } ADMIN_LOGIN_LOG { int id PK int a_id FK "管理员ID" string ip "登录IP" int addtime "登录时间" } ADMIN_OPERATION_LOG { int id PK int a_id FK "管理员ID" string ip "操作IP" string operation "操作控制器" text content "操作内容" int addtime "操作时间" } ADMIN_GOODS_LOG { int id PK int a_id FK "管理员ID" int goods_id "商品ID" int goods_list_id "奖品ID" text original_data "原始数据" text new_data "修改后数据" string ip "操作IP" int addtime "操作时间" } ``` ## 6. 数据表索引设计 ```sql -- 用户表索引 CREATE INDEX idx_user_phone ON user(phone); CREATE INDEX idx_user_openid ON user(openid); CREATE INDEX idx_user_share_uid ON user(share_uid); -- 商品表索引 CREATE INDEX idx_goods_category_id ON goods(category_id); CREATE INDEX idx_goods_type ON goods(type); CREATE INDEX idx_goods_status ON goods(status); CREATE INDEX idx_goods_addtime ON goods(addtime); -- 奖品表索引 CREATE INDEX idx_goods_list_goods_id ON goods_list(goods_id); CREATE INDEX idx_goods_list_num ON goods_list(num); CREATE INDEX idx_goods_list_shang_id ON goods_list(shang_id); CREATE INDEX idx_goods_list_real_pro ON goods_list(real_pro); CREATE INDEX idx_goods_list_surplus_stock ON goods_list(surplus_stock); CREATE INDEX idx_goods_list_prize_code ON goods_list(prize_code); -- 订单表索引 CREATE UNIQUE INDEX idx_order_order_num ON `order`(order_num); CREATE INDEX idx_order_user_id ON `order`(user_id); CREATE INDEX idx_order_goods_id ON `order`(goods_id); CREATE INDEX idx_order_status ON `order`(status); CREATE INDEX idx_order_addtime ON `order`(addtime); CREATE INDEX idx_order_pay_time ON `order`(pay_time); -- 中奖记录表索引 CREATE INDEX idx_order_list_user_id ON order_list(user_id); CREATE INDEX idx_order_list_order_id ON order_list(order_id); CREATE INDEX idx_order_list_goods_id ON order_list(goods_id); CREATE INDEX idx_order_list_goodslist_id ON order_list(goodslist_id); CREATE INDEX idx_order_list_status ON order_list(status); CREATE INDEX idx_order_list_prize_code ON order_list(prize_code); CREATE INDEX idx_order_list_addtime ON order_list(addtime); -- 财务记录表索引 CREATE INDEX idx_profit_money_user_id ON profit_money(user_id); CREATE INDEX idx_profit_money_type ON profit_money(type); CREATE INDEX idx_profit_money_addtime ON profit_money(addtime); -- 集市表索引 CREATE INDEX idx_market_user_id ON market(user_id); CREATE INDEX idx_market_status ON market(status); CREATE INDEX idx_market_addtime ON market(addtime); ``` ## 7. 数据库分表策略 ```mermaid graph TD subgraph "订单相关表分表策略" A1[order表] --> B1[按月分表order_202401] A1 --> B2[按月分表order_202402] A1 --> B3[按月分表order_202403] A2[order_list表] --> C1[按月分表order_list_202401] A2 --> C2[按月分表order_list_202402] A2 --> C3[按月分表order_list_202403] end subgraph "日志表分表策略" D1[admin_operation_log] --> E1[按月分表admin_operation_log_202401] D1 --> E2[按月分表admin_operation_log_202402] D2[admin_login_log] --> F1[按月分表admin_login_log_202401] D2 --> F2[按月分表admin_login_log_202402] end subgraph "财务表分表策略" G1[profit_money] --> H1[按月分表profit_money_202401] G1 --> H2[按月分表profit_money_202402] G2[profit_integral] --> I1[按月分表profit_integral_202401] G2 --> I2[按月分表profit_integral_202402] end ``` ## 8. 数据备份与恢复策略 ```mermaid graph TD subgraph "备份策略" A1[全量备份] --> B1[每日凌晨2点] A2[增量备份] --> B2[每4小时一次] A3[日志备份] --> B3[实时备份] end subgraph "存储策略" C1[本地存储] --> D1[保留7天] C2[远程存储] --> D2[保留30天] C3[归档存储] --> D3[保留1年] end subgraph "恢复策略" E1[热备恢复] --> F1[5分钟内] E2[温备恢复] --> F2[30分钟内] E3[冷备恢复] --> F3[2小时内] end B1 --> C1 B1 --> C2 B2 --> C1 B3 --> C1 C1 --> C2 C2 --> C3 D1 --> E1 D2 --> E2 D3 --> E3 ``` ## 数据库设计特点 ### 1. 业务特点适配 - 支持多种抽奖类型的数据结构 - 灵活的奖品配置和概率控制 - 完整的用户财务流水记录 ### 2. 性能优化 - 合理的索引设计提升查询效率 - 分表策略应对大数据量 - 读写分离支持高并发 ### 3. 数据完整性 - 外键约束保证数据一致性 - 事务支持确保操作原子性 - 完善的日志记录便于审计 ### 4. 扩展性设计 - 预留扩展字段支持功能升级 - 模块化表结构便于维护 - 标准化命名规范提升可读性 这个数据库设计充分考虑了抽奖盲盒系统的业务复杂性,在保证数据完整性的同时,也为系统的高性能和可扩展性提供了良好的基础。