CaiWuXiTong/app/Jobs/Common/CreateZipForDownload.php
15061959991 1adf627c0d feat: 财务系统二次开发 - 营销账户账单功能
- 基础环境:Docker 部署配置,源码挂载实时同步
- 修复:super_admin 权限补全、登录重定向循环
- 开发:店铺营销账户账单 - 抖音账户(15字段汇总账单)
- 开发:店铺营销账户账单 - 淘系支付宝账户(8字段流水账单)
- 开发:店铺营销账户账单 - 拼多多账户(7字段流水账单)
- 业务页面导航集成:config/business_navigation.php + Business\Pages 控制器
- 各平台独立表结构和视图,互不影响
2026-07-21 18:43:52 +08:00

111 lines
2.8 KiB
PHP

<?php
namespace App\Jobs\Common;
use App\Abstracts\JobShouldQueue;
use Illuminate\Support\Facades\File;
use Illuminate\Support\Facades\Storage;
use ZipArchive;
class CreateZipForDownload extends JobShouldQueue
{
public $selected;
public $class;
public $file_name;
/**
* Create a new job instance.
*
* @param $selected
* @param $class
* @param $file_name
*/
public function __construct($selected, $class, $file_name)
{
$this->selected = $selected;
$this->class = $class;
$this->file_name = $file_name;
$this->onQueue('jobs');
}
public function handle()
{
$zip_archive = new ZipArchive();
$folder_path = 'app' . DIRECTORY_SEPARATOR . 'temp' . DIRECTORY_SEPARATOR . company_id() . DIRECTORY_SEPARATOR . 'bulk_actions' . DIRECTORY_SEPARATOR;
File::ensureDirectoryExists(storage_path($folder_path));
File::ensureDirectoryExists(get_storage_path($folder_path));
$zip_path = storage_path($folder_path . $this->file_name . '.zip');
$zip_archive->open($zip_path, ZipArchive::CREATE | ZipArchive::OVERWRITE);
foreach ($this->selected as $selected) {
$pdf_path = $this->dispatch(new $this->class($selected, $folder_path));
$fileContent = $this->getQueuedFile($pdf_path);
$zip_archive->addFromString(basename($pdf_path), $fileContent);
/*
Storage::disk('local')->put($folder_path . basename($pdf_path), $fileContent);
$zip->addFile(storage_path($folder_path . basename($pdf_path)), basename($pdf_path));
*/
}
$zip_archive->close();
$this->copyQueuedFile($folder_path, $zip_path);
return $zip_path;
}
public function getQueuedFile($pdf_path)
{
return config('dompdf.disk') !== null
? $this->getRemoteQueuedMedia($pdf_path)
: $this->getLocalQueuedMedia($pdf_path);
}
public function getLocalQueuedMedia($pdf_path)
{
$content = File::get($pdf_path);
return $content;
}
public function getRemoteQueuedMedia($pdf_path)
{
$disk = config('dompdf.disk');
$content = Storage::disk($disk)->get($pdf_path);
return $content;
}
public function copyQueuedFile($folder_path, $zip_path)
{
return config('dompdf.disk') !== null
? $this->copyRemoteQueuedMedia($folder_path, $zip_path)
: true;
}
public function copyRemoteQueuedMedia($folder_path, $zip_path)
{
$disk = config('dompdf.disk');
$file_path = get_storage_path($folder_path . basename($zip_path));
$content = Storage::disk($disk)->put($file_path, fopen($zip_path, 'r+'));
report($file_path);
return $content;
}
}