AutoRepairWorkOrderCommand.php 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. <?php
  2. namespace App\Console\Commands;
  3. use App\Models\Bike;
  4. use App\Models\WorkOrder;
  5. use Carbon\Carbon;
  6. use Illuminate\Console\Command;
  7. use Illuminate\Support\Facades\Log;
  8. class AutoRepairWorkOrderCommand extends Command
  9. {
  10. /**
  11. * The name and signature of the console command.
  12. *
  13. * @var string
  14. */
  15. protected $signature = 'auto_repair:work_order';
  16. /**
  17. * The console command description.
  18. *
  19. * @var string
  20. */
  21. protected $description = '系统自动修复工单';
  22. /**
  23. * Create a new command instance.
  24. *
  25. * @return void
  26. */
  27. public function __construct()
  28. {
  29. parent::__construct();
  30. }
  31. /**
  32. * Execute the console command.
  33. *
  34. * @return mixed
  35. */
  36. public function handle()
  37. {
  38. // 离线工单
  39. $workOrder = WorkOrder::query()
  40. ->where('type',WorkOrder::TYPE_OFFLINE)
  41. ->where('status',WorkOrder::STATUS_NO)
  42. ->get();
  43. if(count($workOrder) == 0) return ;
  44. foreach ($workOrder as $v){
  45. $bike_no = $v->bike_no;
  46. $bike = Bike::query()->where('bike_no',$bike_no)->first();
  47. if($bike->is_link == Bike::LOCK_YES){
  48. $this->overWorkOrder($v->id);
  49. }
  50. }
  51. }
  52. /**
  53. * 完结工单
  54. * @param $workOrderId int 工单id
  55. * */
  56. private function overWorkOrder($workOrderId){
  57. try{
  58. $work_order = WorkOrder::find($workOrderId);
  59. $work_order->planned = WorkOrder::PLANNED_STATUS_OVER;
  60. $work_order->status = WorkOrder::STATUS_OK;
  61. $work_order->fix_start_time = Carbon::now();
  62. $work_order->worker_id = 0;
  63. $work_order->work_over_id = 0;
  64. $work_order->fix_end_time = Carbon::now();
  65. $work_order->save();
  66. }catch (\Exception $e){
  67. Log::error($e->getMessage());
  68. }
  69. }
  70. }