12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273 |
- <?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;
- /**
- * Create a new job instance.
- *
- * @return void
- */
- public function __construct(Bike $bike)
- {
- //
- $this->bike = $bike;
- }
- /**
- * Execute the job.
- *
- * @return void
- */
- public function handle()
- {
- //
- $bike = $this->bike;
- $res = app()->redis->hexists(BikeStatusInfoSyncHandler::REDIS_RIDE_BIKE_WORKER_ORDERS_TAG,$bike->bike_no);
- if($res){
- $bike_location = LocationsLog::getNewestLocationByBikeNo($bike->bike_no);
- (new BikeStatusInfoSyncHandler())->toBikeWaitRideStatus($bike->bike_no, $bike_location['lng'], $bike_location['lat'], $bike->put_status);
- if(!$bike->is_riding){
- $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();
- }
- }
- }
- }
|