VerifyWatchWorkOrderJob.php 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. <?php
  2. namespace App\Jobs;
  3. use App\Models\Bike;
  4. use App\Models\WorkOrder;
  5. use Carbon\Carbon;
  6. use Illuminate\Bus\Queueable;
  7. use Illuminate\Queue\SerializesModels;
  8. use Illuminate\Queue\InteractsWithQueue;
  9. use Illuminate\Contracts\Queue\ShouldQueue;
  10. use Illuminate\Foundation\Bus\Dispatchable;
  11. use Illuminate\Support\Facades\Log;
  12. class VerifyWatchWorkOrderJob implements ShouldQueue
  13. {
  14. use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
  15. public $tries = 5;
  16. private $work_no;
  17. /**
  18. * Create a new job instance.
  19. *
  20. * @return void
  21. */
  22. public function __construct($work_no)
  23. {
  24. //
  25. $this->work_no = $work_no;
  26. }
  27. /**
  28. * Execute the job.
  29. *
  30. * @return void
  31. */
  32. public function handle()
  33. {
  34. //
  35. $work_order = WorkOrder::query()->where('work_no',$this->work_no)->first();
  36. if(empty($work_order)){
  37. Log::error('watch工单验证时,找不到工单内容,工单号为:'.$this->work_no);
  38. return ;
  39. }
  40. $bike_id = $work_order->bike_id;
  41. $bike = Bike::query()->find($bike_id);
  42. if(empty($bike)){
  43. Log::error('watch工单验证时,找不到工单车辆信息,工单号为:'.$this->work_no);
  44. return ;
  45. }
  46. if($bike->last_use_bike_end_time > Carbon::now()->subHours(36)){
  47. try{
  48. $work_order->status = WorkOrder::STATUS_OK;
  49. $work_order->planned = WorkOrder::PLANNED_STATUS_OVER;
  50. $work_order->fix_end_time = Carbon::now();
  51. $work_order->save();
  52. }catch (\Exception $e){
  53. Log::error('更新watch工单为结束状态失败'.$e->getMessage());
  54. }
  55. }else{
  56. // 未通过验证 改为未待处理状态
  57. try{
  58. $work_order->planned = WorkOrder::PLANNED_STATUS_WORK;
  59. $work_order->save();
  60. }catch (\Exception $e){
  61. Log::error('更新watch工单为待处理状态失败'.$e->getMessage());
  62. }
  63. }
  64. }
  65. }