feat: enhance FastRequest functionality with shift scheduling and improve payment callback handling

This commit is contained in:
2026-09-21 04:45:57 +03:30
parent 5f19f82f86
commit 45da0103c0
11 changed files with 74 additions and 15 deletions
+20 -1
View File
@@ -60,12 +60,17 @@ class ShiftScheduleService
->get();
}
public function isOnShift(User $doctor, Carbon $moment): bool
{
return $this->shiftsCoveringMoment($moment)->contains('user_id', $doctor->id);
}
public function autoSelectDoctor(Carbon $moment): ?User
{
$doctorIds = $this->shiftsCoveringMoment($moment)->pluck('user_id')->filter()->unique();
if ($doctorIds->isEmpty()) {
return null;
return $this->doctorWithNearestShift($moment);
}
return User::where('level', UserEnum::Doctor->value)
@@ -81,6 +86,20 @@ class ShiftScheduleService
->first();
}
// fallback when nobody is on shift: the doctor whose next shift starts soonest
public function doctorWithNearestShift(Carbon $from): ?User
{
$doctorIds = Shift::active()->whereNotNull('user_id')->distinct()->pluck('user_id');
return User::where('level', UserEnum::Doctor->value)
->whereIn('id', $doctorIds)
->get()
->map(fn (User $doctor) => ['doctor' => $doctor, 'start' => $this->nextShiftStart($doctor, $from)])
->filter(fn (array $item) => $item['start'] !== null)
->sortBy('start')
->first()['doctor'] ?? null;
}
public function nextShiftStart(User $doctor, Carbon $from): ?Carbon
{
$shifts = Shift::active()->where('user_id', $doctor->id)->get();