123 lines
3.4 KiB
PHP
123 lines
3.4 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use App\User;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
|
|
|
/**
|
|
* @property int $id
|
|
* @property string $event checkout_visited|form_submitted|payment_initiated|payment_returned|payment_confirmed
|
|
* @property string|null $session_id
|
|
* @property string|null $domain
|
|
* @property int|null $shopping_user_id
|
|
* @property int|null $shopping_order_id
|
|
* @property int|null $shopping_payment_id
|
|
* @property int|null $consultant_user_id
|
|
* @property string|null $payment_method
|
|
* @property string|null $return_status
|
|
* @property int|null $amount_cents
|
|
* @property array|null $metadata
|
|
* @property \Illuminate\Support\Carbon $created_at
|
|
*/
|
|
class CheckoutFunnelEvent extends Model
|
|
{
|
|
protected $fillable = [
|
|
'event',
|
|
'session_id',
|
|
'domain',
|
|
'shopping_user_id',
|
|
'shopping_order_id',
|
|
'shopping_payment_id',
|
|
'consultant_user_id',
|
|
'payment_method',
|
|
'return_status',
|
|
'amount_cents',
|
|
'metadata',
|
|
];
|
|
|
|
protected function casts(): array
|
|
{
|
|
return [
|
|
'metadata' => 'array',
|
|
'amount_cents' => 'integer',
|
|
];
|
|
}
|
|
|
|
public function shopping_order(): BelongsTo
|
|
{
|
|
return $this->belongsTo(ShoppingOrder::class);
|
|
}
|
|
|
|
public function shopping_payment(): BelongsTo
|
|
{
|
|
return $this->belongsTo(ShoppingPayment::class);
|
|
}
|
|
|
|
public function consultant(): BelongsTo
|
|
{
|
|
return $this->belongsTo(User::class, 'consultant_user_id');
|
|
}
|
|
|
|
/** @return array<string, string> */
|
|
public static function eventLabels(): array
|
|
{
|
|
return [
|
|
'checkout_visited' => 'Checkout aufgerufen',
|
|
'form_submitted' => 'Formular abgeschickt',
|
|
'payment_initiated' => 'Zahlung gestartet',
|
|
'payment_returned' => 'Zurück von PAYONE',
|
|
'payment_confirmed' => 'PAYONE Callback',
|
|
];
|
|
}
|
|
|
|
public function getEventLabelAttribute(): string
|
|
{
|
|
return self::eventLabels()[$this->event] ?? $this->event;
|
|
}
|
|
|
|
/**
|
|
* Classifies the domain into a human-readable source channel.
|
|
*
|
|
* - my.mivita.* → Salescenter (Berater-Bereich)
|
|
* - in.mivita.* → Beraterzugang (in.mivita.care login)
|
|
* - *.mivita.care → Kundenshop (Live)
|
|
* - *.mivita.shop → Kundenshop (Live)
|
|
* - *.mivita.test → Testserver
|
|
*/
|
|
public function getSourceTypeAttribute(): string
|
|
{
|
|
$domain = strtolower($this->domain ?? '');
|
|
|
|
if (str_starts_with($domain, 'my.')) {
|
|
return 'salescenter';
|
|
}
|
|
|
|
if (str_starts_with($domain, 'in.')) {
|
|
return 'beraterzugang';
|
|
}
|
|
|
|
if (str_ends_with($domain, '.test') || str_contains($domain, '.mivita.test')) {
|
|
return 'testserver';
|
|
}
|
|
|
|
if (str_ends_with($domain, '.care') || str_ends_with($domain, '.shop')) {
|
|
return 'kundenshop';
|
|
}
|
|
|
|
return 'unbekannt';
|
|
}
|
|
|
|
/** @return array<string, string> */
|
|
public static function sourceLabels(): array
|
|
{
|
|
return [
|
|
'kundenshop' => 'Kundenshop (*.mivita.care / *.mivita.shop)',
|
|
'salescenter' => 'Salescenter (my.mivita.care)',
|
|
'beraterzugang' => 'Beraterzugang (in.mivita.care)',
|
|
'testserver' => 'Testserver (*.mivita.test)',
|
|
'unbekannt' => 'Unbekannt',
|
|
];
|
|
}
|
|
}
|