|
|
|
|
<?php
|
|
|
|
|
/**
|
|
|
|
|
* 预约
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
namespace App\Jobs;
|
|
|
|
|
|
|
|
|
|
use App\Models\Appointment;
|
|
|
|
|
use App\Models\Config;
|
|
|
|
|
use App\Models\User;
|
|
|
|
|
use App\Notifications\MeetNotify;
|
|
|
|
|
use App\Repositories\DoorRepository;
|
|
|
|
|
use Illuminate\Bus\Queueable;
|
|
|
|
|
use Illuminate\Contracts\Queue\ShouldQueue;
|
|
|
|
|
use Illuminate\Foundation\Bus\Dispatchable;
|
|
|
|
|
use Illuminate\Queue\InteractsWithQueue;
|
|
|
|
|
use Illuminate\Queue\SerializesModels;
|
|
|
|
|
use Illuminate\Support\Facades\Notification;
|
|
|
|
|
use Illuminate\Support\Facades\Log;
|
|
|
|
|
|
|
|
|
|
class SendAppoint implements ShouldQueue
|
|
|
|
|
{
|
|
|
|
|
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
|
|
|
|
|
|
|
|
|
|
public $tries = 3;
|
|
|
|
|
public $timeout = 850;
|
|
|
|
|
|
|
|
|
|
public $appointmentModel;
|
|
|
|
|
public $appointmentConfig;
|
|
|
|
|
public $traceId;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Create a new job instance.
|
|
|
|
|
*
|
|
|
|
|
* @return void
|
|
|
|
|
*/
|
|
|
|
|
public function __construct($appointmentModel, $AppointmentConfig, $traceId = null)
|
|
|
|
|
{
|
|
|
|
|
$this->appointmentModel = $appointmentModel;
|
|
|
|
|
$this->appointmentConfig = $AppointmentConfig;
|
|
|
|
|
$this->traceId = $traceId ?: uniqid('appointment-job-', true);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Execute the job.
|
|
|
|
|
*
|
|
|
|
|
* @return void
|
|
|
|
|
*/
|
|
|
|
|
public function handle()
|
|
|
|
|
{
|
|
|
|
|
$startedAt = microtime(true);
|
|
|
|
|
$context = ['trace_id' => $this->traceId, 'appointment_id' => $this->appointmentModel->id];
|
|
|
|
|
Log::info('appointment.retry.job.started', $context);
|
|
|
|
|
try {
|
|
|
|
|
Log::info('appointment.retry.car.begin', $context);
|
|
|
|
|
$carResult = Appointment::sendAppoinCar($this->appointmentModel);
|
|
|
|
|
Log::info('appointment.retry.car.completed', $context + ['result' => $carResult]);
|
|
|
|
|
|
|
|
|
|
Log::info('appointment.retry.meet.begin', $context);
|
|
|
|
|
$meetResult = (new Appointment())->appointMeet($this->appointmentModel, $this->appointmentConfig);
|
|
|
|
|
Log::info('appointment.retry.meet.completed', $context + ['result' => $meetResult]);
|
|
|
|
|
|
|
|
|
|
Log::info('appointment.retry.door.begin', $context);
|
|
|
|
|
$doorResult = (new Appointment())->appointDoor($this->appointmentModel, $this->appointmentConfig);
|
|
|
|
|
Log::info('appointment.retry.door.completed', $context + ['result' => $doorResult]);
|
|
|
|
|
|
|
|
|
|
$this->appointmentModel->status = $doorResult ? 1 : 4;
|
|
|
|
|
$this->appointmentModel->save();
|
|
|
|
|
Log::info('appointment.retry.job.completed', $context + [
|
|
|
|
|
'status' => $this->appointmentModel->status,
|
|
|
|
|
'elapsed_ms' => (int) ((microtime(true) - $startedAt) * 1000),
|
|
|
|
|
]);
|
|
|
|
|
} catch (\Throwable $exception) {
|
|
|
|
|
Log::error('appointment.retry.job.failed', $context + [
|
|
|
|
|
'elapsed_ms' => (int) ((microtime(true) - $startedAt) * 1000),
|
|
|
|
|
'exception' => $exception,
|
|
|
|
|
]);
|
|
|
|
|
throw $exception;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 预约门禁
|
|
|
|
|
// $result = (new Appointment())->appointDoor($this->appointmentModel, $this->appointmentConfig);
|
|
|
|
|
// if ($result) {
|
|
|
|
|
// // 成功预约会议室
|
|
|
|
|
// $result = (new Appointment())->appointMeet($this->appointmentModel, $this->appointmentConfig);
|
|
|
|
|
// }
|
|
|
|
|
// if ($result) {
|
|
|
|
|
// // 门禁会议预约成功,预约车牌
|
|
|
|
|
// Appointment::sendAppoinCar($this->appointmentModel);
|
|
|
|
|
// // 预约成功
|
|
|
|
|
// $this->appointmentModel->status = 1;
|
|
|
|
|
// } else {
|
|
|
|
|
// // 预约失败
|
|
|
|
|
// $this->appointmentModel->status = 4;
|
|
|
|
|
// }
|
|
|
|
|
// $this->appointmentModel->save();
|
|
|
|
|
}
|
|
|
|
|
}
|