✏️ 正在编辑: ServiceController.php
路径:
/srv/systems_dir/yuppiecred-lidernegocios/application/controllers/ServiceController.php
提示:
您可以编辑任何文件(包括二进制文件),但请注意不当修改可能导致文件损坏。
<?php class ServiceController extends Zend_Controller_Action { private $_log = null; public function init() { /* Apenas para LOG */ $urlSistema = Yuppie_Auth::getSiteKey(); $writer = new Zend_Log_Writer_Stream("/var/log/sistemayuppie/zf_log_{$urlSistema}_mobile_" . Zend_Date::now()->get("ddMMyyyy") . ".txt"); $this->_log = new Zend_Log($writer); $this->_log->log('#######################', Zend_Log::INFO); if( $this->getRequest()->getActionName() == "sinc-yuppies" ){ $this->_log->log('WEBSERVICE SINCRONIZACAO YUPPIES', Zend_Log::INFO); } else { $this->_log->log('WEBSERVICE APLICATIVO', Zend_Log::INFO); } $this->_log->log('$_SERVER', Zend_Log::INFO); $this->_log->log(print_r($_SERVER, true), Zend_Log::INFO); $this->_log->log('Action:' . $this->getRequest()->getActionName(), Zend_Log::INFO); $url = "http://" . $_SERVER['SERVER_NAME'] . $this->getRequest()->getBaseUrl(); $this->_helper->layout->setLayout('layout_basico'); $this->_helper->viewRenderer->setNoRender(); $this->_helper->getHelper('layout')->disableLayout(); $this->_wsdl = $url . "/service/wsdl?wsdl"; if( isset($_SERVER['HTTP_ORIGIN']) ){ header("Access-Control-Allow-Origin: {$_SERVER['HTTP_ORIGIN']}"); header('Access-Control-Allow-Credentials: true'); header('Access-Control-Max-Age: 86400'); // cache for 1 day } // Access-Control headers are received during OPTIONS requests if( $_SERVER['REQUEST_METHOD'] == 'OPTIONS' ){ if( isset($_SERVER['HTTP_ACCESS_CONTROL_REQUEST_METHOD']) ) header("Access-Control-Allow-Methods: GET, POST, OPTIONS"); if( isset($_SERVER['HTTP_ACCESS_CONTROL_REQUEST_HEADERS']) ) header("Access-Control-Allow-Headers: {$_SERVER['HTTP_ACCESS_CONTROL_REQUEST_HEADERS']}"); exit(0); } //actions liberadas $actions = ['proposta', 'combos', 'sinc-yuppies', 'sinc-yuppies-comissionamento', 'webhook-higienizacao-cpf']; if( !in_array($this->getRequest()->getActionName(), $actions) ){ $config = new Zend_Config_Ini(CLIENT_PATH . '/configs/application.ini', APPLICATION_ENV); $dados = $config->yuppie; if( $dados ){ $permissionAPP = $dados->toArray(); if( $permissionAPP['webservice'] == false ){ $this->_helper->json(array( 'status' => 'fail', 'result' => 'Aplicativo não liberado.' )); } } } } public function indexAction() { if( isset($_GET['wsdl']) ){ //return the WSDL $this->hadleWSDL(); } else { //handle SOAP request $this->handleSOAP(); } } /** * Esse método deve existir pois nos testes com o C# ele sempre aponta para o endereco /index/wsdl o que * causa um erro. Mesmo sendo informado no visual studio a referencia para /index?wsdl * */ public function wsdlAction() { if( isset($_GET['wsdl']) ){ //return the WSDL $this->hadleWSDL(); } else { //handle SOAP request $this->handleSOAP(); } } private function hadleWSDL() { $autodiscover = new Zend_Soap_AutoDiscover(); $autodiscover->setClass('Service_ServerSoap'); $autodiscover->handle(); } private function handleSOAP() { $soap = new Zend_Soap_Server($this->_wsdl); $soap->setClass('Service_ServerSoap'); $soap->handle(); } public function propostaAction() { if( $this->_request->isPost() ){ $dados = $this->_request->getPost(); $url = $this->_request->getPost('retorno'); if( !$url ){ die(utf8_decode('ERRO! Url de retorno não definida!')); } try { if( $_FILES['file_cpf']['name'] == '' && $_FILES['file_rg']['name'] == '' && $_FILES['file_contra_cheque']['name'] == '' && $_FILES['file_ficha_cadastral']['name'] == '' && $_FILES['file_beneficio']['name'] == '' ){ $url .= '?erro=4'; // Nenhum anexo foi enviado $this->getHelper('Redirector')->gotoUrlAndExit($url); } if( !$dados['login'] || !$dados['senha'] ){ $url .= '?erro=1'; // Login e senha obrigatórios $this->getHelper('Redirector')->gotoUrlAndExit($url); } $modelCorretor = new Model_Corretor(); if( !$modelCorretor->autenticar($dados['login'], $dados['senha']) ){ $url .= '?erro=2'; // Login ou senha incorretos $this->getHelper('Redirector')->gotoUrlAndExit($url); } /* TO DO * tratar consulta para evitar SQL Injections */ $tbCorretor = new Model_DbTable_Corretor(); $corretor = $tbCorretor->fetchRow( "login = '{$dados['login']}' " . "AND senha = '" . md5($dados['senha']) . "' " . "AND excluido = 0" ); $upload = new Zend_File_Transfer_Adapter_Http(); $upload->setDestination(UPLOAD_PATH); $files = array(); foreach ( $upload->getFileInfo() as $file => $info ) { $fname = substr(md5(microtime()), 1, 4) . $info['name']; $upload->addFilter(new Zend_Filter_File_Rename(array( 'target' => UPLOAD_PATH . '/' . $fname, 'overwrite' => false ))); if( $upload->receive($file) ){ $files[$file] = $fname; } } $dados['corretor_id'] = $corretor->id; $dados['empresa_id'] = $corretor->empresa_id; // Banco $modelBanco = new Model_Banco(); $dados['banco_id'] = $modelBanco->bancoPorNome($dados['banco']); unset($dados['banco']); if( !$dados['banco_id'] ){ $url .= '?erro=5'; // Banco para liberação inválido $this->getHelper('Redirector')->gotoUrlAndExit($url); } // Convênio $tbConvenio = new Model_DbTable_Convenio(); /* TO DO * tratar consulta para evitar SQL Injections */ $convenio = $tbConvenio->fetchRow( "nome = '{$dados['convenio']}'"); $dados['convenio_id'] = $convenio->id; unset($dados['convenio']); if( !$dados['convenio_id'] ){ $url .= '?erro=6'; // Convênio inválido $this->getHelper('Redirector')->gotoUrlAndExit($url); } // Banco Beneficiado $tbBancoFebraban = new Model_DbTable_BancoFebraban(); $bancoBeneficiado = $tbBancoFebraban->findByCodigo($dados['banco_beneficiado']); $dados['banco_beneficiado'] = $bancoBeneficiado->codigo; if( !$dados['banco_beneficiado'] ){ $url .= '?erro=7'; // Banco do beneficiado inválido $this->getHelper('Redirector')->gotoUrlAndExit($url); } $proposta = new Model_Proposta($dados); if( count($files) > 0 ){ if( isset($files['file_cpf']) ){ $proposta->setAnexoCpf($files['file_cpf']); } if( isset($files['file_rg']) ){ $proposta->setAnexoRg($files['file_rg']); } if( isset($files['file_contra_cheque']) ){ $proposta->setAnexoContraCheque($files['file_contra_cheque']); } if( isset($files['file_ficha_cadastral']) ){ $proposta->setAnexoFichaCadastral($files['file_ficha_cadastral']); } if( isset($files['file_beneficio']) ){ $proposta->setAnexoBeneficio($files['file_beneficio']); } } $cliente = new Model_Cliente($dados); $result = $proposta->salvar($proposta, $cliente); if( !$result ){ $url .= '?erro=3'; // Erro ao tentar salvar proposta } else { $url .= '?success=1'; // Proposta cadastrada com sucesso } } catch ( Zend_Exception $e ) { $url .= '?erro=8'; // Erro desconhecido echo $e->getMessage(); die($e->getTraceAsString()); } $this->getHelper('Redirector')->gotoUrlAndExit($url); } } public function combosAction() { $request = $this->getRequest(); $corretorId = (int) $request->getParam('corretor_id'); $grupo = (int) $request->getParam('grupo_id'); $combos = array( 'bancos' => array_filter(Core_Combos::getBancosOptions()), 'convenios' => Core_Combos::getConveniosOptions(), 'formas_liberacao' => Core_Combos::getFormasLiberacaoOptions(), 'bancos_beneficiados' => Core_Combos::getBancosFebrabanOptions(), 'codigos_usuarios' => Core_Combos::getCodigoUsuarioCorretorOptions($corretorId), 'ufs' => Core_Combos::getUfOptions(), 'usuarios' => Core_Combos::getUsuariosByGrupoOptions($grupo) ); $this->_helper->json($combos); } public function fisicosPendentesAction() { $request = $this->getRequest(); $login = $request->getParam('l'); $senha = $request->getParam('p'); $service = new Service_ServerSoap(); return $service->getFisicosPendentes($login, $senha); } public function echoWsdlAction() { die($this->_wsdl); } public function loginCorretorAction() { $request = $this->getRequest(); $this->_log->log('Params:', Zend_Log::INFO); $this->_log->log(print_r($request->isGet(), true), Zend_Log::INFO); $this->_log->log(print_r($request->isPost(), true), Zend_Log::INFO); $this->_log->log(print_r($request->getParams(), true), Zend_Log::INFO); if( $request->isGet() ){ $params = $request->getParams(); } else { $input = file_get_contents("php://input"); $postdata = json_decode($input); $this->_log->log("POSTDATA: " . print_r($postdata, true), Zend_Log::INFO); $params = (array) $postdata->params; } if( isset($params) ){ $token = null; $existToken = null; $login = $params['username']; $senha = $params['password']; $this->_log->log("Login/senha: ", Zend_Log::INFO); $this->_log->log(print_r(array( $login, $senha ), true), Zend_Log::INFO); if( !$login || !$senha ){ $this->_helper->json(array( 'error' => 'Login e senha obrigatórios.' )); } $modelCorretor = new Model_Corretor(); if( !$modelCorretor->autenticar($login, $senha, 'tb_corretores', 'Corretor') ){ $this->_helper->json(array( 'status' => 'fail' )); } /* TO DO * tratar consulta para evitar SQL Injections */ $tbCorretor = new Model_DbTable_Corretor(); $corretor = $tbCorretor->fetchRow( "login = '{$login}' " . "AND senha = '" . md5($senha) . "' " . "AND excluido = 0 AND acesso_aplicativo = 1" ); if( $corretor != "" ){ $token = Yuppie_Auth::getIdentity()->token; $service = new Service_ServerSoap(); $acessoTemporario = $service->acessoTemporarioCorretor($corretor->acesso_temporario, $corretor->data_temporario_app); if( !$acessoTemporario ){ $this->_helper->json(array( 'status' => 'fail', 'permission' => 'false' )); } $existToken = $tbCorretor->findExistToken($corretor->id); if( !$existToken ){ $tbCorretor->update(array( 'token_aplicativo' => $token ), "id = " . $corretor->id); } $this->_helper->json(array( 'status' => 'ok', 'token' => $existToken ? $existToken : $token, 'corr' => $corretor->id, 'email' => $corretor->email, 'username' => $corretor->login )); } else { $this->_helper->json(array( 'status' => 'fail', 'permission' => 'false' )); } } else { $this->_helper->json("Não foi possível se autenticar."); } } //consulta a situaçao de contratos public function consultarContratosAction() { $request = $this->getRequest(); if( $request->isGet() ){ $params = $request->getParams(); } else { $input = file_get_contents("php://input"); $postdata = json_decode($input); $this->_log->log("POSTDATA: " . print_r($postdata, true), Zend_Log::INFO); $params = (array) $postdata; } $this->_log->log('Params:', Zend_Log::INFO); $this->_log->log(print_r($params, true), Zend_Log::INFO); if( isset($params) ){ $token = $params['token']; if (empty($token)) { $this->_helper->json(['Token não identificado.']); } $service = new Service_ServerSoap(); $response = $service->getSituacaoContrato($token, $params); if( $response ){ $this->_helper->json(array( $response )); } else { $this->_helper->json(""); } } else { $this->_helper->json("Não foi possível consultar, por favor tente novamente."); } } public function meusProtocolosAction() { $request = $this->getRequest(); if( $request->isGet() ){ $params = $request->getParams(); } else { $input = file_get_contents("php://input"); $postdata = json_decode($input); $this->_log->log("POSTDATA: " . print_r($postdata, true), Zend_Log::INFO); $params = (array) $postdata; $this->_log->log("PARAMS: " . print_r($params, true), Zend_Log::INFO); } if( isset($params) ){ $token = $params['token']; if (empty($token)) { $this->_helper->json(['Token não identificado.']); } $service = new Service_ServerSoap(); $response = $service->getProtocolosCorretor($token); if( $response ){ $this->_helper->json(array( $response )); } else { $this->_helper->json(array( "Nenhum protocolo encontrado." )); } } else { $this->_helper->json("Não foi possível consultar, por favor tente novamente."); } } public function minhasPendenciasCorretorAction() { $request = $this->getRequest(); if( $request->isGet() ){ $params = $request->getParams(); } else { $input = file_get_contents("php://input"); $postdata = json_decode($input); $this->_log->log("POSTDATA: " . print_r($postdata, true), Zend_Log::INFO); $params = (array) $postdata; } if( isset($params) ){ $token = $params['token']; $pendencias = $params['pendencia_fisicos']; $service = new Service_ServerSoap(); $response = $service->getFisicosPendentesCorretor($token, $pendencias, $params); if( $response ){ $this->_helper->json(array( $response )); } else { $this->_helper->json(array( "not_found" => "Nenhuma pendência encontrada." )); } } else { $this->_helper->json("Não foi possível consultar, por favor tente novamente."); } } public function preCadastroPropostaAction() { $request = $this->getRequest(); if( $request->isGet() ){ $params = $request->getParams(); } else { $input = file_get_contents("php://input"); $postdata = json_decode($input); $this->_log->log("POSTDATA: " . print_r($postdata, true), Zend_Log::INFO); $params = (array) $postdata; $this->_log->log("PARAMS: " . print_r($params, true), Zend_Log::INFO); } if( isset($params) ){ $token = $params['token']; $service = new Service_ServerSoap(); $response = $service->preCadastroProposta($token, $params, $this->_log); if( $response ){ $this->_helper->json($response); } else { $this->_helper->json(array( "Nenhuma proposta foi salva." )); } } } public function regularizarPendenciaAction() { $request = $this->getRequest(); $upload = new Zend_File_Transfer_Adapter_Http(); $upload->setDestination(UPLOAD_PATH); try { $anexo = null; if( $upload->receive() ){ $anexo = $upload->getFileName(null, false); } } catch ( Zend_File_Transfer_Exception $e ) { $this->_helper->json(array( 'error' => $e->getMessage() )); } if( $request->isGet() ){ $params = $request->getParams(); } else { $params = (array) $request->getParams(); $this->_log->log("PARAMS: " . print_r($params, true), Zend_Log::INFO); } if( isset($params) && !empty($params) ){ $token = $params['token']; $service = new Service_ServerSoap(); try { $result = $service->regularizarPendencia($token, $params['id'], $params['file'], $params['tipo_documento'], $this->_log); if( $result ){ $this->_helper->json(array( 'success' => "Documento enviado com sucesso. Aguarde nosso setor de formalização identificar." )); } else { $this->_helper->json(array( 'alert' => "Nenhuma informação foi adicionada." )); } } catch ( Exception $e ) { $this->_helper->json(array( 'alert' => $e->getMessage() )); } } } public function saveMobileTokenAction() { $request = $this->getRequest(); if ($request->isGet()) { $params = $request->getParams(); } else { $input = file_get_contents("php://input"); $postdata = json_decode($input); $this->_log->log("POSTDATA: " . print_r($postdata, true), Zend_Log::INFO); $params = (array) $postdata; $this->_log->log("PARAMS: " . print_r($params, true), Zend_Log::INFO); } if (isset($params)) { $token = $params['token']; if (empty($token)) { $this->_helper->json(['Token não identificado.']); } $service = new Service_ServerSoap(); $response = $service->saveMobileToken($token, $params, $this->_log); if ($response) { $this->_helper->json($response); } else { $this->_helper->json(array( "Nenhum registro foi salvo." )); } } } public function sincYuppiesAction() { if ($this->_request->isPost()) { $dados = $this->_request->getPost(); try { if (empty($dados['token'])) { $this->_helper->json('Token obrigatório.'); } $sistema = Yuppie_Auth::getSiteKey(); $modelCorretor = new Model_Corretor(); if (!$corretor = $modelCorretor->autenticarSinc($dados['token'])) { $this->_helper->json(["error" => "Token incorreto."]); } $dbtContrato = new Model_DbTable_Contrato(); $contratos = $dbtContrato->fetchSincronizacaoYuppies($corretor->id, $dados['offset'], $dados['ultimaSinc']); $comissoes = (new Model_DbTable_ProtocoloContrato())->getProtocolosPagos($corretor->id, $dados['offset'], $dados['ultimaSinc']); $this->_helper->json([ "token" => $dados['token'], "contratos" => $contratos, 'comissoes' => $comissoes, "sistema" => $sistema ]); } catch ( Core_Exception $e ) { $this->_helper->json($e->getMessage()); } catch ( Exception $e ) { Yuppie_Log::write($e->getMessage(), $this); $this->_helper->json("Falha de comunicação com o sistema origem"); } } } public function sincYuppiesComissionamentoAction() { if ($this->_request->isPost()) { $dados = $this->_request->getPost(); try { if (empty($dados['token'])) { $this->_helper->json('Token obrigatório.'); } $sistema = Yuppie_Auth::getSiteKey(); $modelCorretor = new Model_Corretor(); if (!$corretor = $modelCorretor->autenticarSinc($dados['token'])) { $this->_helper->json(["error" => "Token incorreto."]); } $dbtComissionamentoIndividual = new Model_ComissionamentoCorretorPercentual(); $comissionamentoIndividual = $dbtComissionamentoIndividual->listar(['corretor_id' => $corretor->id, 'page' => $dados['offset']], $dados['offset'], 100); $individual = (array) $comissionamentoIndividual; $dbtComissionamentoGrupo = new Model_ComissionamentoGrupoPercentual(); $comissionamentoGrupo = $dbtComissionamentoGrupo->listar(['corretor_id' => $corretor->id, 'page' => $dados['offset']], $dados['offset'], 100); $grupo = (array) $comissionamentoGrupo; $this->_helper->json(["token" => $dados['token'], "individual" => $individual, 'grupo' => $grupo, "sistema" => $sistema ]); } catch ( Core_Exception $e ) { $this->_helper->json($e->getMessage()); } catch ( Exception $e ) { Yuppie_Log::write($e->getMessage(), $this); $this->_helper->json("Falha de comunicação com o sistema origem"); } } } public function exibirNotificacaoAction() { if( Yuppie_Auth::hasIdentity() ){ $request = $this->getRequest(); $permissao = $request->getParam('permissao'); if( $permissao ){ $ns = new Zend_Session_Namespace(); if( !$ns->acl->isAllowed(Yuppie_Auth::getIdentity()->grupo, $permissao) ){ $this->_helper->json(array( 'success' => true )); } } } $this->_helper->json(array( 'error' => false )); } public function webhookHigienizacaoCpfAction() { $params = json_decode($this->getRequest()->getRawBody()); if (empty($params->listaMargemConsignacao)) { $this->_helper->json(['alert' => 'Nenhuma informação a ser lida.']); } foreach ($params->listaMargemConsignacao as $margem) { try { $callcenterBase = new Model_CallcenterBase(); $callcenterBase->gravarConsultaOmega($margem); } catch (Core_Exception $e) { continue; } catch (Zend_Db_Exception $e) { $this->_helper->json(['error' => 'Erro ao salvar dados no banco de dados.']); } } $this->_helper->json(['success' => 'Processo concluído com sucesso.']); } }
💾 保存文件
← 返回文件管理器