search

Home  >  Q&A  >  body text

javascript - How to implement automatic refund function in php?

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?

曾经蜡笔没有小新曾经蜡笔没有小新2871 days ago707

reply all(5)I'll reply

  • 某草草

    某草草2017-05-16 13:05:45

    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.

    reply
    0
  • PHPz

    PHPz2017-05-16 13:05:45

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

    reply
    0
  • 某草草

    某草草2017-05-16 13:05:45

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

    reply
    0
  • phpcn_u1582

    phpcn_u15822017-05-16 13:05:45

    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

    reply
    0
  • 高洛峰

    高洛峰2017-05-16 13:05:45

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

    reply
    0
  • Cancelreply