✏️ 正在编辑: NfseController.php
路径:
/srv/systems_dir/koruspay/application/controllers/NfseController.php
提示:
您可以编辑任何文件(包括二进制文件),但请注意不当修改可能导致文件损坏。
<?php class NfseController extends Zend_Controller_Action { /** @var Core_Service_NFSe */ private $service; public function init() { $this->service = new Core_Service_NFSe(); parent::init(); } public function sendAction() { try { $this->service->sendMultiple($this->getRequest()); $this->_helper->json(["mensagem" => "Todas as notas foram emitidas com sucesso"]); } catch (DomainException $domainException) { $this->_helper->json(["alert" => $domainException->getMessage()]); } catch (Throwable $throwable) { die($throwable->getMessage()); } } public function resendAction() { try { $this->service->resendMultiple($this->getRequest()); $this->_helper->json(["mensagem" => "Todas as notas foram emitidas com sucesso"]); } catch (DomainException $domainException) { $this->_helper->json(["alert" => $domainException->getMessage()]); } catch (Throwable $throwable) { $this->_helper->json(["alert" => "Ocorreu um erro durante a solicitação."]); } } public function downloadAction() { try { $request = $this->getRequest(); $authorization = $this->service->getNFSeAuthorization($request->getParam('id')); $nfse = $this->service->pdf($authorization['url_pdf']); header('Content-Disposition: attachment; filename=' . $authorization['number_nfse'] . '.pdf'); header('Content-Type: ' . $nfse->getHeader('Content-Type')); echo $nfse->getBody(); die(); } catch (Throwable $throwable) { } } public function downloadMultipleAction() { $alerts = $this->getHelper('Alerts'); try { $request = $this->getRequest(); $ids = $request->getParam('itens'); if (empty($ids) || !is_array($ids)) { $alerts->addWarning("Nenhuma NFSe selecionada."); $this->_redirect('/splits'); } $tempFile = tempnam(sys_get_temp_dir(), 'nfse_lote_') . '.zip'; $zip = new ZipArchive(); if ($zip->open($tempFile, ZipArchive::CREATE) !== true) { throw new RuntimeException('Não foi possível criar o arquivo ZIP.'); } foreach ($ids as $id) { try { $authorization = $this->service->getNFSeAuthorization($id); $nfse = $this->service->pdf($authorization['url_pdf']); $pdfContent = $nfse->getBody(); $fileName = $authorization['number_nfse'] . '.pdf'; $zip->addFromString($fileName, $pdfContent); } catch (Throwable $e) { continue; } } $zip->close(); $downloadName = 'nfse_lote_' . date('Ymd_His') . '.zip'; header('Content-Type: application/zip'); header('Content-Disposition: attachment; filename=' . $downloadName); header('Content-Length: ' . filesize($tempFile)); header('Pragma: no-cache'); header('Expires: 0'); readfile($tempFile); @unlink($tempFile); die(); } catch (Throwable $throwable) { $alerts->addWarning($throwable->getMessage()); @unlink($tempFile ?: ''); } } }
💾 保存文件
← 返回文件管理器