AutoCloseBikeLockJob.php 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. <?php
  2. namespace App\Jobs;
  3. use App\Handlers\BikeControl;
  4. use App\Handlers\BikeStatusInfoSyncHandler;
  5. use App\Models\Bike;
  6. use App\Models\LocationsLog;
  7. use App\Models\WorkerBikeOperate;
  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. class AutoCloseBikeLockJob implements ShouldQueue
  15. {
  16. use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
  17. protected $bike;
  18. /**
  19. * Create a new job instance.
  20. *
  21. * @return void
  22. */
  23. public function __construct(Bike $bike)
  24. {
  25. //
  26. $this->bike = $bike;
  27. }
  28. /**
  29. * Execute the job.
  30. *
  31. * @return void
  32. */
  33. public function handle()
  34. {
  35. //
  36. $bike = $this->bike;
  37. $res = app()->redis->hexists(BikeStatusInfoSyncHandler::REDIS_RIDE_BIKE_WORKER_ORDERS_TAG,$bike->bike_no);
  38. if($res){
  39. $bike_location = LocationsLog::getNewestLocationByBikeNo($bike->bike_no);
  40. (new BikeStatusInfoSyncHandler())->toBikeWaitRideStatus($bike->bike_no, $bike_location['lng'], $bike_location['lat'], $bike->put_status);
  41. if(!$bike->is_riding){
  42. $bike->last_use_bike_end_time = Carbon::now();
  43. $bike->is_lock = Bike::LOCK_YES;
  44. $bike->save();
  45. BikeControl::closeLock($bike->box_no);
  46. // 添加记录
  47. $worker_bike_operate = new WorkerBikeOperate();
  48. $worker_bike_operate->type = WorkerBikeOperate::TYPE_CLOSE_BIKE_LOCK;
  49. $worker_bike_operate->name = WorkerBikeOperate::$typeMaps[WorkerBikeOperate::TYPE_CLOSE_BIKE_LOCK];
  50. $worker_bike_operate->bike_id = $bike->id;
  51. $last_location = object_array(json_decode($bike->last_location));
  52. $worker_bike_operate->latitude = empty($last_location['lat']) ? 0 : $last_location['lat'];
  53. $worker_bike_operate->longitude = empty($last_location['lng']) ? 0 : $last_location['lng'];
  54. $worker_bike_operate->reason = "系统自动关锁";
  55. $worker_bike_operate->worker_id = 0;
  56. $worker_bike_operate->save();
  57. }
  58. }
  59. }
  60. }