setName('check:dispatch-sms-plant') ->setDescription($this->title); } protected function execute(Input $input, Output $output){ $Model = new OrderDispatch(); $now = date('Y-m-d H:i:s'); //两小时通知 $afterTwoHours = date('Y-m-d H:i:s', strtotime('+2 hours')); $Model->whereIn('status',[OrderDispatch::STATUS_PLANIT,OrderDispatch::STATUS_OVERTIME]) ->where('plan_time','between',[$now,$afterTwoHours]) ->where('notice_num','<',3) ->chunk(100, function ($list){ $ids = []; foreach ($list as $item) { $ids[] = $item->id; try { SendMailLogic::sendToWorker($item->worker_tel); }catch (Exception $exception){ echo '短信发送失败:'.$exception->getMessage().PHP_EOL; Db::name('debug_log')->insert([ 'title' => $this->title, 'content' => '错误内容:'.$exception->getMessage().',错误行:'. $exception->getLine().',错误文件:'. $exception->getFile(), 'create_time' => date('Y-m-d H:i:s', time()) ]); } echo '短信发送完成:'.$item->id.PHP_EOL; } if(!empty($ids)){ OrderDispatch::whereIn('id',$ids)->update(['notice_num'=>3,'notice_time'=>date('Y-m-d H:i:s')]); } }); $output->info('OVER'); } }