onWorkerStart=function ($conn){ Timer::add(3,function (){ $orders= MobileOrder::expired()->field('id')->select(); self::log(sprintf('%d条数据',count($orders))); foreach ($orders as $order){ try { Db::startTrans(); $order=MobileOrder::where('id',$order['id'])->lock(true)->find(); $order->cancel(); Db::commit(); }catch (\Exception $e){ Db::rollback(); Log::error("关闭订单[$order->id]失败:{$e->getMessage()}"); } } }); }; } } MobileOrderExpired::run();