CancelDispatch.php 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. <?php
  2. namespace app\common\command;
  3. use think\facade\Db;
  4. use think\console\Input;
  5. use think\console\Output;
  6. use think\console\Command;
  7. use app\common\model\works\ServiceWork;
  8. use app\common\model\master_worker\MasterWorkerTeam;
  9. use app\common\model\works\ServiceWorkAnomalous;
  10. class CancelDispatch extends Command
  11. {
  12. protected function configure()
  13. {
  14. $this->setName('cancel_dispatch')
  15. ->setDescription('派单10分钟未领取的工单自动取消');
  16. }
  17. protected function execute(Input $input, Output $output)
  18. {
  19. $this->cancelDispatch();
  20. }
  21. /*
  22. * 超过10分钟未领取工单的,取消分配
  23. */
  24. protected function cancelDispatch()
  25. {
  26. $list = ServiceWork::where('work_status',1)
  27. ->where('dispatch_time','<',strtotime('-10 minutes'))
  28. ->where('dispatch_time','>=',strtotime('-1 days'))
  29. ->field('id,tenant_id,master_worker_id,appointment_time,exec_num')
  30. ->limit(100)
  31. ->select()
  32. ->toArray();
  33. foreach($list as $item) {
  34. ServiceWork::where('id',$item['id'])
  35. ->update([
  36. 'master_worker_id' => 0,
  37. 'tenant_id' => 0,
  38. 'work_status' => 0,
  39. 'dispatch_time' => 0,
  40. 'first_contact_time' => 0,
  41. 'estimated_finish_time' => 0,
  42. ]);
  43. if ($item['tenant_id'] > 0) {
  44. $updateData = date("H",strtotime($item['appointment_time'])) < 12 ? ['am_order' => Db::raw('am_order - 1')] : ['pm_order' => Db::raw('pm_order - 1')];
  45. MasterWorkerTeam::where('master_worker_id',$item['master_worker_id'])->where('tenant_id',$item['tenant_id'])->update($updateData);
  46. }
  47. //自动派单2次后,标记工单异常
  48. if ($item['exec_num'] >= 2) {
  49. ServiceWorkAnomalous::create([
  50. 'work_id' => $item['id'],
  51. 'reason_type' => 2,
  52. 'reason' => '自动派单:2次无人接单',
  53. ]);
  54. }
  55. }
  56. }
  57. }