setName('check:dispatch-record-notice') ->setDescription('dispatch跟进记录通知,每天9点1分执行'); } protected function execute(Input $input, Output $output){ $Model = new OrderDispatchRecord(); $now = date('Y-m-d H:i:s'); //创建三十分名以上未接的任务 //$Model->where('need_notice',1) $Model->where('notice_time','<=',$now) ->where('status',0) ->chunk(100, function ($list) { $ids = []; $dispatchIds = []; foreach ($list as $item) { $ids[] = $item->id; $dispatchIds[] = $item->dispatch_id; //修改状态 if($item->need_notice == 1){ //需要通知 $dispatch = OrderDispatch::get($item->dispatch_id,['orderb']); Message::create([ 'to_id' => $dispatch->admin_id, 'type' => 1, 'title' => '派单任务跟进提示', 'content' => '【订单跟进提示】您有一条待跟进订单,订单编号:'.$dispatch->orderb->order_no.',请及时关注。' ]); } } OrderDispatchRecord::whereIn('id',$ids)->where('status',0)->update(['status'=>1]); OrderDispatch::whereIn('id',$dispatchIds)->where('follow',1)->update(['follow'=>0]); }); $output->info('OVER'); } }