VerifyRealOffLineWorkOrderJob.php 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. <?php
  2. namespace App\Jobs;
  3. use App\Models\Bike;
  4. use App\Models\WarningLog;
  5. use App\Models\WorkOrder;
  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. // 验证是否真正长时间离线
  13. class VerifyRealOffLineWorkOrderJob implements ShouldQueue
  14. {
  15. use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
  16. private $warning_id;
  17. /**
  18. * Create a new job instance.
  19. *
  20. * @return void
  21. */
  22. public function __construct($warning_id)
  23. {
  24. //
  25. $this->warning_id = $warning_id;
  26. }
  27. /**
  28. * Execute the job.
  29. *
  30. * @return void
  31. */
  32. public function handle()
  33. {
  34. $warning = WarningLog::find($this->warning_id);
  35. if(empty($warning)) {
  36. Log::error('找不到警报相关信息,警报id为'.$this->warning_id);
  37. return;
  38. }
  39. $bike = Bike::where('bike_no',$warning->bike_no)->first();
  40. if(empty($bike)) {
  41. Log::error('找不到警报车辆相关信息,警报id为'.$this->warning_id.'车辆编号为'.$warning->bike_no);
  42. return;
  43. }
  44. if($bike->is_link == 0){
  45. $data = [
  46. 'work_no' => WorkOrder::makeWorkNo(),
  47. 'bike_no' => $warning->bike_no,
  48. 'bike_id' => $bike->id,
  49. 'source' => WorkOrder::SOURCE_SYSTEM,
  50. 'planned' => WorkOrder::PLANNED_STATUS_MEET,
  51. 'area_id' => $bike->put_area_id,
  52. 'type' => WorkOrder::TYPE_OFFLINE,
  53. 'reason' => WarningLog::$typeMaps[WarningLog::TYPE_BIKE_OFF_LINE],
  54. 'type_name' => WorkOrder::$typeMaps[WorkOrder::TYPE_OFFLINE],
  55. 'insert_time' => $warning->created_at,
  56. ];
  57. // 验证是否存在数据
  58. $verify = [
  59. 'type' => WorkOrder::TYPE_OFFLINE,
  60. 'bike_id' => $bike->id,
  61. 'status' => WorkOrder::STATUS_NO,
  62. ];
  63. WorkOrder::firstOrCreate($verify,$data);
  64. }
  65. }
  66. }