场景:
有4项:
30day pass
60day pass
180day pass
365day pass
有每月(30天)信用上限。因此,如果您在月底之前用完积分,则需要再购买 30 天通行证,或者等到下一个续订期。
一个人今天购买了 30 天的通行证,购买日期被记录到数据库中。有效期也被记录。
if ($todaysdate >= $expirydate) //DONE.
但是 60 天和 180 天的通行证呢?
我们已经购买了&到期日。每30天,下个月的信用需要重置。
我真的不知道如何最好地解决这个问题。
scenario:
there are 4 items:
30day pass
60day pass
180day pass
365day pass
there is a monthly (30 day) credit cap. so if you use the credit up before the end of the month you need to purchase another 30day pass, or wait till the next renewal period.
A person purchases a 30day pass today, purchase date is recorded to DB. Expiry date is also recorded.
if ($todaysdate >= $expirydate) //DONE.
but whAt about for 60day and 180day passes ?
we have purchasedate & expiry date. every 30days, the credit needs to be reset for the next month.
I am really lost how to best approach this problem.
发布评论
评论(4)
一种方法是使用 cron 和 mysql,
当您每天运行此 cron 时,
定义一个变量
,检查当天经过的查询,
返回的结果是从该日期起 30 天过去的所有成员。
one way to do that is with cron and mysql
when you run this cron every day
define a variable
check the day pass by query
the results that return is all the members that pass 30 days from the date.
您可以每天运行一个任务(或 cron 作业)来检查当前日期是否晚于记录的到期日期,以及是否将用户信用重置为 0,并向他们发送一封电子邮件,让他们知道他们的信用已过期。
当用户购买积分时,您只需将其到期日期添加 30、60 或 90 天。
有关更多信息,请参阅 php + cronjob 标签。
You could run a task (or cron job) daily to check and see if the current date is later than the recorded expiration date, and if it is reset the users credit to 0, and send them an email letting them know their credit has expired.
As the users buys credit, you merely add 30, 60 or 90 days to their expiration date.
For more information, see php + cronjob tags.
在您的情况下,您可以有一个像这样的表:
每天您都可以刷新任何已过期通行证上未使用的积分:
通过使用 end_time <= now() 您确保仅在到期日期过后才重置积分。因为您记得哪些遍被刷新,所以您可以根据需要多次运行它,并且错过一天不是问题(它将在下次运行时检测到)。
这实际上就是预付费电话卡的工作方式 - 您有一定的分钟数,该分钟数在 X(30/60/90 等)天内有效,并且分钟数在结束时重置。
顺便说一句,您可以通过使用易于使用的订阅管理系统(例如 recurly 或 chargify。
in your situation, you could have a table like this:
every day you can flush the unused credit on any pass that has expired:
by using end_time <= now() you ensure the credit is only reset once the expiration date has passed. since you remember which passes were flushed, you can run this as often as you like and missing a day is not an issue (it will be detected on the next run).
this is effectively how a prepaid calling card would work - you have a certain number of minutes that are valid for X (30/60/90 whatever) days and the minutes are reset at the end.
btw, you can simplify all that stuff by using an easy to use subscription management system like recurly or chargify.
或者,在数据库中,您可以为每个人保存自己的到期日期。
要设置到期日期,您应该使用 unix 时间戳。 30 天是 2592000,因此要查找到期日期,如果您想计算到期日期(用多少个月更改月份),可以使用类似以下内容。
然后,将这些值放入数据库中。
然后,您可以执行一些执行自动化任务的操作(例如 cron)。
当您运行该自动化任务时,您会检查当前时间戳(时间的另一种说法)是否大于到期日期。如果是这样,则更改数据库中该字段的值,以确定他们是否具有正确的学分。
Or, in the database, you can save each person has their own expiry date.
To make an expiry date, you should use a unix timestamp. 30 days is 2592000 so to find the expiry date, you could use something like the following if you want to calculate the expiry date (Changing months with how many months).
Then, put those values into a database.
Then, you can do something that does an automated task (for example, cron).
When you run that automated task, you check if the current timestamp (another word for time) is bigger then the expiry date. If so, then change the value in the database in the field for if they have the right credits.