VerifyWatchWorkOrderJob.php 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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. private $work_no;
  16. /**
  17. * Create a new job instance.
  18. *
  19. * @return void
  20. */
  21. public function __construct($work_no)
  22. {
  23. //
  24. $this->work_no = $work_no;
  25. }
  26. /**
  27. * Execute the job.
  28. *
  29. * @return void
  30. */
  31. public function handle()
  32. {
  33. //
  34. $work_order = WorkOrder::query()->where('work_no',$this->work_no)->first();
  35. if(empty($work_order)){
  36. Log::error('watch工单验证时,找不到工单内容,工单号为:'.$this->work_no);
  37. return ;
  38. }
  39. $bike_id = $work_order->bike_id;
  40. $bike = Bike::query()->find($bike_id);
  41. if(empty($bike)){
  42. Log::error('watch工单验证时,找不到工单车辆信息,工单号为:'.$this->work_no);
  43. return ;
  44. }
  45. if($bike->last_use_bike_end_time > Carbon::now()->subHours(36)){
  46. try{
  47. $work_order->status = WorkOrder::STATUS_OK;
  48. $work_order->planned = WorkOrder::PLANNED_STATUS_OVER;
  49. $work_order->fix_end_time = Carbon::now();
  50. $work_order->save();
  51. }catch (\Exception $e){
  52. Log::error('更新watch工单为结束状态失败'.$e->getMessage());
  53. }
  54. }else{
  55. // 未通过验证 改为未待处理状态
  56. try{
  57. $work_order->planned = WorkOrder::PLANNED_STATUS_WORK;
  58. $work_order->save();
  59. }catch (\Exception $e){
  60. Log::error('更新watch工单为待处理状态失败'.$e->getMessage());
  61. }
  62. }
  63. }
  64. }