ThemeExportJob.php 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2016~2026 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;
  12. use app\services\diy\ThemeDownloadServices;
  13. use app\services\diy\ThemeServices;
  14. use crmeb\basic\BaseJobs;
  15. use crmeb\traits\QueueTrait;
  16. use think\facade\Log;
  17. /**
  18. * 主题导出队列任务
  19. * Class ThemeExportJob
  20. * @package app\jobs
  21. */
  22. class ThemeExportJob extends BaseJobs
  23. {
  24. use QueueTrait;
  25. /**
  26. * 执行主题导出任务
  27. * 1. 打包主题文件生成 zip
  28. * 2. 将 download_url 写回 eb_theme_download 记录
  29. *
  30. * @param $info 主题信息
  31. * @param int $recordId eb_theme_download 记录ID
  32. * @return bool
  33. * @author wuhaotian
  34. * @email 442384644@qq.com
  35. * @date 2026/3/10
  36. */
  37. public function export($info, int $recordId): bool
  38. {
  39. try {
  40. /** @var ThemeServices $themeServices */
  41. $themeServices = app()->make(ThemeServices::class);
  42. /** @var ThemeDownloadServices $themeDownloadServices */
  43. $themeDownloadServices = app()->make(ThemeDownloadServices::class);
  44. $downloadUrl = $themeServices->exportThemePackage($info);
  45. // 将生成的下载地址写回下载记录
  46. $themeDownloadServices->updateDownloadUrl($recordId, $downloadUrl);
  47. } catch (\Throwable $e) {
  48. Log::error('主题导出队列失败,原因:' . $e->getMessage() . ' ' . $e->getFile() . ':' . $e->getLine());
  49. return false;
  50. }
  51. return true;
  52. }
  53. }