feat(invitation): update seat allocation structure and enhance provisioning logic
This commit is contained in:
@@ -17,21 +17,25 @@ class InvitationPurchaseProvisioner
|
||||
private const PAYMENT_METHOD = 'invitation';
|
||||
|
||||
/**
|
||||
* @var list<array{sector: string, row: int, seats: int, type: string}>
|
||||
* @var list<array{sector: string, row: int, first_seat: int, last_seat: int, type: string}>
|
||||
*/
|
||||
private const ALLOCATIONS = [
|
||||
['sector' => 'A', 'row' => 1, 'seats' => 16, 'type' => 'NORMAL'],
|
||||
['sector' => 'A', 'row' => 3, 'seats' => 14, 'type' => 'NORMAL'],
|
||||
['sector' => 'C', 'row' => 1, 'seats' => 16, 'type' => 'VIP + LUNCH'],
|
||||
['sector' => 'A', 'row' => 1, 'first_seat' => 1, 'last_seat' => 16, 'type' => 'NORMAL'],
|
||||
['sector' => 'A', 'row' => 3, 'first_seat' => 1, 'last_seat' => 14, 'type' => 'NORMAL'],
|
||||
['sector' => 'C', 'row' => 1, 'first_seat' => 1, 'last_seat' => 16, 'type' => 'VIP + LUNCH'],
|
||||
['sector' => 'C', 'row' => 3, 'first_seat' => 6, 'last_seat' => 7, 'type' => 'NORMAL'],
|
||||
];
|
||||
|
||||
public function provision(): void
|
||||
/**
|
||||
* @param list<array{sector: string, row: int, first_seat: int, last_seat: int, type: string}>|null $allocations
|
||||
*/
|
||||
public function provision(?array $allocations = null): void
|
||||
{
|
||||
if (! $this->prerequisitesExist()) {
|
||||
return;
|
||||
}
|
||||
|
||||
DB::transaction(function (): void {
|
||||
DB::transaction(function () use ($allocations): void {
|
||||
$now = now();
|
||||
$userId = $this->userId($now);
|
||||
$purchaseId = $this->purchaseId($userId, $now);
|
||||
@@ -44,8 +48,8 @@ class InvitationPurchaseProvisioner
|
||||
throw new RuntimeException('No se encontró el catálogo de entradas del desfile.');
|
||||
}
|
||||
|
||||
foreach (self::ALLOCATIONS as $allocation) {
|
||||
foreach (range(1, $allocation['seats']) as $seat) {
|
||||
foreach ($allocations ?? self::ALLOCATIONS as $allocation) {
|
||||
foreach (range($allocation['first_seat'], $allocation['last_seat']) as $seat) {
|
||||
$variant = $this->variant(
|
||||
(int) $catalogItem->id,
|
||||
$allocation['sector'],
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
<?php
|
||||
|
||||
use App\Domains\Desfile\Services\InvitationPurchaseProvisioner;
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
public function up(): void
|
||||
{
|
||||
app(InvitationPurchaseProvisioner::class)->provision([
|
||||
[
|
||||
'sector' => 'C',
|
||||
'row' => 3,
|
||||
'first_seat' => 6,
|
||||
'last_seat' => 7,
|
||||
'type' => 'NORMAL',
|
||||
],
|
||||
]);
|
||||
}
|
||||
|
||||
public function down(): void
|
||||
{
|
||||
// Intentionally irreversible: issued invitation tickets may already be used.
|
||||
}
|
||||
};
|
||||
@@ -288,19 +288,19 @@ class DesfilePuraTendenciaSeederTest extends TestCase
|
||||
|
||||
$items = DB::table('compra_items')->where('compra_id', $purchase->id);
|
||||
|
||||
$this->assertSame(46, (clone $items)->count());
|
||||
$this->assertSame(46, (clone $items)
|
||||
$this->assertSame(48, (clone $items)->count());
|
||||
$this->assertSame(48, (clone $items)
|
||||
->where('precio_unitario', 0)
|
||||
->where('discount_total', 0)
|
||||
->where('tax_total', 0)
|
||||
->where('total', 0)
|
||||
->count());
|
||||
$this->assertSame(46, DB::table('tickets')
|
||||
$this->assertSame(48, DB::table('tickets')
|
||||
->where('source_purchase_id', $purchase->id)
|
||||
->where('user_id', $user->id)
|
||||
->where('source_catalog_item_id', $catalogItemId)
|
||||
->count());
|
||||
$this->assertSame(46, DB::table('stock_reservations')
|
||||
$this->assertSame(48, DB::table('stock_reservations')
|
||||
->where('purchase_id', $purchase->id)
|
||||
->where('status', 'committed')
|
||||
->count());
|
||||
@@ -309,6 +309,7 @@ class DesfilePuraTendenciaSeederTest extends TestCase
|
||||
['sector' => 'A', 'fila' => '1', 'tipo' => 'NORMAL', 'count' => 16],
|
||||
['sector' => 'A', 'fila' => '3', 'tipo' => 'NORMAL', 'count' => 14],
|
||||
['sector' => 'C', 'fila' => '1', 'tipo' => 'VIP + LUNCH', 'count' => 16],
|
||||
['sector' => 'C', 'fila' => '3', 'tipo' => 'NORMAL', 'count' => 2, 'seats' => ['6', '7']],
|
||||
] as $allocation) {
|
||||
$allocatedVariants = DB::table('variantes')
|
||||
->where('catalog_item_id', $catalogItemId)
|
||||
@@ -326,6 +327,20 @@ class DesfilePuraTendenciaSeederTest extends TestCase
|
||||
}
|
||||
|
||||
$this->assertSame($allocation['count'], $allocatedVariants->count());
|
||||
|
||||
if (isset($allocation['seats'])) {
|
||||
$seatValues = DB::table('variant_values')
|
||||
->join('item_attributes', 'item_attributes.id', '=', 'variant_values.item_attribute_id')
|
||||
->join('attribute', 'attribute.id', '=', 'item_attributes.attribute_id')
|
||||
->whereIn('variant_values.variant_id', (clone $allocatedVariants)->pluck('id'))
|
||||
->where('attribute.codigo', 'asiento')
|
||||
->pluck('variant_values.value')
|
||||
->sort()
|
||||
->values()
|
||||
->all();
|
||||
|
||||
$this->assertSame($allocation['seats'], $seatValues);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user