The opening of vip and the renewal and upgrade!

now there is a project, and the demand is too painful!
the price of each type of vip, from vip1 to vip5, is different!

there is a data table in the backend that stores vip type vip_type
with vip type price (money) and grade (level)

now users write a record in vip_open in the activation table after purchase!

vip_open table field:

user_id --id
vip_id  -- vipid
open_time  --  ()
open_money --
open_length --  ()
end_time -- ()

then you can simply overlay the end_time when you renew it.

but it hurts when users upgrade!
refer to large-scale ones such as Baidu disk QQ VIP

they temporarily disable the previous one after upgrading, then write the vip data after the upgrade, and then disable it before it is enabled after the upgrade expires!
this way doesn"t feel good for my needs!
Please advise if there is any other way to upgrade directly!


first of all, the logic of copying big factories directly is not "stupid", but it is not normal either. It all depends on your specific needs. After seeing your question, I personally think that you just need a record sheet. The user records the user's actions on the vip table, such as upgrade, expiration, demotion, and so on. And the calculation method of upgrade is according to what you say, end_time+. All you have to do is record it over a period of time. The practice of "them" is actually to record all the actions of the user.


the problem with direct upgrade is that it is difficult to downgrade again. I think we should add a new piece of data, that is, multiple pieces coexist:

first of all, you have a piece of data that is [vip1,2019-05-30, valid]
and then he chooses to upgrade to vip3, then add a new piece of data [vip3,2019-05-30, valid]
if the user upgrades vip5, but only upgrades for 3 months, then add [vip5,2018-12-31, valid]

so there are three pieces of vip data.

1. How to determine the user's current vip level
take the highest one

2. How to downgrade when it expires?
you just need to brush the expiration date as invalid every day

.

make up the price difference. Suppose the first-level vip costs 10 yuan a month and the second-level vip20 yuan, and the user wants to upgrade from the first-level vip to the second-level vip,. If the current first-level vip still has 20 days to expire, then the price difference is (20-10) * (20 vip 30) = 6.66 yuan

.
MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1bd1226-30d3e.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1bd1226-30d3e.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?