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.
|
|
|
|
|
<?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(),
|
|
|
|
|
|
]);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|