Domäne: Rabattcodes mit Geltungsbereich (Warenkorb oder gewählte Ziele) und Einlösungsberechtigung (allgemein oder freigeschaltete Konten) unabhängig voneinander; Prüfung bei Eingabe, in jeder Übersicht und unter Sperre vor Bestellabschluss (Prüfsumme der Übersicht enthält den Rabatt). Rabatt je Position, Zwischensumme und Zahlbetrag in der Bestellung; Stripe erhält den Preis nach Rabatt. Nutzerkreis (Einzel-/Mehrfachlizenz, Trainerzahl) an der Angebotsfassung, kopiert in Bestellposition und Erwerb, Teil der Prüfung "Bereits erworben". OfferService::activate lehnt Angebote ohne veröffentlichten Artikelstand ab. Kasse: Zustimmungen als Pflichtangabe mit Nachweis, "Zahlungspflichtig bestellen", Rechnungsweg für Organisationen, Erstattung über Stripe, Widerruf erklären. Produktivfreigabe SHOP_LIVE_RELEASE standardmäßig aus. Bestandstests geändert (fachlich überholt, Assertions nicht abgeschwächt): die Schaltfläche heißt "Zahlungspflichtig bestellen" (§ 312j BGB), die Summe heißt "Zu zahlen", der Vereinshinweis steht als Rollenliste; Bestellungen über die Kasse senden jetzt die Zustimmungen. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
73 lines
1.7 KiB
PHP
73 lines
1.7 KiB
PHP
<?php
|
|
|
|
namespace App\Domain\Commerce;
|
|
|
|
use App\Domain\Identity\Party;
|
|
use App\Models\User;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
|
use Illuminate\Database\Eloquent\Relations\HasMany;
|
|
|
|
class Order extends Model
|
|
{
|
|
protected $fillable = [
|
|
'user_id',
|
|
'party_id',
|
|
'status',
|
|
'holder_kind',
|
|
'total_cents',
|
|
'currency',
|
|
'subtotal_cents',
|
|
'discount_cents',
|
|
'discount_code_id',
|
|
'discount_snapshot',
|
|
'payment_method',
|
|
'terms_accepted_at',
|
|
'terms_snapshot',
|
|
'withdrawal_requested_at',
|
|
'withdrawal_note',
|
|
];
|
|
|
|
protected function casts(): array
|
|
{
|
|
return [
|
|
'discount_snapshot' => 'array',
|
|
'terms_snapshot' => 'array',
|
|
'terms_accepted_at' => 'datetime',
|
|
'withdrawal_requested_at' => 'datetime',
|
|
];
|
|
}
|
|
|
|
/** Listenpreise vor Rabatt; bei älteren Bestellungen die Summe der Positionen. */
|
|
public function subtotal(): int
|
|
{
|
|
return (int) ($this->subtotal_cents ?? $this->total_cents ?? $this->lines->sum('price_cents'));
|
|
}
|
|
|
|
/** Endgültiger Zahlbetrag. */
|
|
public function payable(): int
|
|
{
|
|
return (int) ($this->total_cents ?? $this->lines->sum('price_cents'));
|
|
}
|
|
|
|
public function user(): BelongsTo
|
|
{
|
|
return $this->belongsTo(User::class);
|
|
}
|
|
|
|
public function party(): BelongsTo
|
|
{
|
|
return $this->belongsTo(Party::class);
|
|
}
|
|
|
|
public function lines(): HasMany
|
|
{
|
|
return $this->hasMany(OrderLine::class);
|
|
}
|
|
|
|
public function payments(): HasMany
|
|
{
|
|
return $this->hasMany(Payment::class);
|
|
}
|
|
}
|