feat: enhance FastRequest functionality with shift scheduling and improve payment callback handling
This commit is contained in:
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user