I
I
itscoldhell2022-04-17 12:28:44
Database design
itscoldhell, 2022-04-17 12:28:44

How to make a daily bonus in PHP Mysql JS?

I am creating a website, I am new to the development of functionality.
There was a question with the creation of a daily bonus for users.
I searched on the Internet but could not find a more detailed code for implementing the bonus.

If it's not difficult for someone who can help write an example code of how the daily bonus works for users.

The site is written in Vuejs Laraval php musql

Answer the question

In order to leave comments, you need to log in

4 answer(s)
O
object_Object, 2022-04-17
@object_Object

I will not write the code, but I will describe how I personally implemented it. In a DB to the user put one more column (bonusTime). When registering, time() is put in this column. Then just when the page is displayed, the script checks whether 86400 seconds have elapsed. (24 hours) and if yes then gives pick up bonus. When a bonus is received, the bonusTime column is set back to time().

S
Slava Rozhnev, 2022-04-17
@rozhnev

Once a day, for example, at midnight, the Laravel Task Scheduler is launched, which adds a bonus depending on the specified conditions

T
ThunderCat, 2022-04-17
@ThunderCat

Write the date of the last issue to the database, when the user enters, count how many bonuses should have been accumulated, add to the bonuses, write the current date to the database.

O
oleg_ods, 2022-04-17
@oleg_ods

You can also store the date of registration in the database and count the number of full days that the user is registered.
Bonuses = (number of full days) * (number of bonuses per day);
If you can get something for bonuses, which would be logical, start a table of spent bonuses.
Accordingly, the formula for current bonuses takes the form:
Bonuses = (number of full days) * (number of bonuses per day) - (sum of spent bonuses);
This is for a situation where bonuses are awarded regardless of the user's activity.
PS Any use of cron or analogues will create a large load on the database at the time of recalculation of bonuses with an increase in the number of users. Although, if the number of bonus readings exceeds the number of accruals, this option has the right to life.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question