Use
EcshopThe building of the mall, there is a demand, the user orders need to limit the payment within two hours, if not paid to cancel the order.
Originally thought is to do a cron timed sweep script , but this is not a permanent, but PHP is not like Java has multithreading .
How can we achieve this?
Reply content:
The mall built with Ecshop , there is a demand, the user orders need to limit the payment within two hours, if not paid to cancel the order.
Originally thought is to do a cron timed sweep script , but this is not a permanent, but PHP is not like Java has multithreading .
How can we achieve this?
PHP is trigger-type,
In other words, you first save the timestamp of the order generation, the Status field is 0,
To the payment page, the judgment timeout is not, if the time-out, the state is changed to 1, give the timeout prompt,
If there is no time-out, pay, change the status to 1, if the payment is successful, change the status to 2.
Don't know why to use crontab.
This time limit of two hours to pay, according to normal demand this does not have to be particularly punctual, up and down a few minutes or not related to it.
Then write a job that runs every 5 minutes.
Use the planning task directly.
Relatively rough:
Make a clear_ord.php, make a url_write, become a clear_ord.js.
Add random to the entry page, low probability, look at the number of user visits
Elegant:
Redis,memcache can all be solved.
The display of the unpaid and time more than two hours of display as canceled orders on the line.
The time is also judged on the page that constructs the payment information.
This is a bit like the expiration date of SMS verification code! Memcache Store the relevant payment information, set an expiration date is OK.
When you pay, judge the order generation time. Check the list of orders and then read the time to be OK.
General Practice:
Write a scheduled task on Linux to change the order status of the condition to canceled
@tiyee said is back-end verification, I add a little, you use the JS timer to do a countdown, users can see how much time left, you see the time, directly put the status to expire! ~
When submitting an order, record a time, pay, and then determine the current time minus the time of submission, if more than 2 hours, the prompt order has expired.
Database fields add a timestamp to create an order, see your own requirements You can also set the expiration timestamp (create order timestamp + 2 hour timestamp), and then read the order to determine the current timestamp and the database timestamp difference. You don't have to run a task regularly. A lot of systems are doing this.
When the order is generated, write to Redis with the order number key, set the cache time for two hours, collect the order information from the Redis when the payment operation, if not, do not allow payment, whether it can meet your needs
If you want to strictly implement the logic you want, you need to do timed tasks, you can use cron. If trickery, can be in the view of the order to modify the order status, to ensure that the right time to see the correct can be, pay attention to the best front and back to do the same logic.
There's a carbon bag in composer to use this.
To write a MySQL event:
Set GLOBAL Event_scheduler = on;
Create Event Event_canle
On schedule every 1 day
Starts Date_add (date (curdate () + 1), Interval 3 hour)
Do update order_info Set o_status = 2,finish_time = Unix_timestamp (now ())
Where ((Unix_timestamp (now ())-add_time) > 86400)
and pay_id in (2,3) and pay_status = 0;