- Brand/Theming: Marketing-Farb- und Typographievariablen in `resources/css/app.css` eingeführt, AdminLayout, Dashboardkarten und Onboarding-Komponenten entsprechend angepasst; Dokumentation (`docs/todo/tenant-admin-onboarding-fusion.md`, `docs/changes/...`) aktualisiert. - Checkout & Payments: Checkout-, PayPal-Controller und Tests für integrierte Stripe/PayPal-Flows sowie Paket-Billing-Abläufe überarbeitet; neue PayPal SDK-Factory und Admin-API-Helper (`resources/js/admin/api.ts`) schaffen Grundlage für Billing/Members/Tasks-Seiten. - DX & Tests: Neue Playwright/E2E-Struktur (docs/testing/e2e.md, `tests/e2e/tenant-onboarding-flow.test.ts`, Utilities), E2E-Tenant-Seeder und zusätzliche Übersetzungen/Factories zur Unterstützung der neuen Flows. - Marketing-Kommunikation: Automatische Kontakt-Bestätigungsmail (`ContactConfirmation` + Blade-Template) implementiert; Guest-PWA unter `/event` erreichbar. - Nebensitzung: Blogsystem gefixt und umfassenden BlogPostSeeder für Beispielinhalte angelegt.
148 lines
3.7 KiB
PHP
148 lines
3.7 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use Illuminate\Database\Eloquent\Casts\Attribute;
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Database\Eloquent\Relations\HasMany;
|
|
use Illuminate\Database\Eloquent\Relations\HasManyThrough;
|
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
|
use Illuminate\Database\Eloquent\Relations\HasOne;
|
|
use Illuminate\Support\Facades\DB;
|
|
use App\Models\EventCreditsLedger;
|
|
|
|
class Tenant extends Model
|
|
{
|
|
use HasFactory;
|
|
|
|
protected $table = 'tenants';
|
|
protected $guarded = [];
|
|
|
|
protected $casts = [
|
|
'features' => 'array',
|
|
'settings' => 'array',
|
|
'last_activity_at' => 'datetime',
|
|
'total_revenue' => 'decimal:2',
|
|
'settings_updated_at' => 'datetime',
|
|
'subscription_expires_at' => 'datetime',
|
|
];
|
|
|
|
public function events(): HasMany
|
|
{
|
|
return $this->hasMany(Event::class);
|
|
}
|
|
|
|
public function photos(): HasManyThrough
|
|
{
|
|
return $this->hasManyThrough(
|
|
Photo::class,
|
|
Event::class,
|
|
'tenant_id',
|
|
'event_id',
|
|
'id',
|
|
'id'
|
|
);
|
|
}
|
|
|
|
public function purchases(): HasMany
|
|
{
|
|
return $this->hasMany(PackagePurchase::class);
|
|
}
|
|
|
|
public function tenantPackages(): HasMany
|
|
{
|
|
return $this->hasMany(TenantPackage::class);
|
|
}
|
|
|
|
public function activeResellerPackage(): HasOne
|
|
{
|
|
return $this->hasOne(TenantPackage::class)->where('active', true);
|
|
}
|
|
|
|
public function canCreateEvent(): bool
|
|
{
|
|
$package = $this->activeResellerPackage()->first();
|
|
if (!$package) {
|
|
return false;
|
|
}
|
|
|
|
return $package->canCreateEvent();
|
|
}
|
|
|
|
public function incrementUsedEvents(int $amount = 1): bool
|
|
{
|
|
$package = $this->activeResellerPackage()->first();
|
|
if (!$package) {
|
|
return false;
|
|
}
|
|
|
|
$package->increment('used_events', $amount);
|
|
return true;
|
|
}
|
|
|
|
public function setSettingsAttribute($value): void
|
|
{
|
|
if (is_string($value)) {
|
|
$this->attributes['settings'] = $value;
|
|
return;
|
|
}
|
|
|
|
$this->attributes['settings'] = json_encode($value ?? []);
|
|
}
|
|
|
|
public function incrementCredits(int $amount, string $reason = 'manual', ?string $note = null, ?int $purchaseId = null): bool
|
|
{
|
|
if ($amount <= 0) {
|
|
return false;
|
|
}
|
|
|
|
$balance = (int) ($this->event_credits_balance ?? 0) + $amount;
|
|
$this->forceFill(['event_credits_balance' => $balance])->save();
|
|
|
|
EventCreditsLedger::create([
|
|
'tenant_id' => $this->id,
|
|
'delta' => $amount,
|
|
'reason' => $reason,
|
|
'related_purchase_id' => $purchaseId,
|
|
'note' => $note,
|
|
]);
|
|
|
|
return true;
|
|
}
|
|
|
|
public function decrementCredits(int $amount, string $reason = 'usage', ?string $note = null, ?int $purchaseId = null): bool
|
|
{
|
|
$current = (int) ($this->event_credits_balance ?? 0);
|
|
|
|
if ($amount <= 0 || $amount > $current) {
|
|
return false;
|
|
}
|
|
|
|
$balance = $current - $amount;
|
|
$this->forceFill(['event_credits_balance' => $balance])->save();
|
|
|
|
EventCreditsLedger::create([
|
|
'tenant_id' => $this->id,
|
|
'delta' => -$amount,
|
|
'reason' => $reason,
|
|
'related_purchase_id' => $purchaseId,
|
|
'note' => $note,
|
|
]);
|
|
|
|
return true;
|
|
}
|
|
|
|
public function activeSubscription(): Attribute
|
|
{
|
|
return Attribute::make(
|
|
get: fn () => $this->activeResellerPackage()->exists(),
|
|
);
|
|
}
|
|
|
|
public function user(): BelongsTo
|
|
{
|
|
return $this->belongsTo(User::class);
|
|
}
|
|
}
|