海南旅游SAAS
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

45 lines
1.1 KiB

  1. <?php
  2. namespace App\Jobs;
  3. use App\Exports\ProductExport;
  4. use App\Models\ProductExportLog;
  5. use Illuminate\Bus\Queueable;
  6. use Illuminate\Contracts\Queue\ShouldBeUnique;
  7. use Illuminate\Contracts\Queue\ShouldQueue;
  8. use Illuminate\Foundation\Bus\Dispatchable;
  9. use Illuminate\Queue\InteractsWithQueue;
  10. use Illuminate\Queue\SerializesModels;
  11. use Maatwebsite\Excel\Facades\Excel;
  12. class ExportProductToExcel implements ShouldQueue
  13. {
  14. use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
  15. private int $supplier_id;
  16. /**
  17. * Create a new job instance.
  18. *
  19. * @return void
  20. */
  21. public function __construct(int $supplier_id)
  22. {
  23. $this->supplier_id = $supplier_id;
  24. }
  25. /**
  26. * Execute the job.
  27. *
  28. * @return void
  29. */
  30. public function handle()
  31. {
  32. $filePath = "supplier/export/{$this->supplier_id}/" . date('Y-m') . "/导出产品-" . date('Y-m-d_H-i-s') . '.xlsx';
  33. Excel::store(new ProductExport($this->supplier_id), $filePath, 'public');
  34. ProductExportLog::create([
  35. 'supplier_id' => $this->supplier_id,
  36. 'filename' => $filePath,
  37. ]);
  38. }
  39. }