count = 1; $bot_loop->name = 'OrderCancel'; function OrderCancel() { Tool::log('开始执行任务', 2); $url = Tool::ini('ORDER_CANCEL'); $res = Tool::post($url); Tool::log(json_encode($res, JSON_UNESCAPED_UNICODE), 2); } function OrderCancelFunc() { $db = Db::get(); $order_cancel_count = $db->getRow("select count(1) as c from orders where status = ? and created_at < ?", [ 1, date('Y-m-d H:i:s', time() - 60 * 20) ]); if ($order_cancel_count['c'] > 0) { OrderCancel(); } else { Tool::log('未检测到任务'); } } $bot_loop->onWorkerStart = function () { OrderCancelFunc(); Timer::add(10, function () { OrderCancelFunc(); }); };