# 第04节:抽奖活动策略库表设计

作者:小傅哥
博客:https://bugstack.cn (opens new window)

沉淀、分享、成长,让自己和他人都能有所收获!

# 一、需要建哪些表

一个满足业务需求的抽奖系统,需要提供抽奖活动配置、奖品概率配置、奖品梳理配置等内容,同时用户在抽奖后需要记录用户的抽奖数据,这就是一个抽奖活动系统的基本诉求。

那么为了满足这个诉求,我们可以提供表包括:

  • 活动配置,activity:提供活动的基本配置
  • 策略配置,strategy:用于配置抽奖策略,概率、玩法、库存、奖品
  • 策略明细,strategy_detail:抽奖策略的具体明细配置
  • 奖品配置,award:用于配置具体可以得到的奖品
  • 用户参与活动记录表,user_take_activity:每个用户参与活动都会记录下他的参与信息,时间、次数
  • 用户活动参与次数表,user_take_activity_count:用于记录当前参与了多少次
  • 用户策略计算结果表,user_strategy_export_001~004:最终策略结果的一个记录,也就是奖品中奖信息的内容

# 二、建表语句

# 1. lottery.sql

create database lottery;

-- auto-generated definition
create table activity
(
    id            bigint auto_increment comment '自增ID',
    activityId    bigint       null comment '活动ID',
    activityName  varchar(64)  not null comment '活动名称',
    activityDesc  varchar(128) null comment '活动描述',
    beginDateTime datetime     not null comment '开始时间',
    endDateTime   datetime     not null comment '结束时间',
    stockCount    int          not null comment '库存',
    takeCount     int          null comment '每人可参与次数',
    state         int          null comment '活动状态:编辑、提审、撤审、通过、运行、拒绝、关闭、开启',
    creator       varchar(64)  not null comment '创建人',
    createTime    datetime     not null comment '创建时间',
    updateTime    datetime     not null comment '修改时间',
    constraint activity_id_uindex
        unique (id)
)
    comment '活动配置';
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21