javascript - How to implement automatic refund function in php?
曾经蜡笔没有小新
曾经蜡笔没有小新 2017-05-16 13:03:45
0
5
634

I want to make an automatic refund function? For example, if no one responds to his content within three days after payment, he will automatically enter the refund process! But how to write this timed task? Should I run the PHP script every second or write a scheduled task in mysql?

曾经蜡笔没有小新
曾经蜡笔没有小新

reply all(5)
某草草

There are several options, each with pros and cons, see which one is more suitable for you:
The relevant table needs to set the order time field and expiration time field.
The first type: crontab scheduled task, execute a php script to scan the table, and if the expiration time minus the order time is more than three days, it will be changed to refund status.

Second method: Use mysql's scheduled tasks. The following is a demo. The specific logic can be written according to your own.

create event myevent
on schedule at current_timestamp + interval 1 hour (周期或者时间点)
do
update myschema.mytable set mycol = mycol + 1;     (执行的sql)

The third method: Use Redis to save, and the expiration time is 3 days when saving.

The first option
Advantages: Simple, the code logic does not change much, just use it after writing it
Disadvantages: The timeliness is not very good, because you must run the crontab task at a fixed time
The second option
Advantages: Direct Mysql is done, no other links are needed
Disadvantages: Similar to the advantages of crontab, and if you are not familiar with mysql scheduled tasks, you still need to familiarize yourself with it
The third option
Advantages: easy to use, good order timeliness, and you don’t have to go to mysql once io
Disadvantages: The logic layer code may need to add redis logic, and the persistence strategy, HA, and master-slave must be done well, otherwise a downtime will be tragic.

PHPzhong

Use Linux crontab scheduled tasks to run a fixed php script every once in a while~

某草草

Write a scheduled task and execute the php script every second.

phpcn_u1582

By delaying the message queue, register the writing task of the message queue after placing the order, and trigger it three days later; then write an interface to simply judge whether to perform a refund operation

小葫芦

Are refunds not subject to review? He also ran the script directly and broke the bank!

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template