Portal-Synchronisation: unser System führt
- Connector-System (app/Channels, config/channels.php) mit iCal-Connector, robustem Parser und Export-Feed je Portal (ohne eigene Belegungen, ohne Gästedaten) - Abgleich alle 5 Min. mit Protokoll, Echo-Erkennung, Konflikt-Mail bei möglicher Doppelbuchung - Überwachung: Störungs-Mail, Status-Endpunkt /health/sync für n8n - Portal-Aufgaben für Sofortbuchungsportale (FeWo-direkt): automatisch aus Buchungen/Sperren/anderen Portalen, Mail + Erinnerung, Abhaken im Admin - Optionaler signierter Automatisierungs-Webhook mit Rückmeldung - Herkunftsmessung: Abfrage im Formular + UTM-Parameter - Portal-Analyse: AGB-Prüfung Automatisierung, Umsetzungsbeschreibung Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
a8e72715ab
commit
0b7205e050
55 files changed
+2290
-3
No files matched your search
@@ -2,9 +2,11 @@
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use App\Observers\BlockedPeriodObserver;
|
||||
use Carbon\CarbonInterface;
|
||||
use Database\Factories\BlockedPeriodFactory;
|
||||
use Illuminate\Database\Eloquent\Attributes\Fillable;
|
||||
use Illuminate\Database\Eloquent\Attributes\ObservedBy;
|
||||
use Illuminate\Database\Eloquent\Attributes\Scope;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
@@ -15,7 +17,8 @@
|
||||
* Dates that are not bookable (own use, maintenance, bookings from portals).
|
||||
* Like bookings, ends_on is the first free day again.
|
||||
*/
|
||||
#[Fillable(['property_id', 'starts_on', 'ends_on', 'reason', 'source', 'external_uid'])]
|
||||
#[ObservedBy(BlockedPeriodObserver::class)]
|
||||
#[Fillable(['property_id', 'channel_id', 'starts_on', 'ends_on', 'reason', 'source', 'external_uid'])]
|
||||
class BlockedPeriod extends Model
|
||||
{
|
||||
/** @use HasFactory<BlockedPeriodFactory> */
|
||||
@@ -42,6 +45,14 @@ public function property(): BelongsTo
|
||||
return $this->belongsTo(Property::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return BelongsTo<Channel, $this>
|
||||
*/
|
||||
public function channel(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Channel::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Builder<BlockedPeriod> $query
|
||||
* @return Builder<BlockedPeriod>
|
||||
|
||||
@@ -3,9 +3,12 @@
|
||||
namespace App\Models;
|
||||
|
||||
use App\Enums\BookingStatus;
|
||||
use App\Enums\ReferralSource;
|
||||
use App\Observers\BookingObserver;
|
||||
use Carbon\CarbonInterface;
|
||||
use Database\Factories\BookingFactory;
|
||||
use Illuminate\Database\Eloquent\Attributes\Fillable;
|
||||
use Illuminate\Database\Eloquent\Attributes\ObservedBy;
|
||||
use Illuminate\Database\Eloquent\Attributes\Scope;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
@@ -17,11 +20,16 @@
|
||||
* A reservation or booking. arrival is the first night, departure the day the guest leaves,
|
||||
* so a departure and the next arrival on the same day do not collide.
|
||||
*/
|
||||
#[ObservedBy(BookingObserver::class)]
|
||||
#[Fillable([
|
||||
'property_id',
|
||||
'guest_id',
|
||||
'status',
|
||||
'source',
|
||||
'referral_source',
|
||||
'utm_source',
|
||||
'utm_medium',
|
||||
'utm_campaign',
|
||||
'arrival',
|
||||
'departure',
|
||||
'guests',
|
||||
@@ -59,6 +67,7 @@ protected function casts(): array
|
||||
{
|
||||
return [
|
||||
'status' => BookingStatus::class,
|
||||
'referral_source' => ReferralSource::class,
|
||||
'arrival' => 'immutable_date',
|
||||
'departure' => 'immutable_date',
|
||||
'extras' => 'array',
|
||||
|
||||
@@ -0,0 +1,123 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use App\Channels\ChannelRegistry;
|
||||
use App\Channels\Contracts\ChannelConnector;
|
||||
use Database\Factories\ChannelFactory;
|
||||
use Illuminate\Database\Eloquent\Attributes\Fillable;
|
||||
use Illuminate\Database\Eloquent\Attributes\Hidden;
|
||||
use Illuminate\Database\Eloquent\Attributes\Scope;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
/**
|
||||
* A sales channel (portal) of a property. Our system leads: occupations are imported from the
|
||||
* channel and every channel gets its own export feed without its own occupations.
|
||||
*/
|
||||
#[Fillable(['property_id', 'name', 'connector', 'settings', 'is_active', 'requires_manual_blocking', 'manage_url'])]
|
||||
#[Hidden(['export_token'])]
|
||||
class Channel extends Model
|
||||
{
|
||||
/** @use HasFactory<ChannelFactory> */
|
||||
use HasFactory;
|
||||
|
||||
protected static function booted(): void
|
||||
{
|
||||
static::creating(function (Channel $channel): void {
|
||||
$channel->export_token ??= Str::random(48);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the attributes that should be cast.
|
||||
*
|
||||
* @return array<string, string>
|
||||
*/
|
||||
protected function casts(): array
|
||||
{
|
||||
return [
|
||||
'settings' => 'array',
|
||||
'is_active' => 'boolean',
|
||||
'requires_manual_blocking' => 'boolean',
|
||||
'last_synced_at' => 'immutable_datetime',
|
||||
'last_success_at' => 'immutable_datetime',
|
||||
'alerted_at' => 'immutable_datetime',
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return BelongsTo<Property, $this>
|
||||
*/
|
||||
public function property(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Property::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return HasMany<BlockedPeriod, $this>
|
||||
*/
|
||||
public function blockedPeriods(): HasMany
|
||||
{
|
||||
return $this->hasMany(BlockedPeriod::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return HasMany<ChannelSyncLog, $this>
|
||||
*/
|
||||
public function syncLogs(): HasMany
|
||||
{
|
||||
return $this->hasMany(ChannelSyncLog::class)->latest('id');
|
||||
}
|
||||
|
||||
/**
|
||||
* @return HasMany<ChannelTask, $this>
|
||||
*/
|
||||
public function tasks(): HasMany
|
||||
{
|
||||
return $this->hasMany(ChannelTask::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Builder<Channel> $query
|
||||
* @return Builder<Channel>
|
||||
*/
|
||||
#[Scope]
|
||||
protected function active(Builder $query): Builder
|
||||
{
|
||||
return $query->where('is_active', true);
|
||||
}
|
||||
|
||||
public function connector(): ChannelConnector
|
||||
{
|
||||
return app(ChannelRegistry::class)->resolve($this->connector);
|
||||
}
|
||||
|
||||
public function importsOccupations(): bool
|
||||
{
|
||||
return $this->is_active && $this->connector()->canImport($this);
|
||||
}
|
||||
|
||||
public function exportUrl(): string
|
||||
{
|
||||
return route('channels.feed', ['token' => $this->export_token]);
|
||||
}
|
||||
|
||||
public function setting(string $key): mixed
|
||||
{
|
||||
return $this->settings[$key] ?? null;
|
||||
}
|
||||
|
||||
/**
|
||||
* The import is considered stale when no successful sync happened within the threshold.
|
||||
*/
|
||||
public function isStale(): bool
|
||||
{
|
||||
return $this->importsOccupations()
|
||||
&& ($this->last_success_at === null || $this->last_success_at->lessThan(now()->subMinutes(config('fewo.channels.stale_after_minutes'))));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Attributes\Fillable;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
|
||||
#[Fillable(['channel_id', 'successful', 'events', 'added', 'changed', 'removed', 'conflicts', 'message', 'duration_ms'])]
|
||||
class ChannelSyncLog extends Model
|
||||
{
|
||||
public const UPDATED_AT = null;
|
||||
|
||||
/**
|
||||
* Get the attributes that should be cast.
|
||||
*
|
||||
* @return array<string, string>
|
||||
*/
|
||||
protected function casts(): array
|
||||
{
|
||||
return [
|
||||
'successful' => 'boolean',
|
||||
'created_at' => 'immutable_datetime',
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return BelongsTo<Channel, $this>
|
||||
*/
|
||||
public function channel(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Channel::class);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,77 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use App\Enums\ChannelTaskAction;
|
||||
use App\Enums\ChannelTaskStatus;
|
||||
use Database\Factories\ChannelTaskFactory;
|
||||
use Illuminate\Database\Eloquent\Attributes\Fillable;
|
||||
use Illuminate\Database\Eloquent\Attributes\Scope;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
|
||||
/**
|
||||
* A change that has to be made by hand (or by an external automation) on a portal that
|
||||
* cannot be kept in sync fast enough by calendar feeds, e.g. because of instant booking.
|
||||
*/
|
||||
#[Fillable(['channel_id', 'action', 'starts_on', 'ends_on', 'reason', 'status', 'completed_by', 'completed_at', 'reminded_at', 'automation_sent_at', 'automation_error'])]
|
||||
class ChannelTask extends Model
|
||||
{
|
||||
/** @use HasFactory<ChannelTaskFactory> */
|
||||
use HasFactory;
|
||||
|
||||
/**
|
||||
* Get the attributes that should be cast.
|
||||
*
|
||||
* @return array<string, string>
|
||||
*/
|
||||
protected function casts(): array
|
||||
{
|
||||
return [
|
||||
'action' => ChannelTaskAction::class,
|
||||
'status' => ChannelTaskStatus::class,
|
||||
'starts_on' => 'immutable_date',
|
||||
'ends_on' => 'immutable_date',
|
||||
'completed_at' => 'immutable_datetime',
|
||||
'reminded_at' => 'immutable_datetime',
|
||||
'automation_sent_at' => 'immutable_datetime',
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return BelongsTo<Channel, $this>
|
||||
*/
|
||||
public function channel(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Channel::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Builder<ChannelTask> $query
|
||||
* @return Builder<ChannelTask>
|
||||
*/
|
||||
#[Scope]
|
||||
protected function open(Builder $query): Builder
|
||||
{
|
||||
return $query->where('status', ChannelTaskStatus::Open);
|
||||
}
|
||||
|
||||
public function complete(string $completedBy): void
|
||||
{
|
||||
$this->update([
|
||||
'status' => ChannelTaskStatus::Done,
|
||||
'completed_by' => $completedBy,
|
||||
'completed_at' => now(),
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Human readable period, e.g. "14.06.2027 – 21.06.2027".
|
||||
*/
|
||||
public function period(): string
|
||||
{
|
||||
return $this->starts_on->format('d.m.Y').' – '.$this->ends_on->format('d.m.Y');
|
||||
}
|
||||
}
|
||||
@@ -69,6 +69,14 @@ public function blockedPeriods(): HasMany
|
||||
return $this->hasMany(BlockedPeriod::class)->orderBy('starts_on');
|
||||
}
|
||||
|
||||
/**
|
||||
* @return HasMany<Channel, $this>
|
||||
*/
|
||||
public function channels(): HasMany
|
||||
{
|
||||
return $this->hasMany(Channel::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return HasMany<Amenity, $this>
|
||||
*/
|
||||
|
||||
Reference in new issue
Block a user