You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

30 lines
762 B
PHP

<?php
namespace Workerman\Lib;
use Workerman\Worker;
$bot_loop = new Worker();
$bot_loop->count = 1;
$bot_loop->name = "OrderCancel";
function OrderCancelFunc()
{
$db = Db::get();
$order = $db->getRow("select * from user_orders
where status = 1
and created_at < '" . date('Y-m-d H:i:s', (time() - 60 * 60 * 2)) . "'
limit 1");
if (!!$order) {
$db->querysql("update user_orders set status = 3 where id = " . $order['id']);
$db->querysql("update appointments set used_count = used_count - 1 where id = " . $order['appointment']);
var_dump(date('Y-m-d H:i:s') . ' 取消订单[' . $order['id'] . ']');
}
}
$bot_loop->onWorkerStart = function () {
Timer::add(3, function () {
OrderCancelFunc();
});
};