| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647 |
- <?php
- namespace App\Jobs;
- use App\Models\Schedule;
- use Illuminate\Bus\Queueable;
- use Illuminate\Contracts\Queue\ShouldQueue;
- use Illuminate\Foundation\Bus\Dispatchable;
- use Illuminate\Queue\InteractsWithQueue;
- use Illuminate\Queue\SerializesModels;
- class InvalidateExpiredSchedules implements ShouldQueue
- {
- use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
- public function handle(): void
- {
- $today = today();
- $now = now();
- // Agendamentos aceitos cuja data já passou.
- Schedule::query()
- ->where('status', 'accepted')
- ->whereDate('date', '<', $today)
- ->update([
- 'status' => 'cancelled',
- ]);
- // Agendamentos pendentes cuja data já passou.
- Schedule::query()
- ->where('status', 'pending')
- ->whereDate('date', '<', $today)
- ->update([
- 'status' => 'cancelled',
- ]);
- // Agendamentos pendentes de hoje cujo horário já terminou.
- Schedule::query()
- ->where('status', 'pending')
- ->whereDate('date', $today)
- ->whereNotNull('end_time')
- ->whereRaw("CAST(end_time AS time) < ?", [$now->format('H:i:s')])
- ->update([
- 'status' => 'cancelled',
- ]);
- }
- }
|