setName('check:dispatch-tts-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('+1 hours')); $Model->where('status','=',OrderDispatch::STATUS_PLANIT) ->where('type','=',2) ->where('plan_time','between',[$now,$afterTwoHours]) ->where('tts_notice','<',2) ->chunk(100, function ($list) { $ids = []; $logs = []; foreach ($list as $item) { try { $ids[] = $item->id; //修改状态 $logs[] = [ 'dispatch_id' => $item->id, 'order_id'=>$item->order_id, 'mobile' => $item->worker_tel, 'type' => 2, 'outid' => md5(time().rand(1000,9999).rand(1000,9999)), 'create_time' => date('Y-m-d H:i:s'), 'status' => 0, 'update_time' => date('Y-m-d H:i:s') ]; (new TtsLog())->insertAll($logs); }catch (Exception $exception){ 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()) ]); } } if(!empty($ids)){ $count = OrderDispatch::whereIn('id',$ids)->update(['tts_notice'=>2,'tts_check_time'=>date('Y-m-d H:i:s')]); echo $count.PHP_EOL; } }); $output->info('OVER'); } }