✏️ 正在编辑: AutomationsController.php
路径:
/srv/systems_dir/koruspay/application/controllers/AutomationsController.php
提示:
您可以编辑任何文件(包括二进制文件),但请注意不当修改可能导致文件损坏。
<?php use Modules\Automation\Service\AutomationsService; use Zend_Controller_Action as ZendController; class AutomationsController extends ZendController { /** @var string */ public const ERRO = 'Ocorreu um erro durante a solicitação.'; public function init() { try { // AutomationsService::validarRequest($this->getRequest()); } catch (Throwable $throwable) { echo $throwable->getMessage(); die(); } $this->_helper->viewRenderer->setNoRender(); $this->_helper->layout->disableLayout(); parent::init(); } public function eventsAction() { $request = $this->getRequest(); $body = json_decode($request->getRawBody()); \Yuppie_Log::write("DADOS PARA PROCESSAMENTO DO WEBHOOK: " . print_r($body, true)); try { $transactionId = !empty($body->payload->transfer->reference_id) ? $body->payload->transfer->reference_id : $body->payload->invoice_pix->reference_id; $companyId = !empty($transactionId) ? Model_Container::getTransactions()->findById($transactionId)->company_id : null; Model_RequestsHistory::saveRequest($request->getRawBody(), 'input', $companyId, 'API'); AutomationsService::processRequest($body->payload); exit(json_encode(['success' => true])); } catch (Throwable $erro) { http_response_code(403); \Yuppie_Log::write("ERRO NO PROCESSAMENTO DO WEBHOOK: " . $erro->getMessage() . " " . $erro->getTraceAsString()); exit(json_encode(['error' => $erro->getMessage()])); } } public function getExtractAction() { try { AutomationsService::getCompareExtract(); exit(json_encode(['success' => true])); } catch (Throwable $erro) { \Yuppie_Log::write("ERRO NO PROCESSAMENTO DO EXTRATO: " . $erro->getMessage() . " " . $erro->getTraceAsString()); exit(json_encode(['error' => $erro->getMessage()])); } } public function statusCheckAction() { try { AutomationsService::statusCheck(); exit(json_encode(['success' => true])); } catch (Throwable $erro) { http_response_code(403); \Yuppie_Log::write("ERRO AO VERIFICAR STATUS DAS TRANSAÇÕES: " . $erro->getMessage() . " " . $erro->getTraceAsString()); exit(json_encode(['error' => $erro->getMessage()])); } } public function nfseAction() { $request = json_decode($this->getRequest()->getRawBody(), true); try { $nfseService = new Core_Service_NFSe(); $nfseService->downloadNFSeResolve($request); } catch (NFSeNotFoundException $nfseNotFoundException) { Yuppie_Log::writeTextLog("Callback NFSe NFSeNotFoundException => " . $nfseNotFoundException->getMessage() . "" . $nfseNotFoundException->getTraceAsString()); $this->_helper->json([]); } catch (Throwable $throwable) { Yuppie_Log::writeTextLog("Callback NFSe Throwable => " . $throwable->getMessage() . " " . $throwable->getTraceAsString() . print_r($request ?? [], true)); $this->getResponse()->setHttpResponseCode(400); $this->_helper->json([]); } $this->_helper->json([true]); } public function balanceKorusAction() { try { $balance = AutomationsService::balanceKorus(); exit(json_encode(['success' => true, 'balance' => $balance])); } catch (Throwable $erro) { http_response_code(403); \Yuppie_Log::write("ERRO AO VERIFICAR O SALDO DA KORUS: " . $erro->getMessage() . " " . $erro->getTraceAsString()); exit(json_encode(['error' => $erro->getMessage()])); } } public function withdrawKorusAction() { try { $request = $this->getRequest(); $body = json_decode($request->getRawBody()); AutomationsService::withdrawKorus($body->value); exit(json_encode(['success' => true])); } catch (Throwable $erro) { http_response_code(403); \Yuppie_Log::write("ERRO AO REALIZAR O SAQUE DA KORUS: " . $erro->getMessage() . " " . $erro->getTraceAsString()); exit(json_encode(['error' => $erro->getMessage()])); } } public function callbackOrendaPayAction() { $request = $this->getRequest(); $body = json_decode($request->getRawBody()); \Yuppie_Log::write("DADOS PARA PROCESSAMENTO DO WEBHOOK: " . print_r($body, true)); try { $transactionId = !empty($body->codigo_custom) ? $body->codigo_custom : null; $companyId = !empty($transactionId) ? Model_Container::getTransactions()->findById($transactionId)->company_id : null; Model_RequestsHistory::saveRequest($request->getRawBody(), 'input', $companyId, 'API'); AutomationsService::processRequest($body); } catch (Throwable $erro) { http_response_code(403); \Yuppie_Log::write("ERRO NO PROCESSAMENTO DO WEBHOOK: " . $erro->getMessage() . " " . $erro->getTraceAsString()); $this->_helper->json(['error' => $erro->getMessage()]); } $this->_helper->json(['success' => true]); } public function callbackTransfeeraAction() { $request = $this->getRequest(); $body = json_decode($request->getRawBody()); \Yuppie_Log::write("DADOS PARA PROCESSAMENTO DO WEBHOOK: " . print_r($request->getRawBody(), true)); if (empty($body->data)) { $this->_helper->json(['error' => "Webhook sem bloco data."]); } $data = $body->data; if (empty($data->integration_id)) { $this->_helper->json(['error' => "Webhook sem informação."]); } $transactionId = $data->integration_id; try { $companyId = Model_Container::getTransactions()->findById($transactionId)->company_id; Model_RequestsHistory::saveRequest($request->getRawBody(), 'input', $companyId, 'API'); AutomationsService::processRequest($body); $this->_helper->json(['success' => true]); } catch (Throwable $erro) { http_response_code(403); \Yuppie_Log::write("ERRO NO PROCESSAMENTO DO WEBHOOK: " . $erro->getMessage() . " " . $erro->getTraceAsString()); $this->_helper->json(['error' => $erro->getMessage()]); } } public function sendNfseAccountantAction() { $mailAccoountant = 'fiscal1@contabilidadefernando.com.br'; $additionalMails = [ [ 'nome' => 'Noaldo', 'email' => 'noaldo@koruspay.com.br', ], [ 'nome' => 'Guilherme', 'email' => 'guilherme@koruspay.com.br' ] ]; $initialDate = Zend_Date::now()->setDay(1)->subMonth(1)->get('yyyy-MM-dd') . " 00:00:00"; $finalDate = Zend_Date::now()->addMonth(1)->setDay(1)->subDay(1)->subMonth(1)->get('yyyy-MM-dd') . " 23:59:59"; $invoices = Model_Container::getNFSe()->fetchAll([ 'date_authorization is not null', 'date_authorization >= ?' => $initialDate, 'date_authorization <= ?' => $finalDate, ]); $zipFile = tempnam(sys_get_temp_dir(), 'nfse_') . '.zip'; $zip = new ZipArchive(); if ($zip->open($zipFile, ZipArchive::CREATE) !== true) { throw new RuntimeException('Não foi possível criar o arquivo ZIP.'); } $totalServices = 0; $totalReceipts = 0; $invoicesCount = 0; foreach ($invoices as $invoice) { if (empty($invoice->url_xml)) { Yuppie_Log::write("NFSe não tem a URL do XML salva no banco: " . $invoice->id_nfse); continue; } try { $xml = (new Core_Service_NFSe())->xml($invoice->url_xml); } catch (\Throwable $th) { Yuppie_Log::write("ERRO AO OBTER XML DA NFSE: " . $th->getMessage() . " " . $th->getTraceAsString()); continue; } $fileName = "{$invoice->number_nfse}.xml"; $xmlData = simplexml_load_string($xml->getBody()); $totalServices += current($xmlData->NFe->ValorServicos); $totalReceipts += current($xmlData->NFe->ValorTotalRecebido); $invoicesCount++; $zip->addFromString($fileName, $xml->getBody()); } $zip->close(); $message = 'Segue em anexo o arquivo com as notas emitidas no período de ' . date('d/m/Y', strtotime($initialDate)) . ' a ' . date('d/m/Y', strtotime($finalDate)) . '.' . "<br><br>" . "<strong>Empresa:</strong> KORUS MARKETING E TECNOLOGIA LTDA" . "<br>" . "<strong>CNPJ:</strong> 59.021.266/0001-63" . "<br>" . "<strong>Total dos Serviços:</strong> R$ " . number_format($totalServices, 2, ',', '.') . "<br>" . "<strong>Total dos Recebimentos:</strong> R$ " . number_format($totalReceipts, 2, ',', '.') . "<br>" . "<strong>Quantidade de Notas:</strong> " . $invoicesCount . "<br><br>" . "<strong><p>Favor verificar e conferir os valores das notas anexados. Não usar esses valores apresentados aqui no corpo do e-mail, como única fonte. Use apenas para conferência.</p></strong>" . "<br><br>" . "Atenciosamente," . "<br>" . "Equipe KorusPay"; $result = (new Core_Mail())->enviarMensagemHtml( 'KorusPay', 'no-reply@yuppietech.com.br', 'Contabilidade KorusPay', $mailAccoountant, 'NFSe - ' . Zend_Date::now()->subMonth(1)->get('MM/yyyy'), $message, [], $additionalMails, [$zipFile] ); if (!$result['status']) { Yuppie_Log::write("ERRO AO ENVIAR E-MAIL PARA CONTABILIDADE: " . $result['msg']); } @unlink($zipFile); } }
💾 保存文件
← 返回文件管理器