S
S
Sergey Sokolov2017-03-27 09:44:21
Database
Sergey Sokolov, 2017-03-27 09:44:21

How to keep paid tariffs purchased by the user in the database?

There is a service where Free (B), Paid 1 (P1) and Paid 2 (P2) modes are available. (In fact, there are more tariffs)
At any time, the user can purchase one of the Paid modes for 1 month or more.
Maybe, without waiting for the expiration of P1, upgrade to a more expensive P2.
Tasks:

  1. At any time, quickly determine what mode the user currently has
  2. Warn the user during the visit about the need / possibility to renew the subscription for a week, a day, a day after, a week after.
  3. At the right time, switch the tariff for the user, autonomously, without his visit.

Questions:
  1. What is the best way to keep the current state of the user in the database? Probably, its active tariff and its expiration date.
  2. In the case of an upgrade, after the end of P2, it is logical to roll back first to the unused tail of P1, and only then to the Free one. What is the best way to implement this - keep only purchases in the database and recalculate once a day / 12 hours / hour?
  3. What is the best way to keep in the db (and is it necessary) a perspective? - for example, the date-time when the upgrade to P2 will end and there will be a rollback to the “tail” of the paid P1; and when that tail ends and rolls back to Free.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Draconian, 2017-03-27
@Draconian

DBMS was not specified.
In the general case, in my opinion, it will be something like this: Table of users (with the id of the currently
active tariff). By default, all users are free. Tariff table. Since one user can have many tariffs, NM connection, we need a connection table: user_tariff (user id, tariff id, start date, end time, is_active attribute) Jobs check users for active tariffs, if the time is up, change the tariff to that , which has time left, set the is_active flag to 0, change the active tariff in the users table. You can also keep a log of which user, when, from which to which tariff they transferred.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question