✏️ 正在编辑: CallcenterFerramentasController.php
路径:
/srv/systems_dir/yuppiecred/application/controllers/CallcenterFerramentasController.php
提示:
您可以编辑任何文件(包括二进制文件),但请注意不当修改可能导致文件损坏。
<?php class CallcenterFerramentasController extends Zend_Controller_Action { public function init() { $this->_helper->layout->setLayout('layout_callcenter'); } public function mensagemAction() { $form = new Form_Filtro_CallcenterFerramentaMensagem(); $request = $this->getRequest(); $ns = new Zend_Session_Namespace('filtro_callcenter_msg'); if( $request->isPost() && $form->isValid($request->getPost()) ){ $ns->filtro_callcenter_msg = $request->getPost(); } if( isset($ns->filtro_callcenter_msg) ){ $form->populate($ns->filtro_callcenter_msg); $model = new Model_CallcenterMensagem(); $select = $model->listar($ns->filtro_callcenter_msg, 'assunto ASC'); $this->view->mensagens = $select; } $this->view->form = $form; } public function mensagemSaveAction() { $request = $this->getRequest(); $id = (int) $request->getParam('id'); $form = new Form_CallcenterFerramentaMensagem(); if( ($request->getPost('tipo') == "SMS-TEXTO") || ($request->getPost('tipo') == "MSG-VOZ") ){ if( $request->getPost('tipo') == "SMS-TEXTO" ){ $validator = new Validators_TamanhoString(array( 'min' => 1, 'max' => 160 )); //160 } else { $validator = new Validators_TamanhoString(array( 'min' => 1, 'max' => 351 )); //351 } $form->getElement('mensagem')->addValidator($validator); } if( $request->isPost() ){ if( $form->isValid($request->getPost()) ){ $mensagem = new Model_CallcenterMensagem($request->getPost()); try { $id = $mensagem->salvar($mensagem); $this->_helper->flashMessenger(array( 'success' => 'Dados salvos com sucesso.' )); } catch ( Zend_Exception $e ) { $this->_helper->flashMessenger($e->getMessage()); } } } if( $id > 0 ){ $mensagem = new Model_CallcenterMensagem(); $dados = $mensagem->exibir($id); $form->populate($dados->toArray()); } $this->view->form = $form; } public function mensagemDeleteAction() { $request = $this->getRequest(); $id = (int) $request->getParam('id'); if( $id > 0 ){ $banco = new Model_CallcenterMensagem(); $retorno = $banco->excluir($id); } if( $retorno ){ $this->_helper->flashMessenger(array( 'success' => 'Mensagem excluída com sucesso.' )); } else { $this->_helper->flashMessenger(array( 'A mensagem não foi excluída.' )); } $this->_redirect('callcenter-ferramentas/mensagem'); } public function escolherMensagemAction() { set_time_limit(0); $request = $this->getRequest(); $id = (int) $request->getParam('id'); $form = new Form_Filtro_CallcenterFerramentaCampanha(); /* Informaçãoes da Mensagem */ $modelMensagem = new Model_CallcenterMensagem(); $mensagem = $modelMensagem->exibir($id); $tipoMensagem = $mensagem->tipo; $this->view->mensagem = $mensagem; if( $id > 0 ){ $this->view->form = $form; $fields = $request->getPost(); if( $request->isPost() && $form->isValid($fields) ){ $fields['tipo_mensagem'] = $tipoMensagem; $base = $modelMensagem->getBaseCliente($fields, 'campanhas.id'); if( count($base) <= 0 ){ $this->_helper->flashMessenger(array( "alert" => "Nenhuma contato apto para esta campanha para o tipo selecionado ({$tipoMensagem})." )); } $this->view->base = $base; $ns = new Zend_Session_Namespace('filtro_callcenter_mensagem'); $ns->filtro_callcenter_mensagem = $fields; } } else { $this->_helper->flashMessenger(array ( 'Mensagem não localizada.' )); } } public function enviarMsgVozAction() { $request = $this->getRequest(); $modelMensagem = new Model_CallcenterMensagem(); $modelHistorico = new Model_DbTable_CallcenterMensagemHistorico(); $qtdeSucesso = $qtdeFalha = 0; $msg = $request->getParam('msg'); $base = $request->getParam('base'); $campanha = $request->getParam('campanha'); $config = new Zend_Config_Ini(CLIENT_PATH . "/configs/application.ini"); if( empty($config->production->mobipronto->user) || empty($config->production->mobipronto->credencial) ){ $this->_helper->flashMessenger(array( "alert" => "Dados de integração com o MobiPronto não estão configurados." )); $this->_redirect("/callcenter-ferramentas/mensagem"); } $arrayRetorno = array(); $principalUser = isset($config->production->mobipronto->user) ? $config->production->mobipronto->user : null; $credencial = isset($config->production->mobipronto->credencial) ? $config->production->mobipronto->credencial : null; $tokenGateway = isset($config->production->mobipronto->tokenGatewayVoz) ? $config->production->mobipronto->tokenGatewayVoz : null; try { $mobilePronto = new Yuppie_Service_Sms_MobilePronto($principalUser, $credencial); $mobilePronto->setTokenGateway($tokenGateway); } catch ( Exception $ex ) { $this->_helper->flashMessenger(array( "alert" => $ex->getMessage() )); $this->_redirect("/callcenter-ferramentas/mensagem"); } if( $request->isPost() ){ $listaTel = array(); if( count($base) > 0 ){ foreach ( $base as $cliente ) { /* Substituir variaveis da mensagem caso existam */ $msgAtualizada = $modelMensagem->processarMensagem($msg->mensagem, $cliente); try { /* Retornar telefone caso seja válido */ $tel = Core_Service_Sms::isValidPhone($cliente['fone']); /* Envio via MobiPronto */ $envio = $mobilePronto->sendVoice($tel, $msgAtualizada); $qtdeSucesso++; $cliente['retorno'] = $envio; $arrayRetorno[] = $cliente; /* Inserindo no Histórico */ $modelHistorico->insert( array( 'usuario' => Yuppie_Auth::getIdentity()->login, 'base_id' => $cliente['cliente_id'], 'mensagem_id' => $msg->id, 'campanha_id' => $campanha->id, 'tipo' => "voz", 'retorno' => $envio, ) ); } catch ( Exception $ex ) { /* Inserindo no Histórico */ $modelHistorico->insert( array( 'usuario' => Yuppie_Auth::getIdentity()->login, 'base_id' => $cliente['cliente_id'], 'mensagem_id' => $msg->id, 'campanha_id' => $campanha->id, 'tipo' => "voz", 'retorno' => $ex->getMessage(), ) ); $cliente['retorno'] = $ex->getMessage(); $arrayRetorno[] = $cliente; $qtdeFalha++; } } if( $qtdeSucesso ){ $this->_helper->flashMessenger(array( "success" => "{ $qtdeSucesso} MSG-VOZ enviada(s)" )); } if( $qtdeFalha ){ $this->_helper->flashMessenger(array( "alert" => "{$qtdeFalha} falha(s) " )); } } else { $this->_helper->flashMessenger(array( "alert" => "Nenhum contato apto para envio de MSG-VOZ." )); } } $this->view->retorno = $arrayRetorno; $this->render('retorno-envio'); } public function arquivoMalaDiretaAction() { $request = $this->getRequest(); $modelMensagem = new Model_CallcenterMensagem(); $msg = $request->getParam('msg'); $base = $request->getParam('base'); if( $request->isPost() ){ if( count($base) > 0 ){ $modelMensagem->gerarArquivoMalaDireta($base, $msg); $this->getHelper('Layout')->disableLayout(); $this->getHelper('ViewRenderer')->setNoRender(true); } else { $this->_helper->flashMessenger(array ( "alert" => "Nenhum cliente encontrado." )); } } } public function enviarSmsTextoAction() { set_time_limit(0); $request = $this->getRequest(); $qtdeSucesso = $qtdeFalha = 0; $mensagemId = $request->getParam('id'); $mensagem = new Model_CallcenterMensagem(); $mensagem->setOptions($mensagem->exibir($mensagemId)->toArray()); $ns = new Zend_Session_Namespace('filtro_callcenter_mensagem'); $contatos = $mensagem->getBaseCliente($ns->filtro_callcenter_mensagem, "fones.id", "rand()"); if( $request->isPost() && $mensagem->getId() > 0 ){ if( count($contatos) > 0 ){ $enviados = []; foreach ( $contatos as $base ) { if( in_array($base['fone'], $enviados) ){ continue; } $fones = [ 0 => [ 'fone' => $base['fone'] ] ]; try{ $result = $mensagem->enviarSms($fones, $base); } catch (Exception $ex) { $this->_helper->flashMessenger(["alert" => $ex->getMessage()]); } if( $result ){ $qtdeSucesso++; $enviados[] = $base['fone']; }else{ $qtdeFalha++; } } if( $qtdeSucesso ){ $this->_helper->flashMessenger(["success" => "{$qtdeSucesso} SMS enviado(s)."]); } if( $qtdeFalha ){ $this->_helper->flashMessenger(["alert" => "{$qtdeFalha} falha(s) "]); } } else { $this->_helper->flashMessenger(["alert" => "Nenhum contato apto para envio de SMS."]); } } $this->_redirect("/callcenter-ferramentas/mensagem"); } public function enviarMsgEmailAction() { die('Bloqueado Temporariamente'); set_time_limit(0); $request = $this->getRequest(); if (empty(Yuppie_Auth::getIdentity()->email)){ $this->_helper->flashMessenger( [ "alert" => "Seu usuário não possui e-mail cadastrado. " . "Ajuste o seu cadastro, saia do Yuppie e entre " . "novamente para poder efetuar o envio." ]); $this->_redirect("/callcenter-ferramentas/mensagem"); } if ($request->isPost()) { $qtdeSucesso = $qtdeFalha = 0; $arrayRetorno = []; $emailsEnviados = []; $mensagemId = $request->getParam('id'); $mensagem = new Model_CallcenterMensagem(); $msg = $mensagem->exibir($mensagemId)->toArray(); $ns = new Zend_Session_Namespace('filtro_callcenter_mensagem'); $base = $mensagem->getBaseCliente($ns->filtro_callcenter_mensagem, "base.email", "rand()"); foreach ($base as $cliente) { if (in_array($cliente['email'], $emailsEnviados) ){ continue; } $assuntoAtualizado = (new Model_CallcenterMensagem())->processarMensagem($msg['assunto'], $cliente); $msgAtualizada = (new Model_CallcenterMensagem())->processarMensagem($msg['mensagem'], $cliente, true); try { $mail = new Core_Mail(); $mail->enviarMensagemHtml($cliente['nome'], $cliente['email'], $assuntoAtualizado, $msgAtualizada); $cliente['retorno'] = "E-mail enviado com sucesso"; $qtdeSucesso++; } catch ( Zend_Mail_Exception $e ) { $qtdeFalha++; $cliente['retorno'] = $e->getMessage(); } /* Inserindo no Histórico */ (new Model_DbTable_CallcenterMensagemHistorico())->insert( [ 'usuario' => Yuppie_Auth::getIdentity()->login, 'base_id' => $cliente['id'], 'mensagem_id' => $msg['id'], 'campanha_id' => $cliente['campanha_id'], 'tipo' => "email", 'retorno' => $cliente['retorno'], ] ); $arrayRetorno[] = $cliente; $emailsEnviados[] = $cliente['email']; } if ($qtdeSucesso) { $this->_helper->flashMessenger(array( "success" => "{$qtdeSucesso} e-mails enviado(s) com sucesso" )); } if ($qtdeFalha) { $this->_helper->flashMessenger(array( "alert" => "{$qtdeFalha} falha(s) " )); } $this->view->retorno = $arrayRetorno; $this->render('retorno-envio'); return; } $this->_redirect("/callcenter-ferramentas/mensagem"); } public function etiquetasAction() { $request = $this->getRequest(); $form = new Form_Filtro_CallcenterRelatorioEtiquetas(); $fields = array_filter($request->getPost()); $ns = new Zend_Session_Namespace('filtro_callcenter_etiquetas'); if($request->isPost()){ $ns->filtro_callcenter_etiquetas = $request->getPost(); } if( isset($ns->filtro_callcenter_etiquetas) ){ $form->populate($ns->filtro_callcenter_etiquetas); } if( $request->isPost() && $form->isValid($request->getPost()) ){ unset($fields['btn_gerar']); $model = new Model_Campanha(); $clientes = $model->getEtiquetas($fields); if( !$clientes ){ $this->_helper->flashMessenger(array( 'alert' => "Nenhum registro encontrado" )); } else { try { $pdf = new Zend_Pdf(); //LETTER: 612 x 792pt || 215,9 x 279,4mm $page = new Zend_Pdf_Page(Zend_Pdf_Page::SIZE_LETTER); $coluna = $linha = 0; $this->newPage($pdf, $page, $linha, $coluna); $margemLateral = 13.6063; $margemSuperior = 744.86614; $largura = "192"; // 66,7mm $altura = "72"; // 25,4mm foreach ( $clientes as $cliente ) { if( $linha == 0 && $coluna == 3){ $this->newPage($pdf, $page, $linha, $coluna); } $posicaoX = ($coluna * $largura); $posicaoY = $linha * $altura; $x = $margemLateral + $posicaoX + ($coluna * 8.9); $y = $margemSuperior - $posicaoY; $linhas = 0; $filterCep = new Yuppie_Filter_Cep(); $this->drawTextBlock($page, $cliente->nome, $x, $y, $largura, $altura, $linhas); $this->drawTextBlock($page, $cliente->endereco . ($cliente->numero ? ', ' . $cliente->numero : ''), $x, $y, $largura, $altura, $linhas); $this->drawTextBlock($page, "{$cliente->bairro} - {$cliente->cidade}/{$cliente->uf}", $x, $y, $largura, $altura, $linhas); $this->drawTextBlock($page, $filterCep->filter($cliente->cep), $x, $y, $largura, $altura, $linhas); $linha++; if($linha == 10){ $linha = 0; $coluna++; } } // send to browser as download header("Content-Disposition: attachment; filename=etiquetas-clientes.pdf"); header('Content-Type: application/pdf'); echo $pdf->render(); $this->getHelper('Layout')->disableLayout(); $this->getHelper('ViewRenderer')->setNoRender(true); } catch ( Zend_Pdf_Exception $e ) { die('PDF error: ' . $e->getMessage()); } catch ( Exception $e ) { $this->_helper->flashMessenger(array( 'alert' => $e->getMessage() )); $this->_helper->redirector('etiquetas'); } } } $this->view->form = $form; } public function newPage(&$pdf, &$page, &$linha, &$coluna){ $page = new Zend_Pdf_Page(Zend_Pdf_Page::SIZE_LETTER); $font = Zend_Pdf_Font::fontWithName(Zend_Pdf_Font::FONT_COURIER); $cerulean = new Zend_Pdf_Style(); $cerulean->setFont($font, 10); $page->setStyle($cerulean); $pdf->pages[] = $page; $linha = $coluna = 0; } public function drawTextBlock(&$page, $content, $x, $y, $w, $h, &$lines){ $toUpper = new Zend_Filter_StringToUpper(array('encoding' => 'UTF-8')); $letter = 6; //largura do caractere $line = 10; //altura da linha $letterLimit = ($w / $letter); //limite de caracteres $lineLimit = ($h / $line) - 1; //limite de linhas $text = trim($this->view->escape($content)); //se há texto e o limite de linhas não foi excedido if(!empty($text) && $lines < $lineLimit){ while(!empty($text) && $lines < $lineLimit - 1){ $textFit = $toUpper->filter(substr($text, 0, $letterLimit)); $page->drawText($textFit, $x, $y - ($line * $lines) - 5, 'UTF-8'); $lines++; $text = trim(substr($text, $letterLimit)); } } } /** * Relatorio de envio de mensagens */ public function enviosMensagemAnaliticoAction() { $request = $this->getRequest(); $fields = $request->getParams(); $form = new Form_Filtro_RelatorioEnviosAnalitico(); if ($request->isPost()) { $dbTable = new Model_CallcenterMensagem(); $dados = $dbTable->relatorioEnvioAnalitico($fields); $form->populate($fields); $this->view->dados = $dados; } $this->view->form = $form; } }
💾 保存文件
← 返回文件管理器