CancelDispatch.php 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  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. class CancelDispatch extends Command
  10. {
  11. protected function configure()
  12. {
  13. $this->setName('cancel_dispatch')
  14. ->setDescription('派单10分钟未领取的工单自动取消');
  15. }
  16. protected function execute(Input $input, Output $output)
  17. {
  18. $this->cancelDispatch();
  19. }
  20. /*
  21. * 超过10分钟未领取工单的,取消分配
  22. */
  23. protected function cancelDispatch()
  24. {
  25. $list = ServiceWork::where('work_status',1)
  26. ->where('dispatch_time','<',strtotime('-10 minutes'))
  27. ->where('dispatch_time','>=',strtotime('-1 days'))
  28. ->field('id,tenant_id,master_worker_id,appointment_time')
  29. ->limit(100)
  30. ->select()
  31. ->toArray();
  32. foreach($list as $item) {
  33. ServiceWork::where('id',$item['id'])
  34. ->update([
  35. 'master_worker_id' => 0,
  36. 'tenant_id' => 0,
  37. 'work_status' => 0,
  38. 'dispatch_time' => 0,
  39. 'first_contact_time' => 0,
  40. 'estimated_finish_time' => 0,
  41. 'exec_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. }
  48. }
  49. }