points_record (积分表)
user_id (用户ID)
point (点数)
used (已使用了多少)
expire (截止日期)
Every time a point is earned, a record is added to this table
When points are consumed, the value of used is updated
Get points (this is pseudo code):
INSERT user_id=id, point=point, used=0, expire=now() 30 days
Use points:
1. Get all available points first and sort them by deadline:
SELECT user_id=id, expire > now(), point > used ORDER_BY expire
2. Calculate sum( point - used ) to see if the available points are enough
3. If the available points are enough, update the used value in each record in turn until the points to be used are deducted
Every time a point is earned, a record is added to this table
When points are consumed, the value of used is updated
Get points (this is pseudo code):
INSERT user_id=id, point=point, used=0, expire=now() 30 days
Use points:
1. Get all available points first and sort them by deadline:
SELECT user_id=id, expire > now(), point > used ORDER_BY expire
2. Calculate sum( point - used ) to see if the available points are enough
3. If the available points are enough, update the used value in each record in turn until the points to be used are deducted