| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465 |
- <?php
- namespace app\common\command;
- use think\facade\Db;
- use think\console\Input;
- use think\console\Output;
- use think\console\Command;
- use app\common\model\works\ServiceWork;
- use app\common\model\master_worker\MasterWorkerTeam;
- use app\common\model\works\ServiceWorkAnomalous;
- class CancelDispatch extends Command
- {
- protected function configure()
- {
- $this->setName('cancel_dispatch')
- ->setDescription('派单10分钟未领取的工单自动取消');
- }
- protected function execute(Input $input, Output $output)
- {
- $this->cancelDispatch();
- }
- /*
- * 超过10分钟未领取工单的,取消分配
- */
- protected function cancelDispatch()
- {
- $list = ServiceWork::where('work_status',1)
- ->where('dispatch_time','<',strtotime('-10 minutes'))
- ->where('dispatch_time','>=',strtotime('-1 days'))
- ->field('id,tenant_id,master_worker_id,appointment_time,exec_num')
- ->limit(100)
- ->select()
- ->toArray();
- foreach($list as $item) {
- ServiceWork::where('id',$item['id'])
- ->update([
- 'master_worker_id' => 0,
- 'tenant_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);
- }
- //自动派单2次后,标记工单异常
- if ($item['exec_num'] >= 2) {
- ServiceWorkAnomalous::create([
- 'work_id' => $item['id'],
- 'reason_type' => 2,
- 'reason' => '自动派单:2次无人接单',
- ]);
- }
- }
-
- }
- }
|