It is easy to store user credit with an extra col in the user table, e.g. user_credits, now an extra requirement
- for each credit added to the
user_creditscol, it will auto expire one year after if not being consumed.
Definitely I need an extra table for storing expiring information, e.g.
[table credits_history]
user_id
credits
used
created_at
So, when consuming credits, I need to
- check if the
user_creditsis enough to consume - loop all
credits_historytable for the user's credit whichused = 0 AND now - created_at < 1yr, and setused to 1 - update the
user_credits
Finally I need to set a daily cron job to update user_credits by looking at the created_at
Are the above approach reasonable? Or any standard way to handle the above requirements?
Aucun commentaire:
Enregistrer un commentaire