setName('cancel_dispatch') ->setDescription('派单5分钟未领取的工单自动取消'); } protected function execute(Input $input, Output $output) { $this->cancelDispatch(); } /* * 超过5分钟未领取工单的,取消分配 */ protected function cancelDispatch() { $list = ServiceWork::where('work_status',1) ->where('dispatch_time','<',strtotime('-5 minutes')) ->where('dispatch_time','>=',strtotime('-1 days')) ->field('id,tenant_id,master_worker_id,appointment_time') ->limit(100) ->select() ->toArray(); foreach($list as $item) { ServiceWork::where('id',$item['id']) ->update([ 'master_worker_id' => 0, 'work_status' => 0, 'dispatch_time' => 0, 'first_contact_time' => 0, 'estimated_finish_time' => 0, ]); if ($item['tenant_id'] > 0) { $updateData = date("H",strtotime($item['appointment_time'])) < 12 ? ['am_order' => Db::raw('am_order - 1')] : ['pm_order' => Db::raw('pm_order - 1')]; MasterWorkerTeam::where('master_worker_id',$item['master_worker_id'])->where('tenant_id',$item['tenant_id'])->update($updateData); } } } }