/
itp_practice
/
itp_backend
Обзор
Документация
Войти
/
itp_practice
/
itp_backend
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
master
app/Console/Commands/TestOrderPipeline.php
121 строка
4 KB
vivanenko
tariff buy
27 май 2025, 20:52
27 май 2025, 20:52
9a8b3c7
Код
Авторство
О чём код?
<?php namespace App\Console\Commands; use App\Models\User; use App\Models\Tariff; use App\Models\Order; use App\Models\CartItem; use Illuminate\Console\Command; class TestOrderPipeline extends Command { /** * The name and signature of the console command. * * @var string */ protected $signature = 'test:order-pipeline {--user-id=} {--tariff-id=}'; /** * The console command description. * * @var string */ protected $description = 'Test order pipeline with subscription creation'; /** * Execute the console command. */ public function handle() { $this->info('Starting order pipeline test...'); // Получаем или создаем пользователя $userId = $this->option('user-id'); if ($userId) { $user = User::find($userId); if (!$user) { $this->error("User with ID {$userId} not found"); return 1; } } else { $user = User::first(); if (!$user) { $user = User::factory()->create([ 'name' => 'Test User', 'email' => 'test@example.com' ]); $this->info("Created test user with ID: {$user->id}"); } } // Получаем тариф $tariffId = $this->option('tariff-id'); if ($tariffId) { $tariff = Tariff::find($tariffId); if (!$tariff) { $this->error("Tariff with ID {$tariffId} not found"); return 1; } } else { $tariff = Tariff::first(); if (!$tariff) { $this->error('No tariffs found in database'); return 1; } } $this->info("Using user: {$user->name} (ID: {$user->id})"); $this->info("Using tariff: {$tariff->name} (ID: {$tariff->id})"); // Создаем заказ $order = Order::create([ 'user_id' => $user->id, 'status_code' => 'pending', 'subtotal_amount' => $tariff->price, 'discount_amount' => 0, 'tax_amount' => 0, 'shipping_amount' => 0, 'total_amount' => $tariff->price, 'currency' => 'RUB', 'payment_gateway' => 'test' ]); $this->info("Created order with ID: {$order->id}"); // Создаем элемент корзины для заказа $cartItem = CartItem::create([ 'user_id' => $user->id, 'order_id' => $order->id, 'sku' => 'tariff_' . $tariff->id, 'itemable_type' => 'App\\Models\\Tariff', 'itemable_id' => $tariff->id, 'quantity' => 1, 'price' => $tariff->price, 'currency' => 'RUB' ]); $this->info("Created cart item with ID: {$cartItem->id}"); // Симулируем успешную оплату $this->info('Simulating payment success...'); $order->markAsPaid(); $order->save(); $this->info("Order status changed to: {$order->status_code}"); $this->info('Observer should have triggered the job pipeline'); // Проверяем результат sleep(2); // Даем время на обработку $subscriptions = \App\Models\UserTariffSubscription::where('user_id', $user->id)->count(); $this->info("User subscriptions count: {$subscriptions}"); $taps = \App\Models\Tap::where('crm_user_id', $user->id)->count(); $this->info("User taps count: {$taps}"); $this->info('Test completed!'); return 0; } }