✏️ 正在编辑: TermoResponsabilidade.php
路径:
/srv/systems_dir/yuppiecred/application/services/Corretor/TermoResponsabilidade.php
提示:
您可以编辑任何文件(包括二进制文件),但请注意不当修改可能导致文件损坏。
<?php use Zend_Db_Table_Row as Row; use Zend_Controller_Request_Http as Request; class Service_Corretor_TermoResponsabilidade { /** @var Model_Corretor */ private $model; /** @var Model_TermoResponsabilidade */ private $termoModel; /** @var Service_Upload */ private $uploadService; /** @var Model_CorretorAssinaturaTermo */ private $corretorAssiantura; /** @var Yuppie_Core_Autentique_Receive */ private $autentiqueReceive; /** @var Service_S3 */ private $amazonS3; /** @var string */ public const TERMO_PATH = '/corretores/', FILENAME = 'termo-responsabilidade.pdf', PATH_UNDEFINED = 'nao-encontrado/', FILE_AUTENTIQUE = 'Termo Responsabilidade', EMAIL_INVALIDO = 'O Email do corretor precisa estar preenchido com um email válido.', ASSINATURA_PENDENTE = 'Existe uma assinatura pendente para este corretor.' ; public function __construct() { $this->model = model('corretor'); $this->termoModel = model('termo-responsabilidade'); $this->uploadService = service('upload'); $this->corretorAssiantura = model('corretor-assinatura'); $this->autentiqueReceive = new Yuppie_Core_Autentique_Receive(); $this->amazonS3 = service('s3'); } /** * @return stdClass */ public function getTermo(int $id): stdClass { $termo = new stdClass(); $termo->texto = $this->termoModel->getTermoOrThrow($id)['texto']; return $termo; } /** * @param int|null $corretorId * @param int|null $tipoAcesso * @return array */ public function getCorretorTermo(?int $corretorId, ?int $tipoAcesso = null): array { return $this->model->getCorretorTermo($corretorId, $tipoAcesso); } /** * @param int|null $corretor * @return string */ public function getPathResolve(?int $corretor): string { $this->uploadService->dirResolveCreate( UPLOAD_PATH . self::TERMO_PATH ); if (!$corretor) { $path = self::TERMO_PATH . self::PATH_UNDEFINED; $this->uploadService->dirResolveCreate(UPLOAD_PATH . $path); return $path . uniqid() . '_'; } $this->uploadService->dirResolveCreate( UPLOAD_PATH . self::TERMO_PATH . $corretor ); return self::TERMO_PATH . $corretor . '/'; } /** * @param Zend_Controller_Request_Http $request * @return bool */ public function receberDocumentoAssinado(Request $request): bool { $autentiqueDados = $this->autentiqueReceive->initValuesReceive($request->getPost()); if (!$autentiqueDados || !$autentiqueDados->getUuid()) { Yuppie_Log::write("Autentique: webhook sem UUID", $this); return false; } $dadosDoc = $this->corretorAssiantura->getByCorretorId(null, $autentiqueDados->getUuid()); if (!$dadosDoc) { Yuppie_Log::write("Autentique: Não localizou o doc " . $autentiqueDados->getUuid(), $this); return false; } $documentoAssinado = $this->saveDocumentoAssinado( $dadosDoc['corretor_id'], $autentiqueDados->getDocumentoAssinadoUrl() ); $this->autentiqueReceive->setDocumentoAssinado($documentoAssinado); $this->saveCorretorAssinaturaTermo($dadosDoc, $autentiqueDados); return true; } /** * @param array $dadosDoc * @param Yuppie_Core_Autentique_Receive $autentiqueReceive */ public function saveCorretorAssinaturaTermo(array $assinaturaTermo, Yuppie_Core_Autentique_Receive $autentiqueReceive): bool { $assinaturaTermo['result_assinatura'] = $autentiqueReceive->getPost(); $assinaturaTermo['data_assinatura'] = $autentiqueReceive->getDataAssinatura(); $assinaturaTermo['documento_assinado'] = $autentiqueReceive->getDocumentoAssinado(); $this->corretorAssiantura->save($assinaturaTermo); return true; } /** * @param int|null $corretor * @param string $urlDocument * @return string */ public function saveDocumentoAssinado(?int $corretor, string $urlDocument): string { $file = $this->getPathResolve($corretor) . 'assinado_' . uniqid() . '_' . self::FILENAME; $arrContextOptions = [ "ssl" => [ "verify_peer" => false, "verify_peer_name" => false ] ]; $content = file_get_contents($urlDocument, false, stream_context_create($arrContextOptions)); file_put_contents(UPLOAD_PATH . $file, $content); $this->amazonS3->putObject($file, UPLOAD_PATH . $file, true); return $file; } /** * @param int $corretor * @param string $email * @param string|null $uuid */ public function saveSolicitacaoAssinatura(int $corretor, string $email, int $termoId, ?string $uuid): void { $assinaturaTermo = $this->corretorAssiantura->getByCorretorId($corretor, $uuid); $assinaturaTermo['corretor_id'] = $corretor; $assinaturaTermo['termo_id'] = $termoId; $assinaturaTermo['corretor_email'] = $email; $assinaturaTermo['data_solicitacao'] = Zend_Date::now()->get("yyyy-MM-dd H:m:s"); $assinaturaTermo['uuid'] = $uuid; $this->corretorAssiantura->save($assinaturaTermo); } /** * @param array $corretor * @param string $file * @return string */ public function sendAutentiqueDocument(array $corretor, string $file): string { if (empty($corretor['email'])) { throw new DomainException(self::EMAIL_INVALIDO); } $autentique = new Yuppie_Core_Autentique_Send(); $autentique->initValuesReceive($corretor['email'], self::FILE_AUTENTIQUE, UPLOAD_PATH . $file); $autentiqueToken = service('config')->get()->autentique; if (!empty($this->termoModel->getEmpresaId())) { $empresa = (new Model_Empresa())->exibir($this->termoModel->getEmpresaId()); if ($empresa->autentique_token) { $autentiqueToken = new stdClass(); $autentiqueToken->token = $empresa->autentique_token; } } $autentiqueDoc = new Yuppie_Core_Autentique_Document($autentiqueToken); $docCreated = $autentiqueDoc->create($autentique); unlink(UPLOAD_PATH . $file); return $docCreated->uuid; } /** * @param int $termoId * @param int $corretor * @param string $email * @return bool */ public function hasTermoEnviado(int $termoId, int $corretor, string $email): bool { return $this->corretorAssiantura->hasTermoEnviado($termoId, $corretor, $email); } /** * @param int $termoId * @return array */ public function getTermoEnviado(int $termoId, int $corretorId): array { $this->getTermo($termoId); return $this->corretorAssiantura->getTermoEnviado($termoId, $corretorId); } /** * @param string $uuid * @return int */ public function removerTermoPendente(string $uuid) { $autentiqueToken = service('config')->get()->autentique; if (!empty($this->termoModel->getEmpresaId())) { $empresa = (new Model_Empresa())->exibir($this->termoModel->getEmpresaId()); if ($empresa->autentique_token) { $autentiqueToken = new stdClass(); $autentiqueToken->token = $empresa->autentique_token; } } try { $autentiqueDoc = new Yuppie_Core_Autentique_Document($autentiqueToken); $autentiqueDoc->remove($uuid); } catch (Exception $exception) { } finally { return (new Model_CorretorAssinaturaTermo())->delete($uuid); } } /** * @param int $corretor * @param string $email * @throws \Mpdf\MpdfException */ public function sendExterno(int $corretor, string $email, int $termoId): void { $path = $this->getPathResolve($corretor); $view = new \Zend_View(); $view->setScriptPath(APPLICATION_PATH . '/views/scripts'); $file = $path . self::FILENAME; $view->corretor = (new Model_Corretor())->exibir($corretor)->toArray(); $view->termo = $this->getTermo($termoId); \Core_PDF::outputPdfHtml(UPLOAD_PATH . $file, $view->render('termo-responsabilidade/imprimir.phtml')); $dados = []; $dados['email'] = $email; $uuid = $this->sendAutentiqueDocument($dados, $file); $this->saveSolicitacaoAssinatura($corretor, $email, $termoId, $uuid); } }
💾 保存文件
← 返回文件管理器