You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

36 lines
1.0 KiB

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

<?php
namespace App\Services;
use App\Models\Reservation;
use Carbon\Carbon;
class ReservationExpiryService
{
/**
* 将「活动日已过、仍为待核销、未核销」的预约标记为 expired与未履约统计一致
*/
public function expireStalePendingReservations(): int
{
$tz = (string) config('app.timezone');
$today = Carbon::now($tz)->toDateString();
$ids = Reservation::query()
->join('activity_days', 'activity_days.id', '=', 'reservations.activity_day_id')
->where('reservations.status', 'pending')
->whereNull('reservations.verified_at')
->whereNotNull('reservations.activity_day_id')
->whereDate('activity_days.activity_date', '<', $today)
->pluck('reservations.id');
if ($ids->isEmpty()) {
return 0;
}
return Reservation::query()->whereIn('id', $ids)->update([
'status' => 'expired',
'updated_at' => now(),
]);
}
}