|
|
@@ -43,19 +43,52 @@ class ScheduleService
|
|
|
public function createSingleOrMultiple(array $baseData, array $schedules)
|
|
|
{
|
|
|
try {
|
|
|
+
|
|
|
DB::beginTransaction();
|
|
|
+
|
|
|
$createdSchedules = [];
|
|
|
+
|
|
|
foreach ($schedules as $schedule) {
|
|
|
+
|
|
|
$datasMerged = array_merge($baseData, $schedule);
|
|
|
+
|
|
|
$this->validateProviderAvailability($datasMerged, null);
|
|
|
+
|
|
|
$scheduleData = array_merge($datasMerged, [
|
|
|
'code' => str_pad(random_int(0, 9999), 4, '0', STR_PAD_LEFT),
|
|
|
]);
|
|
|
- $createdSchedules[] = Schedule::create($scheduleData);
|
|
|
+
|
|
|
+ $newSchedule = Schedule::create($scheduleData);
|
|
|
+
|
|
|
+ /*NOTIFICAÇÃO PRESTADOR*/
|
|
|
+ if ($newSchedule->provider_id) {
|
|
|
+
|
|
|
+ $notificationService = app(NotificationService::class);
|
|
|
+
|
|
|
+ $notificationService->create([
|
|
|
+ 'title' => 'Nova solicitação de diária!',
|
|
|
+
|
|
|
+ 'description' =>
|
|
|
+ 'Você recebeu uma nova solicitação de diária.',
|
|
|
+
|
|
|
+ 'origin' => 'schedule',
|
|
|
+
|
|
|
+ 'origin_id' => $newSchedule->id,
|
|
|
+
|
|
|
+ 'type' => NotificationTypeEnum::SCHEDULE_PROVIDER_CLIENT_NEW_SOLICITATION->value,
|
|
|
+
|
|
|
+ 'user_id' => $newSchedule->provider->user_id,
|
|
|
+ ]);
|
|
|
+ }
|
|
|
+
|
|
|
+ $createdSchedules[] = $newSchedule;
|
|
|
}
|
|
|
+
|
|
|
DB::commit();
|
|
|
} catch (\Exception $e) {
|
|
|
+
|
|
|
DB::rollBack();
|
|
|
+
|
|
|
throw new \Exception(__($e->getMessage()));
|
|
|
}
|
|
|
|
|
|
@@ -264,8 +297,6 @@ class ScheduleService
|
|
|
|
|
|
$schedule->update(['status' => $status]);
|
|
|
|
|
|
- $schedule->update(['status' => $status]);
|
|
|
-
|
|
|
switch ($status) {
|
|
|
|
|
|
case 'pending':
|
|
|
@@ -357,43 +388,51 @@ class ScheduleService
|
|
|
$notificationService = app(NotificationService::class);
|
|
|
|
|
|
|
|
|
- if ($schedule->cancelled_by === 'client') {
|
|
|
+ switch (Auth::user()->type) {
|
|
|
+ case 'client':
|
|
|
+
|
|
|
+ // PRESTADOR
|
|
|
+ if ($schedule->provider_id) {
|
|
|
+
|
|
|
+ $notificationService->create(['title' => 'Agendamento cancelado!',
|
|
|
+
|
|
|
+ 'description' =>'O cliente cancelou a diária.',
|
|
|
+
|
|
|
+ 'origin' => 'schedule',
|
|
|
+
|
|
|
+ 'origin_id' => $schedule->id,
|
|
|
+
|
|
|
+ 'type' => NotificationTypeEnum::SCHEDULE_PROVIDER_CLIENT_CANCELLED->value,
|
|
|
+
|
|
|
+ 'user_id' => $schedule->provider->user_id,
|
|
|
+ ]);
|
|
|
+ }
|
|
|
+
|
|
|
+ break;
|
|
|
|
|
|
- if ($schedule->provider_id) {
|
|
|
+ case 'provider':
|
|
|
|
|
|
+ // CLIENTE
|
|
|
$notificationService->create([
|
|
|
'title' => 'Agendamento cancelado!',
|
|
|
|
|
|
'description' =>
|
|
|
- 'O cliente cancelou o agendamento.',
|
|
|
+ $schedule->provider->user->name .
|
|
|
+ ' cancelou a diária.',
|
|
|
|
|
|
'origin' => 'schedule',
|
|
|
|
|
|
'origin_id' => $schedule->id,
|
|
|
|
|
|
- 'type' => NotificationTypeEnum::SCHEDULE_PROVIDER_CLIENT_CANCELLED->value,
|
|
|
+ 'type' => NotificationTypeEnum::SCHEDULE_CLIENT_PROVIDER_CANCELLED->value,
|
|
|
|
|
|
- 'user_id' => $schedule->provider->user_id,
|
|
|
+ 'user_id' => $schedule->client->user_id,
|
|
|
]);
|
|
|
- }
|
|
|
- } else {
|
|
|
-
|
|
|
- $notificationService->create([
|
|
|
- 'title' => 'Agendamento cancelado!',
|
|
|
|
|
|
- 'description' =>
|
|
|
- 'Infelizmente ' .
|
|
|
- $schedule->provider->user->name .
|
|
|
- ' cancelou o agendamento. O valor pago será extornado em breve.',
|
|
|
+ break;
|
|
|
|
|
|
- 'origin' => 'schedule',
|
|
|
-
|
|
|
- 'origin_id' => $schedule->id,
|
|
|
-
|
|
|
- 'type' => NotificationTypeEnum::SCHEDULE_CLIENT_PROVIDER_CANCELLED->value,
|
|
|
-
|
|
|
- 'user_id' => $schedule->client->user_id,
|
|
|
- ]);
|
|
|
+ default:
|
|
|
+ break;
|
|
|
}
|
|
|
|
|
|
break;
|