<?php namespace process; use App\Utils\API\SendCode; use app\model\UserPhone; use app\dao\UserRewardDao; use Workerman\Crontab\Crontab; use app\model\GetLodeLog; use support\Log; /** * 查询用户是否在线类 */ class Task { public function onWorkerStart() { // 每1秒执行一次 收取验证码 new Crontab('*/1 * * * * *', function () { $GetLodeLog = GetLodeLog::where('status', 0)->get(); foreach ($GetLodeLog as $key => $value) { try { $res = SendCode::get_code($value->phone); // var_dump($res); if ($res['status'] == 1 && $res['scanCode'] != null) { $value->status = 1; $value->code = $res['scanCode']; $value->save(); } } catch (\Exception $e) { // 记录错误日志,避免任务中断 Log::error("Error processing phone {$value->phone}: " . $e->getMessage()); } } }); } }