Antwortart (Auskunft/Angebot) und Reservierung sind entkoppelt (neue Einstellung inquiry_answer; pre_reservation bleibt die Reservierungsstrategie). Anlass-bezogene Absender für Anreise-Information und Bewertungsbitte; Schablonen liefern Standardwerte unterhalb aller einstellbaren Ebenen. A1/A2 bleiben Voreinstellungen und Altfassungen. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
45 lines
1.7 KiB
PHP
45 lines
1.7 KiB
PHP
<?php
|
||
|
||
namespace App\Actions;
|
||
|
||
use App\Enums\BookingStatus;
|
||
use App\Enums\Responsibility;
|
||
use App\Mail\ReviewRequest;
|
||
use App\Models\Booking;
|
||
use App\Process\OutwardSuspension;
|
||
use App\Process\ProcessPlan;
|
||
use Illuminate\Support\Facades\Mail;
|
||
|
||
/**
|
||
* Sends the review invitation once, a few days after departure. Old stays (more than 30 days ago)
|
||
* are skipped so that switching the feature on does not mail former guests.
|
||
*/
|
||
class RequestReviews
|
||
{
|
||
public function handle(): int
|
||
{
|
||
$latestDeparture = today()->subDays(config('fewo.review_request_after_days'));
|
||
|
||
$bookings = Booking::query()
|
||
->whereIn('status', BookingStatus::occupying())
|
||
->whereNull('review_requested_at')
|
||
->whereDate('departure', '<=', $latestDeparture)
|
||
->whereDate('departure', '>', $latestDeparture->copy()->subDays(30))
|
||
->whereDoesntHave('review')
|
||
->whereHas('guest', fn ($query) => $query->whereNull('anonymized_at')->whereNotNull('email')->where('email', '!=', ''))
|
||
->with('guest')
|
||
->get()
|
||
->filter(fn (Booking $booking): bool => $booking->process()->reviewRequestSender() === Responsibility::Landlord
|
||
// The step can be switched off per channel (Kanal › Ablauf); an open portal report holds it back (O4).
|
||
&& ProcessPlan::of($booking)->enabled('review.request')
|
||
&& OutwardSuspension::reason($booking) === null);
|
||
|
||
foreach ($bookings as $booking) {
|
||
Mail::to($booking->guest->email, $booking->guest->full_name)->send(new ReviewRequest($booking));
|
||
$booking->update(['review_requested_at' => now()]);
|
||
}
|
||
|
||
return $bookings->count();
|
||
}
|
||
}
|