U-A/U-B: Prozesskern mit Fachmodulen, versionierten Modellen, eingefrorenem Prozessplan, ProcessRunner (harte/weiche Abhängigkeiten), CasePricing, Loyalty nur im Tester
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>
This commit is contained in:
1 parent
98df5e9e3b
commit
7e22e12cac
80 files changed
+4628
-445
No files matched your search
@@ -0,0 +1,90 @@
|
||||
<?php
|
||||
|
||||
namespace App\Process\Modules\Loyalty;
|
||||
|
||||
use App\Enums\ActivityState;
|
||||
use App\Enums\BookingStatus;
|
||||
use App\Models\Booking;
|
||||
use App\Process\Activity;
|
||||
use App\Process\CaseContext;
|
||||
use App\Process\Modules\Dependency;
|
||||
use App\Process\Modules\Module;
|
||||
use App\Process\Modules\ModuleDefinition;
|
||||
use App\Process\Modules\StepState;
|
||||
|
||||
/**
|
||||
* Architecture proof (decision E7, docs/Prozessarchitektur/Architektur/02 §6): whether the guest is a returning guest –
|
||||
* completed, not cancelled stays of the same guest e-mail at the same landlord within the look-back. Tester only: never
|
||||
* part of a real case's plan. The status is derived from the stays on every evaluation (no second truth); the rules
|
||||
* (count, look-back) are test assumptions, not released business rules.
|
||||
*/
|
||||
final class LoyaltyStatusCheck extends Module
|
||||
{
|
||||
public const QUALIFIED = 'qualified';
|
||||
|
||||
public const NOT_QUALIFIED = 'not_qualified';
|
||||
|
||||
public const UNKNOWN = 'unknown';
|
||||
|
||||
public static function key(): string
|
||||
{
|
||||
return 'guest.loyalty_status';
|
||||
}
|
||||
|
||||
public static function definition(): ModuleDefinition
|
||||
{
|
||||
return new ModuleDefinition(
|
||||
label: 'Stammgaststatus feststellen',
|
||||
purpose: 'Stellt fest, ob der Gast schon bei Ihnen zu Gast war (Architekturnachweis, nur im Prozess-Tester).',
|
||||
phase: 'P01',
|
||||
requires: [Dependency::hard('guest.details')],
|
||||
triggers: ['facts.applied'],
|
||||
parameters: ['min_stays', 'lookback_years'],
|
||||
toggle: ModuleDefinition::TOGGLE_OPTIONAL,
|
||||
events: ['facts'],
|
||||
points: ['after_guest_identified'],
|
||||
availability: ModuleDefinition::AVAILABILITY_TESTER_ONLY,
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array{status: string, stays: list<string>}
|
||||
*/
|
||||
public function status(CaseContext $case): array
|
||||
{
|
||||
$email = mb_strtolower(trim((string) $case->booking->guest?->email));
|
||||
if ($email === '') {
|
||||
return ['status' => self::UNKNOWN, 'stays' => []];
|
||||
}
|
||||
|
||||
$years = (int) ($case->parameter(self::key(), 'lookback_years') ?? 5);
|
||||
$minimum = (int) ($case->parameter(self::key(), 'min_stays') ?? 1);
|
||||
$stays = Booking::query()
|
||||
->whereKeyNot($case->booking->id)
|
||||
->where('status', BookingStatus::Completed)
|
||||
->whereDate('departure', '>=', $case->today->subYears($years))
|
||||
->whereHas('guest', fn ($query) => $query->whereRaw('lower(email) = ?', [$email]))
|
||||
->orderBy('arrival')
|
||||
->get()
|
||||
->map(fn (Booking $stay): string => (string) $stay->reference)
|
||||
->all();
|
||||
|
||||
return ['status' => count($stays) >= $minimum ? self::QUALIFIED : self::NOT_QUALIFIED, 'stays' => $stays];
|
||||
}
|
||||
|
||||
public function activities(CaseContext $case): array
|
||||
{
|
||||
$status = $this->status($case);
|
||||
|
||||
return [new Activity('loyalty_status', 'Stammgaststatus feststellen', ActivityState::Done, match ($status['status']) {
|
||||
self::QUALIFIED => 'Stammgast: '.count($status['stays']).' frühere Aufenthalte ('.implode(', ', $status['stays']).')',
|
||||
self::NOT_QUALIFIED => 'kein Stammgast',
|
||||
default => 'Status nicht feststellbar (keine E-Mail-Adresse) – kein Rabatt',
|
||||
})];
|
||||
}
|
||||
|
||||
public function state(CaseContext $case): ?StepState
|
||||
{
|
||||
return StepState::Done;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user