Home  >  Article  >  Backend Development  >  How to implement a function similar to gift reminder?

How to implement a function similar to gift reminder?

WBOY
WBOYOriginal
2016-08-04 09:21:401144browse

To make a similar function:
For example, set a date on the 20th of every month, and remind the user to give gifts a few days before this date.
The date can be set to the day of the month, the day of the month, etc. Can the reminder time be a reminder for the current day, a reminder for the previous week, etc.?

How to design the backend database with this kind of function? How many tables are needed? Now that the message push function is available, how to detect when it will be pushed? Write a scheduled task in the background to run continuously?

Reply content:

To make a similar function:
For example, set a date on the 20th of every month, and remind the user to give gifts a few days before this date.
The date can be set to the day of the month, the day of the month, etc. Can the reminder time be a reminder for the current day, a reminder for the previous week, etc.?

How to design the backend database for this kind of function? How many tables are needed? Now that the message push function is available, how to detect when it will be pushed? Write a scheduled task in the background to run continuously?

Two scheduled tasks, three tables
1. Gift table, which contains fields for when to send and whether to send. 2. Message table, whether to send, what is sent, and to whom
3. Message person table, each Extract personal messages
Task one, scan the task table, if it has not been sent and the time is up, insert a piece of data into the message table
Task two, scan the message table, if there is a message, send it according to the system,,,,, he is a A public watch is not necessarily used for giving out gifts

It is necessary to judge the application environment, during web access, and when users access it.

Several tables are needed to see your specific business needs. One information table with uncomplicated business needs is enough. If you set up timing, you definitely need to set up a script. Or you can use a third party to push Jiguang Push

Data Dictionary

1 The user information table uses the field is_accept to store whether the user has enabled message prompts

2 Create a message push configuration table

id primary key
task_obj extended field
title title
content content
on_time end time
status whether the platform enables message prompts
days reminder a few days in advance (this field can also be set for the user, user information exists Table, let the user decide when to prompt him)
tips how many times to push
interval_time push interval (how often does the same user push)
3 message push log table
id primary key id
uid user id
tid message configuration id
on_time send Push time

4 php business logic

//Get all users whose user table is_accept is 1 loop

<code> foreach{
      //获取推送配置信息表
      //判断用户是否已推送,
      //判断 当前时间-用户上次推送时间>=配置间隔时间
      //判断是否已达到最大推送次数
      //写入推送记录表
      }</code>
5 Implementation

If it is a Linux system, it is recommended to use the system command curl
For a Windows system, it is recommended to write the process daemon yourself, or use urlcron

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn