Răsfoiți Sursa

Begin export

Alexander Musikhin 10 luni în urmă
părinte
comite
c1e26b3620

+ 8 - 0
app/Http/Controllers/ProductController.php

@@ -47,6 +47,14 @@ class ProductController extends Controller
         // dispatch job
         ImportCatalog::dispatch($path, $request->year, $request->user()->id);
         Log::info('ImportCatalog job created!');
+        return redirect()->route('catalog.index')->with(['success' => 'Задача импорта успешно создана!']);
+    }
+
+    public function export(Request $request)
+    {
+
+
+
         return redirect()->route('catalog.index')->with(['success' => 'Задача импорта успешно создана!']);
     }
 }

+ 38 - 0
app/Jobs/Export/ExportCatalog.php

@@ -0,0 +1,38 @@
+<?php
+
+namespace App\Jobs\Export;
+
+use App\Events\SendWebSocketMessageEvent;
+use App\Services\ExportService;
+use Exception;
+use Illuminate\Contracts\Queue\ShouldQueue;
+use Illuminate\Foundation\Queue\Queueable;
+use Illuminate\Support\Facades\Log;
+
+class ExportCatalog implements ShouldQueue
+{
+    use Queueable;
+
+    /**
+     * Create a new job instance.
+     */
+    public function __construct(private readonly int $userId)
+    {
+        // can add where clauses
+    }
+
+    /**
+     * Execute the job.
+     */
+    public function handle(): void
+    {
+        try {
+            $file = (new ExportService())->handle();
+            Log::info('ExportCatalog job done!');
+            event(new SendWebSocketMessageEvent('Экспорт завершён!', $this->userId, ['download' => $file]));
+        } catch (Exception $e) {
+            Log::info('ExportCatalog job failed!');
+            event(new SendWebSocketMessageEvent('Ошибка экспорта! ' . $e->getMessage(), $this->userId, ['error' => $e->getMessage()]));
+        }
+    }
+}

+ 21 - 0
app/Services/ExportService.php

@@ -0,0 +1,21 @@
+<?php
+
+namespace App\Services;
+
+use App\Models\Product;
+
+class ExportService
+{
+
+
+    public function handle(): string
+    {
+        $products = Product::cursor();
+
+        foreach ($products as $product) {
+            dump($product->id);
+        }
+
+        return 'path';
+    }
+}

+ 1 - 1
resources/sass/app.scss

@@ -18,7 +18,7 @@
   position: absolute;
   right: 0;
   top: 0;
-  opacity: 0.8;
+  opacity: 0.95;
   z-index: 999;
 
 

BIN
templates/ExportCatalogTemplate.xlsx