ExportExcelJob.php 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2016~2020 https://www.crmeb.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
  8. // +----------------------------------------------------------------------
  9. // | Author: CRMEB Team <admin@crmeb.com>
  10. // +----------------------------------------------------------------------
  11. namespace app\jobs\system;
  12. use crmeb\basic\BaseJobs;
  13. use crmeb\traits\QueueTrait;
  14. use crmeb\services\SpreadsheetExcelService;
  15. use think\facade\Log;
  16. /**
  17. * 导出数据队列
  18. * Class ExportExcelJob
  19. * @package app\jobs
  20. */
  21. class ExportExcelJob extends BaseJobs
  22. {
  23. use QueueTrait;
  24. /**
  25. * 分批导出excel
  26. * @param $order
  27. * @return bool
  28. */
  29. public function doJob(array $export = [], string $filename = '', array $header = [], array $title_arr = [], string $suffix = 'xlsx', bool $is_save = false)
  30. {
  31. if (!$export) {
  32. return true;
  33. }
  34. try {
  35. if ($header && $title_arr) {
  36. $title = isset($title_arr[0]) && !empty($title_arr[0]) ? $title_arr[0] : '导出数据';
  37. $name = isset($title_arr[1]) && !empty($title_arr[1]) ? $title_arr[1] : '导出数据';
  38. $info = isset($title_arr[2]) && !empty($title_arr[2]) ? $title_arr[2] : date('Y-m-d H:i:s', time());
  39. SpreadsheetExcelService::instance()
  40. ->setExcelHeader($header)
  41. ->setExcelTile($title, $name, $info)
  42. ->setExcelContent($export)
  43. ->excelSave($filename, $suffix, $is_save);
  44. } else {
  45. SpreadsheetExcelService::instance()
  46. ->setExcelContent($export)
  47. ->excelSave($filename, $suffix, $is_save);
  48. }
  49. } catch (\Throwable $e) {
  50. Log::error('导出excel' . $title . '失败,原因:' . $e->getMessage());
  51. }
  52. return true;
  53. }
  54. }