海南旅游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.

48 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. /**
  13. * 导出全部产品
  14. */
  15. class ExportProductToExcel implements ShouldQueue
  16. {
  17. use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
  18. private int $supplier_id;
  19. /**
  20. * Create a new job instance.
  21. *
  22. * @return void
  23. */
  24. public function __construct(int $supplier_id)
  25. {
  26. $this->supplier_id = $supplier_id;
  27. }
  28. /**
  29. * Execute the job.
  30. *
  31. * @return void
  32. */
  33. public function handle()
  34. {
  35. $filePath = "supplier/export/{$this->supplier_id}/" . date('Y-m') . "/导出全部产品-" . date('Y-m-d_H-i-s') . '.xlsx';
  36. Excel::store(new ProductExport($this->supplier_id, 'all'), $filePath, 'public');
  37. ProductExportLog::create([
  38. 'supplier_id' => $this->supplier_id,
  39. 'filename' => $filePath,
  40. ]);
  41. }
  42. }