123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172 |
- <?php
- namespace App\Jobs;
- use App\Handlers\BikeControl;
- use App\Handlers\BikeStatusInfoSyncHandler;
- use App\Models\Bike;
- use App\Models\LocationsLog;
- use App\Models\WorkerBikeOperate;
- use Carbon\Carbon;
- use Illuminate\Bus\Queueable;
- use Illuminate\Queue\SerializesModels;
- use Illuminate\Queue\InteractsWithQueue;
- use Illuminate\Contracts\Queue\ShouldQueue;
- use Illuminate\Foundation\Bus\Dispatchable;
- class AutoCloseBikeLockJob implements ShouldQueue
- {
- use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
- protected $bike;
- public $tries = 5;
- /**
- * Create a new job instance.
- *
- * @return void
- */
- public function __construct(Bike $bike)
- {
- //
- $this->bike = $bike;
- }
- /**
- * Execute the job.
- *
- * @return
- */
- public function handle()
- {
- //
- $bike = $this->bike;
- $res = app()->redis->hexists(BikeStatusInfoSyncHandler::REDIS_RIDE_BIKE_WORKER_ORDERS_TAG, $bike->bike_no);
- if ($res) {
- if (!$bike->is_riding) {
- $bike_location = LocationsLog::getNewestLocationByBikeNo($bike->bike_no);
- (new BikeStatusInfoSyncHandler())->toBikeWaitRideStatus($bike->bike_no, $bike_location['lng'], $bike_location['lat'], $bike->put_status);
- $bike->last_use_bike_end_time = Carbon::now();
- $bike->is_lock = Bike::LOCK_YES;
- $bike->save();
- BikeControl::closeLock($bike->box_no);
- // 添加记录
- $worker_bike_operate = new WorkerBikeOperate();
- $worker_bike_operate->type = WorkerBikeOperate::TYPE_CLOSE_BIKE_LOCK;
- $worker_bike_operate->name = WorkerBikeOperate::$typeMaps[WorkerBikeOperate::TYPE_CLOSE_BIKE_LOCK];
- $worker_bike_operate->bike_id = $bike->id;
- $last_location = object_array(json_decode($bike->last_location));
- $worker_bike_operate->latitude = empty($last_location['lat']) ? 0 : $last_location['lat'];
- $worker_bike_operate->longitude = empty($last_location['lng']) ? 0 : $last_location['lng'];
- $worker_bike_operate->reason = "系统自动关锁";
- $worker_bike_operate->worker_id = 0;
- $worker_bike_operate->save();
- }
- }
- return true;
- }
- }
|