CaseActivities/CaseAutomation sind Fassaden über ProcessRunner. Verhaltensvergleich v0.11: 11 Abläufe und 198 Konstellationen gleich, beabsichtigte Abweichungen I-004/I-005 (F-001/F-002). Volle Suite vor U-B: 785/785. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
53 lines
2.2 KiB
PHP
53 lines
2.2 KiB
PHP
<?php
|
||
|
||
namespace App\Console\Commands;
|
||
|
||
use App\Actions\AutoOffer;
|
||
use App\Enums\BookingStatus;
|
||
use App\Models\Booking;
|
||
use App\Models\Tenant;
|
||
use App\Process\ProcessRunner;
|
||
use App\Tenancy\TenantRunner;
|
||
use Illuminate\Console\Attributes\Description;
|
||
use Illuminate\Console\Attributes\Signature;
|
||
use Illuminate\Console\Command;
|
||
use Throwable;
|
||
|
||
#[Signature('bookings:auto-offers')]
|
||
#[Description('Retry automatic offers of pending requests (e.g. once an instant-booking portal has fetched our calendar) – once per landlord')]
|
||
class SendPendingAutoOffers extends Command
|
||
{
|
||
/**
|
||
* Execute the console command.
|
||
*/
|
||
public function handle(AutoOffer $autoOffer, TenantRunner $tenants, ProcessRunner $runner): int
|
||
{
|
||
$tenants->each(function (Tenant $tenant) use ($autoOffer, $runner): void {
|
||
$pending = Booking::query()
|
||
->where('status', BookingStatus::Reserved)
|
||
->where('offer_version', 0)
|
||
->where('information_version', 0)
|
||
// Held requests while their hold runs; requests without a hold (information, package 7) for two weeks.
|
||
->where(fn ($query) => $query->where('hold_expires_at', '>', now())->orWhere(fn ($open) => $open->whereNull('hold_expires_at')->where('created_at', '>', now()->subDays(14))))
|
||
->where(fn ($query) => $query->whereNull('intake')->orWhere('intake', 'inquiry'))
|
||
->with(['property', 'guest', 'importChannel', 'originChannel'])
|
||
->get()
|
||
->filter(fn (Booking $booking): bool => $autoOffer->applies($booking) && ($booking->isHoldActive() || ! $booking->process()->preReservation()));
|
||
|
||
$sent = 0;
|
||
foreach ($pending as $booking) {
|
||
try {
|
||
$result = $runner->advance($booking, 'schedule:bookings:auto-offers');
|
||
$sent += $result->ran('offer.binding') || $result->ran('offer.information') ? 1 : 0;
|
||
} catch (Throwable) {
|
||
// The request stays pending for the landlord; the next run tries again.
|
||
}
|
||
}
|
||
|
||
$this->info("{$tenant->name}: {$sent} von {$pending->count()} Angebot(e) automatisch versendet.");
|
||
});
|
||
|
||
return self::SUCCESS;
|
||
}
|
||
}
|