setName('check:dispatch-sms-plant') ->setDescription('dispatch已预约任务短信提醒,每小时执行一次'); } 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; } 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'); } }