CloseBikeJob.php 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. <?php
  2. namespace App\Jobs;
  3. use App\Handlers\BaseBikeControl;
  4. use App\Handlers\BikeControl;
  5. use App\Handlers\BikeStatusInfoSyncHandler;
  6. use App\Models\Bike;
  7. use App\Models\LocationsLog;
  8. use Carbon\Carbon;
  9. use Illuminate\Bus\Queueable;
  10. use Illuminate\Queue\SerializesModels;
  11. use Illuminate\Queue\InteractsWithQueue;
  12. use Illuminate\Contracts\Queue\ShouldQueue;
  13. use Illuminate\Foundation\Bus\Dispatchable;
  14. use Illuminate\Support\Facades\Log;
  15. class CloseBikeJob implements ShouldQueue
  16. {
  17. use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
  18. protected $bike;
  19. /**
  20. * Create a new job instance.
  21. *
  22. * @return void
  23. */
  24. public function __construct(Bike $bike)
  25. {
  26. $this->bike = $bike;
  27. $this->delay(Carbon::now()->addMinutes(30));
  28. }
  29. /**
  30. * Execute the job.
  31. *
  32. * @return void
  33. */
  34. public function handle()
  35. {
  36. $bike_no = $this->bike->bike_no;
  37. $box_no = $this->bike->box_no;
  38. $order = (new BikeStatusInfoSyncHandler())->getRideBikeOrderInfo($bike_no);
  39. if (isset($order['role']) && in_array($order['role'], [BikeStatusInfoSyncHandler::ROLE_BIND, BikeStatusInfoSyncHandler::ROLE_WORKER])) {
  40. $bike_location = LocationsLog::getNewestLocationByBikeNo($bike_no);
  41. (new BikeStatusInfoSyncHandler())->toBikeWaitRideStatus($bike_no, $bike_location['lng'], $bike_location['lat'], $this->bike->put_status);
  42. (new BaseBikeControl($box_no))::closeLock();
  43. }
  44. return;
  45. }
  46. }