ItemSalaryFTMultipleSheetExport.php 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. <?php
  2. namespace App\Exports;
  3. use Maatwebsite\Excel\Concerns\WithMultipleSheets;
  4. class ItemSalaryFTMultipleSheetExport implements WithMultipleSheets
  5. {
  6. protected $monthsData;
  7. protected $projects;
  8. protected $company;
  9. /**
  10. * @param array $monthsData 格式需要包含该月特有的项目列表:
  11. * [
  12. * '2024年4月' => [
  13. * 'projects' => ['RD01', 'RD02'],
  14. * 'data' => [ [...] ]
  15. * ],
  16. * '2024年5月' => [
  17. * 'projects' => ['RD03'],
  18. * 'data' => [ [...] ]
  19. * ]
  20. * ]
  21. */
  22. public function __construct(array $monthsData,$company)
  23. {
  24. $this->monthsData = $monthsData;
  25. $this->company = $company;
  26. }
  27. public function sheets(): array
  28. {
  29. $sheets = [];
  30. foreach ($this->monthsData as $month => $item) {
  31. // 每次实例化 Sheet 时,传入该月特有的 projects 列表
  32. $sheets[] = new ItemSalaryFTSheetExport(
  33. $month,
  34. $item['data'],
  35. $item['projects'],
  36. $this->company
  37. );
  38. }
  39. return $sheets;
  40. }
  41. }