preface

In the previous article, “Requirement Analysis of a Universal lottery Tool”, we have identified the five elements of a lottery tool that meet the requirements of some common lottery scenarios:

Five elements of the draw Name of the element
The first element activity
The second element session
The third element The prize
The fourth element The odds
The fifth element Even for prize

And the 5 basic steps to create a sweepstakes are as follows:

  1. Active configuration
  2. Session configuration
  3. The prize configuration
  4. Prize winning probability configuration
  5. Prize casting configuration

Review of “Requirements Analysis for Universal Lottery Tools”

Requirements have been analyzed, today we will look at the specific design of the universal lottery tool, divided into the following three parts:

  • The DB design
  • Configuration Background Design
  • Interface design

The DB design

Lottery table of the first element activity configuration:

-- Universal lottery tool (universal Glue
CREATE TABLE `glue_activity` (
    `id` int(11) unsigned NOT NULL AUTO_INCREMENT COMMENT 'activity ID'.`serial_no` char(16) unsigned NOT NULL DEFAULT ' ' COMMENT 'Activity number (middle 16 digits of MD5 value)'.`name` varchar(255) unsigned NOT NULL DEFAULT ' ' COMMENT 'Activity Name'.`description` varchar(255) unsigned NOT NULL DEFAULT ' ' COMMENT 'Activity Description'.`activity_type` tinyint(1) unsigned NOT NULL DEFAULT '1' COMMENT 'Activity Lucky Draw Type 1: Time lucky Draw 2: Number of lucky draw 3: Amount Range lucky draw'.`probability_type` tinyint(1) unsigned NOT NULL DEFAULT '1' COMMENT 'Probability type 1: static 2: dynamic'.`times_limit` tinyint(3) unsigned NOT NULL DEFAULT '0' COMMENT 'Limit on lucky draw times, 0 default no limit'.`start_at` int(11) unsigned NOT NULL DEFAULT '0' COMMENT 'Activity Start Time'.`end_at` int(11) unsigned NOT NULL DEFAULT '0' COMMENT 'Event End Time'.`create_at` int(11) unsigned NOT NULL DEFAULT '0' COMMENT 'Creation time'.`create_by` int(11) unsigned NOT NULL DEFAULT '0' COMMENT 'staff_id'.`update_at` int(11) unsigned NOT NULL DEFAULT '0' COMMENT 'Update Time'.`update_by` int(11) unsigned NOT NULL DEFAULT '0' COMMENT 'Modifier staff_id'.`status` tinyint(1)  NOT NULL DEFAULT '0' COMMENT 'Status -1: Deleted, 0:disable, 1:enable',
    PRIMARY KEY (`id`))ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='Lucky Draw Form';
Copy the code

Table of lucky draw of the second factor:

Glue_session List of lottery times
CREATE TABLE `glue_session` (
    `id` int(11) unsigned NOT NULL AUTO_INCREMENT COMMENT 'session ID'.`activity_id` int(11) unsigned NOT NULL DEFAULT '0' COMMENT 'activity ID'.`times_limit` tinyint(3) unsigned NOT NULL DEFAULT '0' COMMENT 'Limit on lucky draw times, 0 default no limit'.`start_at` int(11) unsigned NOT NULL DEFAULT '0' COMMENT 'Session Start time'.`end_at` int(11) unsigned NOT NULL DEFAULT '0' COMMENT 'End of Session'.`create_at` int(11) unsigned NOT NULL DEFAULT '0' COMMENT 'Creation time'.`create_by` int(11) unsigned NOT NULL DEFAULT '0' COMMENT 'staff_id'.`update_at` int(11) unsigned NOT NULL DEFAULT '0' COMMENT 'Update Time'.`update_by` int(11) unsigned NOT NULL DEFAULT '0' COMMENT 'Modifier staff_id'.`status` tinyint(1)  NOT NULL DEFAULT '0' COMMENT 'Status -1: Deleted, 0:disable, 1:enable',
    PRIMARY KEY (`id`))ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='Lucky Draw Schedule';
Copy the code

Prize table of lucky draw for the third and fourth element prize configuration:

Prize list of lucky draw sessions
CREATE TABLE `glue_session_prizes` (
    `id` int(11) unsigned NOT NULL AUTO_INCREMENT COMMENT 'on the ID'.`session_id` int(11) unsigned NOT NULL DEFAULT '0' COMMENT 'session ID'.`node` varchar(255) unsigned NOT NULL DEFAULT ' ' COMMENT 'Node identifier By time lucky draw: null value, by number of lucky draw: number of participating value, by amount range lucky draw: Upper limit of amount range'.`prize_type` int(11) unsigned NOT NULL DEFAULT '0' COMMENT Type of prize 1: coupon, 2: Points, 3: physical, 4: empty prize... '.`name` varchar(255) unsigned NOT NULL DEFAULT ' ' COMMENT 'Prize Name'.`pic_url` varchar(255) unsigned NOT NULL DEFAULT ' ' COMMENT 'Picture of prize'.`value` varchar(255) unsigned NOT NULL DEFAULT ' ' COMMENT 'Prize abstract value Coupon: Coupon ID, Integral: Integral value, object: SKU ID'.`probability` tinyint(3) unsigned NOT NULL DEFAULT '0' COMMENT 'Probability of winning 1~100'.`create_at` int(11) unsigned NOT NULL DEFAULT '0' COMMENT 'Creation time'.`create_by` int(11) unsigned NOT NULL DEFAULT '0' COMMENT 'staff_id'.`update_at` int(11) unsigned NOT NULL DEFAULT '0' COMMENT 'Update Time'.`update_by` int(11) unsigned NOT NULL DEFAULT '0' COMMENT 'Modifier staff_id'.`status` tinyint(1)  NOT NULL DEFAULT '0' COMMENT 'Status -1: Deleted, 0:disable, 1:enable',
    PRIMARY KEY (`id`))ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='Lucky Draw Prize List';

Copy the code

The fifth element of uniform prize lottery time prize delivery table:

-- Glue_session_prizes_timer List of prize timing for lucky draw
CREATE TABLE `glue_session_prizes_timer` (
    `id` int(11) unsigned NOT NULL AUTO_INCREMENT COMMENT 'on the ID'.`session_prizes_id` int(11) unsigned NOT NULL DEFAULT '0' COMMENT 'Lucky Draw Prize ID'.`delivery_at` int(11) unsigned NOT NULL DEFAULT '0' COMMENT 'Timing of prize Delivery'.`prize_quantity` tinyint(3) unsigned NOT NULL DEFAULT '0' COMMENT 'Number of prizes'.`create_at` int(11) unsigned NOT NULL DEFAULT '0' COMMENT 'Creation time'.`create_by` int(11) unsigned NOT NULL DEFAULT '0' COMMENT 'staff_id'.`update_at` int(11) unsigned NOT NULL DEFAULT '0' COMMENT 'Update Time'.`update_by` int(11) unsigned NOT NULL DEFAULT '0' COMMENT 'Modifier staff_id'.`status` tinyint(1)  NOT NULL DEFAULT '0' COMMENT 'Status -1:deleted, 0:wait, 1:success',
    PRIMARY KEY (`id`))ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='Timing Slot for Lucky Draw Prizes';

Copy the code

Other forms, Lottery Records & Prize Distribution Records:

-- Universal lottery tool (Glue) GLUe_user_draw_record User lottery record
CREATE TABLE `glue_user_draw_record` (
    `id` int(11) unsigned NOT NULL AUTO_INCREMENT COMMENT 'on the ID'.`activity_id` int(11) unsigned NOT NULL DEFAULT '0' COMMENT 'activity ID'.`session_id` int(11) unsigned NOT NULL DEFAULT '0' COMMENT 'session ID'.`prize_type_id` int(11) unsigned NOT NULL DEFAULT '0' COMMENT 'Prize Type ID'.`user_id` int(11) unsigned NOT NULL DEFAULT '0' COMMENT 'creator user_id'.`create_at` int(11) unsigned NOT NULL DEFAULT '0' COMMENT 'Creation time'.`update_at` int(11) unsigned NOT NULL DEFAULT '0' COMMENT 'Update Time'.`status` tinyint(1)  NOT NULL DEFAULT '0' COMMENT 'Status -1: not winning, 1: Already winning, 2: Failed to award, 3: Already awarded'.`log` text COMMENT 'Records of operation information',
    PRIMARY KEY (`id`))ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='User Lucky Draw Record Form';
Copy the code

Configuration Background Design

Create activities

Create event – draw by amount range

List of activities

Interface design

  1. GET {version}/glue/activity

Request parameters:

field type Whether will pass describe
serial_no string Y Activity number

Response content:

{
    "code": "200"."msg": "OK"."result": {
        "serial_no": "String, activity number"."type": "Number, active lucky draw type 1: time lucky draw 2: Number lucky draw 3: Range lucky draw"."name": "String, activity name"."description": "String, activity description"."start_time": "Number, start time"."end_time": "Number, start time"."remaining_times": "Number, no limit on the number of lucky draws."."sessions_list":[
            {
                "start_time": "Number, start time"."end_time": "Number, start time"."remaining_times": "Number, no limit on the number of lucky draw times."."prizes_list": [{"name": "String, prize name"."pic_url": "String, picture of the prize"}]}}Copy the code
  1. Lottery POST {version} / glue/activity/the draw

Request parameters:

field type Whether will pass describe
serial_no string Y Activity number
uid number Y The user ID

Response content:

/ / winning {" code ":" 200 ", "MSG" : "OK", "result" : {" serial_no ":" string, spu id ", "act_remaining_times" : "Session_remaining_times ": "number, remaining_remaining_times ", "prizes_info": {"name": {"name": { "String, the award name", "pic_url" : "string, prize images"}}} / / not winning {" code ":" 401 ", "MSG" : ""," result ": {}}Copy the code

conclusion

Activity marketing system in the first word system universal lottery tool finished today, we hope to have a certain help or inspiration.

eggs

The code design of the universal lottery tool is particularly suitable for the template pattern in design pattern, don’t you think 😏😏😏. So, will I write another “Code Design for the [SKR-Shop] Universal lottery Tool” in the New Year?

(O_O)?

2020

Finally, happy New Year 2020 🆕 ~


[Skr Shop] Project address long press to enter: github.com/skr-shop/ma…


Skr Shop Series

  • System design of Skr Shop universal lottery tool
  • Skr Shop shopping cart design requirements analysis
  • Coder, can you design a trading system?
  • Coder, can you design a trading system?
  • Third party payment process analysis and summary
  • Basic product information of e-commerce design manual
  • User system of e-commerce design manual