✏️ 正在编辑: ChamadoController.php
路径:
/srv/systems_dir/yuppiecred-bkp/application/controllers/ChamadoController.php
提示:
您可以编辑任何文件(包括二进制文件),但请注意不当修改可能导致文件损坏。
<?php class ChamadoController extends Zend_Controller_Action { protected $_bucketFolder = 'chamados'; public function indexAction() { if( Yuppie_Auth::getIdentity()->grupo == 'Corretor' ){ $this->_helper->layout->setLayout('layout_corretor'); } $request = $this->getRequest(); $form = new Form_Filtro_Chamado(); $result = array(); if( $request->isPost() && $form->isValid($request->getPost()) ){ $fields = array_filter($request->getPost()); unset($fields['btn_filtrar']); $chamado = new Model_Chamado(); $result = $chamado->listar($fields); } else { $form->getElement('situacao')->setValue(1); //Andamento } $this->view->paginator = $result; $this->view->form = $form; } public function saveAction() { $usuario = Yuppie_Auth::getIdentity(); $request = $this->getRequest(); $form = new Form_Chamado(); if ($usuario->grupo == 'Corretor'){ $this->_helper->layout->setLayout('layout_corretor'); } if ($request->isPost() && $form->isValid($request->getPost())){ $fields = array_filter($request->getPost()); // Se for solicitação PAC ou de materiais if ($fields['assunto'] == 6 || $fields['assunto'] == 1) { $solicitacaoPac = new Model_SolicitacaoPac($fields); $solicitacaoPacId = $solicitacaoPac->salvar($solicitacaoPac); $fields['solicitacao_pac_id'] = $solicitacaoPacId; } try { Upload::save((new Zend_File_Transfer_Adapter_Http()), $fields, $this->_bucketFolder); $chamado = new Model_Chamado($fields); $ns = new Zend_Session_Namespace('chamado_id'); $chamado->setId($ns->chamado_id); $id = $chamado->salvar($chamado); $request->setParam('chamado_id', $id); $modelCorretor = new Model_Corretor(); $dadosCorretor = $modelCorretor->exibir($chamado->getCorretorId()); if ($id > 0){ $ns->chamado_id = $id; $dbtable = new Model_DbTable_ChamadoSolicitacao(); $dbtable->insertSolicitacoes($fields, $id, $dadosCorretor); $form->init(); $ns->unsetAll(); $this->_helper->flashMessenger([ 'success' => 'Chamado salvo com sucesso.' ]); } else { $this->_helper->flashMessenger([ 'alert' => 'Nenhum registro foi salvo.' ]); } } catch ( Exception $e ) { (new Model_DbTable_Chamado())->closeConnection(); $form->init(); $this->_helper->flashMessenger(['error' => $e->getMessage()]); } } $this->view->form = $form; } public function detalharChamadoAction() { $this->_helper->layout->setLayout('layout_popup'); $request = $this->getRequest(); $form = new Form_ChamadoInteracao(); $id = (int) $request->getParam('id'); $chamado = new Model_Chamado(); $usuario = Yuppie_Auth::getIdentity(); $model = null; if ($id > 0){ $model = $chamado->exibir($id); if (!$model){ $this->_helper->flashMessenger(['alert' => 'Id inválido']); } $this->view->detalhe = $chamado->getDetalhamento($id); $this->view->model = $model; } if ($usuario->grupo == 'Corretor'){ if( $model->validar_anexo == 2 ){ $this->_helper->flashMessenger([ 'alert' => 'Atenção! Seu anexo foi negado, favor anexar um novo documento na interação deste chamado.' ]); } } if ($request->isPost() && $form->isValid($request->getPost())){ $usuarioId = $usuario->grupo != 'Corretor' ? $usuario->id : null; try { $fields = array_filter($request->getPost()); $fields['usuario_id'] = $usuarioId; $fields['chamado_id'] = $id; Upload::save((new Zend_File_Transfer_Adapter_Http()), $fields, $this->_bucketFolder); $modelInteracao = new Model_ChamadoInteracao($fields); $idInteracao = $modelInteracao->salvar($modelInteracao); if ($idInteracao) { $request->setParam('chamado_id', $id); $request->setParam('tipo_notificacao', 1); if ($form->getValue('enviar_notificacao')){ $this->notificacao(); } $this->_helper->flashMessenger([ 'success' => 'Comentário adicionado com sucesso.' ]); } else { $this->_helper->flashMessenger([ 'alert' => 'Nenhum comentário foi adicionado.' ]); } } catch ( Exception $e ) { $this->_helper->flashMessenger(['danger' => $e->getMessage()]); } } $this->view->form = $form; } public function finalizarChamadoAction() { $this->_helper->viewRenderer->setNoRender(); $this->_helper->getHelper('layout')->disableLayout(); $request = $this->getRequest(); $chamadoId = (int)$request->getParam('chamado_id'); if( $chamadoId > 0 ){ $chamado = new Model_Chamado(); $result = $chamado->finalizarChamado($chamadoId); if( $result != null ){ $this->_helper->json([ 'result' => $result, 'alert' => 'Chamado finalizado com sucesso!', 'chamado_id' => $chamadoId, 'tipo_notificacao' => 2 ]); } $this->_helper->json([ 'result' => $result, 'alert' => 'Atenção! O chamado não foi finalizado.' ]); } $this->_helper->json(['alert' => 'Atenção! O chamado não localizado.']); } public function deleteAction() { $request = $this->getRequest(); $id = (int)$request->getParam('id'); if ($id > 0) { $chamado = new Model_Chamado(); try { $chamado->excluir($id); $this->_helper->flashMessenger(['success' => 'Registro excluído com sucesso.']); } catch ( Exception $e ) { $this->_helper->flashMessenger(['error' => $e->getMessage()]); } } $this->_redirect('/chamado'); } public function validarItemChamadoAction() { $this->_helper->viewRenderer->setNoRender(); $this->_helper->getHelper('layout')->disableLayout(); $request = $this->getRequest(); $id = (int) $request->getParam('chamado_solicitacao_id'); if( !$id ){ $this->_helper->json("Id não identificado"); } $chamadoSolicitacao = new Model_DbTable_ChamadoSolicitacao(); $result = $chamadoSolicitacao->update(array( 'validado' => 1 ), 'id = ' . $id); if( $result ){ $this->_helper->json(array( 'success' => 'Validado com sucesso.' )); } else { $this->_helper->json(array( 'alert' => 'Nenhum registro foi validado.' )); } } public function downloadAnexoAction() { $this->_helper->layout->disableLayout(); $request = $this->getRequest(); $id = (int) $request->getParam('id'); if( $id ){ $chamado = new Model_Chamado(); $model = $chamado->exibir($id); $urlAnexo = parse_url($model->anexo, PHP_URL_PATH); try{ Upload::downloadFromUrl($urlAnexo); } catch (Exception $ex) { $this->_helper->flashMessenger(['error' => $ex->getMessage()]); } } else { $this->_helper->flashMessenger(['error' => "Chamado não identificado."]); $this->_redirect("/chamado"); } $this->_redirect("/chamado/detalhar-chamado/id/{$id}"); } public function downloadAnexoInteracaoAction() { $this->_helper->layout->disableLayout(); $request = $this->getRequest(); $id = (int)$request->getParam('id'); if ($id) { $chamado = new Model_ChamadoInteracao(); $model = $chamado->exibir($id); try{ Upload::download($model->anexo, $this->_bucketFolder); } catch (Exception $ex) { $this->_helper->flashMessenger(['error' => $ex->getMessage()]); } $this->_redirect("/chamado/detalhar-chamado/id/{$model->chamado_id}"); } else { $this->_helper->flashMessenger(['alert' => "Chamado não identificado."]); } $this->_redirect("/chamado"); } public function notificacao() { $chamadoId = (int) $this->getRequest()->getParam('chamado_id'); $tipoNotificacao = (int) $this->getRequest()->getParam('tipo_notificacao'); $chamado = new Model_Chamado(); $dadosEnvio = $chamado->notificar($chamadoId, $tipoNotificacao); $this->view->dados_envio = $dadosEnvio; $dadosChamado = $dadosEnvio['dados_chamado']; $modelEmail = new Model_CorretorEmail(); $dadosEmailAdicional = $modelEmail->listar(['corretor_id' => $dadosChamado->corretor_id]); $modelUsuario = new Model_Usuario(); $notificarUsuarios = $modelUsuario->listar(array( 'assuntos_chamado' => $dadosChamado['assunto'] )) ; $emailsAdicionais = array(); foreach ( $dadosEmailAdicional as $adicional ) { if ($adicional->chamado == 1) { $emailsAdicionais[] = array( 'email' => $adicional->email_adicional, 'nome' => $adicional->descricao, 'receber_email' => $adicional->receber_email); } } foreach ( $notificarUsuarios as $usuario ) { $emailsAdicionais[] = array( 'email' => $usuario->email, 'nome' => $usuario->nome, 'receber_email' => 1 ); } //verifica o assunto para notificar o supervisor if( in_array($dadosChamado['assunto'], [2, 3]) ){ $corretor = new Model_Corretor(); $corretor->setId($dadosChamado->corretor_id); $supervisor = $corretor->getSupervisor(); if( !empty($supervisor->email) ){ $emailsAdicionais[] = ['email' => $supervisor->email, 'nome' => $supervisor->nome, 'receber_email' => 1]; } } //faz o envio da mensagem try { $email = new Core_Mail(); $email->enviarMensagemHtml($dadosEnvio['mail_from'][1],$dadosEnvio['mail_from'][0], $dadosEnvio['subject'], $this->view->render('chamado/mensagem-notificacao.phtml'), $emailsAdicionais, $dadosEnvio['email_adicional']); } catch ( Zend_Mail_Exception $e ) { $this->_helper->flashMessenger(array( 'alert' => 'Uma falha pode ter ocorrido. ' . 'Sua mensagem não foi enviada. ' . 'Por favor, tente novamente! <br/>' . $e->getMessage() )); } //faz o envio para o whatsapp do parceiro if ($whatsapp = Core_Whatsapp_Factory::load()){ $textoMensagem = "*{$dadosEnvio['subject']}*\n\n" . "Prezado(a) parceiro(a),\n" . "a resposta abaixo foi enviada sobre o seu chamado {$dadosChamado['id']}.\n\n" . "*Interação:*\n" . date('d/m/Y H:i', strtotime($dadosEnvio['ultima_interacao']['data_cadastro'])) . " - " . $dadosEnvio['ultima_interacao']['comentario'] . "\n\nPara maiores informações, acesse o nosso sistema em " . $this->view->serverUrl() . $this->view->baseUrl() . "\n\n\n _Esta é uma mensagem enviada, automaticamente, pelo Sistema Yuppie_"; $whatsapp->sendMessage(String_Refatorar::formatarTelefone($dadosEnvio['dados_corretor']['celular']), $textoMensagem); } } public function validarAnexoAction() { $request = $this->getRequest(); $id = $request->getParam('id'); $validarAnexo = $request->getParam('campo'); $result = null; $anexoInteracao = $request->getParam('anexo_interacao'); if( $anexoInteracao ){ $dbtable = new Model_DbTable_ChamadoInteracao(); $campo = $request->getParam('validar_anexo'); $result = $dbtable->copyAnexoToCorretor($id, $request->getParam('corretor_id'), $campo); $chamadoId = $request->getParam('chamado_id'); if( $result > 0 ){ $this->_helper->flashMessenger(array( 'success' => "Registro salvo com sucesso." )); } $this->_redirect("/chamado/detalhar-chamado/id/{$chamadoId}"); } if( $id && $validarAnexo ){ $dbtable = new Model_DbTable_Chamado(); try { $result = $dbtable->copyAnexoToCorretor($id, $validarAnexo); } catch ( Exception $ex ) { $this->_helper->json(array( 'alert' => $ex->getMessage() )); } $this->_helper->json(array( 'result' => ($result != null ? 1 : 0) )); } } public function emailConfiguracaoAction() { $request = $this->getRequest(); $form = new Form_EmailConfiguracao(); $dbtable = new Model_DbTable_EmailConfiguracao(); $delete = $request->getParam('delete'); $id = (int) $request->getParam('id'); if( $delete ){ $dbtable->delete("id = {$id}"); $this->_helper->flashMessenger(array( 'success' => 'Registro excluído com sucesso.' )); $this->_helper->redirector("email-configuracao"); } if( $request->isPost() ){ if( $form->isValid($request->getPost()) ){ try { $dbtable->insert($form->getValues()); $this->_helper->flashMessenger(array( 'success' => 'Configurações salvas com sucesso.' )); } catch ( Exception $e ) { $this->_helper->flashMessenger(array( 'alert' => $e->getMessage() )); } } } $this->view->emails = $dbtable->fetchAll(); $this->view->form = $form; } /** * Impressão de Solicitação de Pac */ public function imprimirSolicitacaoPacAction() { $this->_helper->layout->setLayout('layout_impressao'); $id = $this->_getParam('id'); $mPac = new Model_SolicitacaoPac(); $pacObj = $mPac->getChamadoBySolicitacao($id); $this->view->pac = $pacObj; } /** * Atualizar Solicitação de Pac */ public function atualizarSolicitacaoPacAction() { $request = $this->getRequest(); $id = (int) $request->getParam('id'); $campo = $request->getParam('campo'); $valor = $request->getParam('valor'); $result = 0; if( $id ){ $dbtable = new Model_DbTable_SolicitacaoPac(); $result = $dbtable->update(array( $campo => $valor ), "id = {$id}"); } $this->_helper->json(array( 'result' => $result )); } /** * Atualização de Código de Rastreamento */ public function atualizarCodRastreamentoAction() { $request = $this->getRequest(); $id = (int) $request->getParam('id'); $campo = $request->getParam('campo'); $valor = $request->getParam('valor'); $result = 0; if( $id ){ $dbtable = new Model_DbTable_Chamado(); $result = $dbtable->update(array( $campo => $valor ), "id = {$id}"); } $this->_helper->json(array( 'result' => $result )); } public function excluirInteracoesAction() { $idInteracao = new Model_DbTable_ChamadoInteracao(); $deleted = $idInteracao->update([ 'excluido' => 1 ], [ 'id = ?' => $this->getRequest()->getParam('id') ]); return $this->_helper->json($deleted); } }
💾 保存文件
← 返回文件管理器