Home  >  Article  >  Backend Development  >  Regarding the design and distribution of gift packs, how to automatically update the number of gift packs the next day? How to design the database?

Regarding the design and distribution of gift packs, how to automatically update the number of gift packs the next day? How to design the database?

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

Suppose I set a total of 1,000 gift packs to be distributed, 100 per day. Regardless of whether all 100 gift packs are received on that day, the number of remaining gift packs will be re-calculated. Starting from the next day, if there are enough 100 gift packs left, the number of gift packs distributed on that day will be the same. The new number is 100. If it is less than 100, the current number of gift packs will be distributed until all gift packs are claimed.
The problem is, how do I automatically update the quantity on the next day? Obtaining the time is a problem. I should store a time field in the database, but the automatic update of the time is a problem. I don’t know if you understand what I mean?

Reply content:

Suppose I set a total of 1,000 gift packs to be distributed, 100 per day. Regardless of whether all 100 gift packs are received on that day, the number of remaining gift packs will be re-calculated. Starting from the next day, if there are enough 100 gift packs left, the number of gift packs distributed on that day will be the same. The new number is 100. If it is less than 100, the current number of gift packs will be distributed until all gift packs are claimed.
The problem is, how do I automatically update the quantity on the next day? Obtaining the time is a problem. I should store a time field in the database, but the automatic update of the time is a problem. I don’t know if you understand what I mean?

You made yourself faint

Total field of database records

Every time when sending out, it will be judged whether 100 items have been sent out today, and if it has not exceeded, it will be sent out. Where can I tell you when it will be automatically updated?

Configuration table

id primary key id
title gift pack name
nums total number of gift packs issued
day_nums total number of daily issues
max_data event end time
ext extension field (you can record the use of the gift pack, because I don’t know what function your gift pack has)

Gift package distribution log table

id primary key
lb_id gift package primary key
uid user id
on_time time

php

//Determine whether 100 gift bags have been distributed today
(select count(*) from logs where on_time = ".date("Y-m-d",time()).")
~Yes
// No distribution
~ No
//Determine whether the user has received the gift package today
(select * from logs where uid=$uid and on_time = ".date("Y-m-d",time()).")

<code>  ~是
  不发放
  ~否
   // 礼包配置数减1
   // 写入礼包发放日志表
</code>

Don’t you have a job?

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