✏️ 正在编辑: ConsultaConsignado.php
路径:
/srv/systems_dir/yuppiecred-lidernegocios/library/Core/Service/ConsultaConsignado.php
提示:
您可以编辑任何文件(包括二进制文件),但请注意不当修改可能导致文件损坏。
<?php /** * Description of ConsultaConsignado * * @author yuppie */ abstract class Core_Service_ConsultaConsignado { protected $_tipoConsulta = null; //A= Avulso; M= Mensal; E= Empresa private $_cpf = null; private $_url = null; protected function getUrl() { return $this->_url; } function __construct(array $options = null) { if( !$this->_verificaPermissoes() ){ $msgErro = 'Você não possui créditos para realizar consultas.'; throw new Core_Exception($msgErro); } if( !$options ){ $options = $this->getConfigData(); } $this->setOptions($options); } public function getTipoConsulta() { return $this->_tipoConsulta; } public function setTipoConsulta($tipoConsulta) { $this->_tipoConsulta = $tipoConsulta; } public function getCpf() { return $this->_cpf; } public function setCpf($cpf) { $this->_cpf = $cpf; } protected function _verificaPermissoes() { $permitido = true; $consulta = new Model_DbTable_ConsultaHiscon(); $identity = Yuppie_Auth::getIdentity(); if( isset($identity->corretor_id) && $identity->corretor_id > 0 ){ $tipo = $consulta->corretorTemCreditos($identity->corretor_id); if( !$tipo ){ $permitido = false; } } elseif( !empty($identity->grupo) && $identity->grupo == 'Corretor' ){ $tipo = $consulta->corretorTemCreditos(); if( !$tipo ){ $permitido = false; } } else { $tipo = 'E'; } $this->setTipoConsulta($tipo); return $permitido; } protected function _isValidXml($xml) { $doc = @simplexml_load_string($xml); if( $doc ){ return $doc; //this is valid } elseif( empty($doc) ){ throw new Core_Exception('Nenhum registro encontrado!'); } else { throw new Core_Exception('Acesso inválido!'); } } protected function formatarCpf($value) { $filter = new Zend_Filter_Digits(); $onlyDigits = $filter->filter($value); $value = trim($onlyDigits); while ( strlen($value) < 11 ) { $value = '0' . $value; } return $value; } protected function _inicializaDados(&$dados) { $dados['situacao'] = null; // $dados['cpf'] = !isset($dados['cpf']) ? null : $dados['cpf']; $dados['matricula'] = null; $dados['beneficio'] = null; $dados['nome'] = "Sem retorno das informações online."; $dados['mae'] = null; $dados['sexo'] = null; $dados['nascto'] = null; $dados['banco_pagto'] = null; $dados['agencia_pagto'] = null; $dados['conta_pagto'] = null; $dados['orgao_pagador'] = null; $dados['tipo_pagto'] = null; $dados['mr'] = 0.00; $dados['especie'] = null; $dados['especie_descricao'] = null; $dados['tipo'] = null; $dados['competencia'] = null; $dados['dib'] = null; $dados['rg'] = null; $dados['nit'] = null; $dados['emails'] = array(); $dados['cessado'] = null; $dados['obito'] = null; $dados['rep_legal'] = null; $dados['itens']['emprestimos'] = array(); $dados['itens']['emails'] = array(); $dados['itens']['enderecos'][] = array( 'logradouro' => null, 'numero' => null, 'complemento' => null, 'bairro' => null, 'cep' => null, 'cidade' => null, 'uf' => null ); } public function callCurlMethod($url) { $curl_handle=curl_init(); curl_setopt($curl_handle, CURLOPT_URL, $url); curl_setopt($curl_handle, CURLOPT_RETURNTRANSFER, 1); curl_setopt($curl_handle, CURLOPT_USERAGENT, Zend_Http_UserAgent::DEFAULT_HTTP_USER_AGENT); curl_setopt($curl_handle, CURLOPT_FOLLOWLOCATION, 1); $result = curl_exec($curl_handle); curl_close($curl_handle); return $result; } public function setFloat($value) { $value = str_replace("R$ ", "", $value); if( $value != '' ){ $locale = new Zend_Locale('en'); if (!Zend_Locale_Format::isFloat($value, array('precision' => 2, 'locale' => $locale))) { //seta o locale para pt_BR para converter para o padrão brasileiro $locale = new Zend_Locale('pt_BR'); $value = Zend_Locale_Format::getNumber($value, array( 'locale' => $locale, 'precision' => 2 )); }else{ $value = Zend_Locale_Format::getNumber($value, array( 'locale' => $locale, 'precision' => 2 )); } } return $value; } public function getMargemCPFWhatsapp($cpf, $log = null) { try { $beneficios = $this->getConsignadoPorCpf($cpf); }catch( Exception $e ){ $log->log('Exception consulta beneficios => ' . $e->getMessage(), Zend_Log::INFO); return $e->getMessage(); } $arrayBeneficios = []; if (empty($beneficios)) { return 'Benefícios não localizados'; } $exceptionMessage = ""; foreach ($beneficios as $beneficio) { try { $arrayBeneficios[] = array_merge($this->getConsignadoPorBeneficio($beneficio['beneficio']), ['detalhamento' => $this->getDetalhamento($beneficio['beneficio'])]); }catch(Exception $e){ $log->log('Exception consulta detalhamento => ' . $e->getMessage(), Zend_Log::INFO); $exceptionMessage .= $e->getMessage() . "\n"; } } if( !empty($exceptionMessage) ){ return "*Exception:* " . $exceptionMessage; } return $this->makeMessageWhatsapp($arrayBeneficios, $log); } public function makeMessageWhatsapp($beneficiosAgrupados, $log) { if(empty($beneficiosAgrupados)){ return 'Benefícios não localizados'; } $result = [ 'mensagem' => '', 'detalhamento' => null ]; foreach ($beneficiosAgrupados as $beneficio) { $margemConsignado = number_format($beneficio['margem'], 2, ',', '.'); $margemCartao = number_format($beneficio['margem_cartao'], 2, ',', '.'); $result['mensagem'] .= "*Nº Benefício:* {$beneficio['beneficio']}\n" . "*Margem Consignado:* {$margemConsignado}\n" . "*Margem Cartão:* {$margemCartao}\n\n"; if( !empty($beneficio['detalhamento']) ){ $result['detalhamento'] = $beneficio['detalhamento']; } $resultLog = $result; unset($resultLog['detalhamento']); $log->log("Result benefícios: " . print_r($resultLog, 1), Zend_Log::INFO); } return $result; } public function calcularTaxaJuros($valorFinanciando, $valorParcela, $numeroParcelas) { if (empty($valorFinanciando) || empty($valorParcela) || empty($numeroParcelas) || ($valorParcela > $valorFinanciando)) { return 0; } $vFin = intval($valorFinanciando); $vParc = $valorParcela; $nParc = $numeroParcelas * (-1); $taxaJuros = 0.5; $subtraendo = 0; $vjur1 = 1; $vjur2 = 0; while (abs($vFin - $subtraendo) > 0.00001) { $subtraendo = $vParc * (( 1 - ( pow(( 1 + $taxaJuros ), $nParc))) / $taxaJuros); if ($subtraendo < $vFin) { $vjur1 = $taxaJuros; } else { $vjur2 = $taxaJuros; } $taxaJuros = ($vjur1 + $vjur2) / 2; } return round(($taxaJuros * 100), 3); } public function getDadosParaProposta($cpf) { if (empty($cpf)) { return; } $retorno = [ 'cpf' => $cpf, 'numero_beneficio' => '', 'data_nascimento' => '', 'especie' => '', 'nome_mae' => '', 'endereco' => '', 'complemento' => '', 'bairro' => '', 'cidade' => '', 'uf' => '', 'cep' => '', 'celular' => '', 'fax' => '', 'fone' => '', 'telefone_comercial' => '', 'banco_beneficiado' => '', 'agencia_beneficiado' => '', 'conta_beneficiado' => '', 'valor_beneficio' => 0, 'beneficio' => '', 'valor_prestacao' => '', ]; try { $beneficios = $this->getConsignadoPorCpf($cpf); } catch (Exception $e) { return ['error' => $e->getMessage()]; } if (count($beneficios) <= 0) { return; } foreach ($beneficios as $beneficio) { try { $dados = $this->getConsignadoPorBeneficio($beneficio['beneficio']); if (empty($dados)) { continue; } //tenta cadastrar o cliente no callcenter (new Model_CallcenterBase())->gravarClienteConsulta($dados); (new Model_DbTable_ConsultaHiscon())->insert([ 'cpf' => $dados['cpf'], 'margem' => $dados['margem'], 'margem_cartao' => $dados['margem_cartao'], 'margem_cartao_rmc' => $dados['margem_cartao_rmc'], 'margem_rcc' => $dados['margem_rcc'], 'beneficio' => $beneficio['beneficio'], 'tipo' => $this->getTipoConsulta(), ]); if ($dados['margem'] > $retorno['margem']) { $retorno = $dados; } } catch (Exception $e) { continue; } } $endereco = current($retorno['itens']['enderecos']); return [ 'cpf' => $cpf, 'nome' => $retorno['nome'], 'rg' => $retorno['rg'], 'numero_beneficio' => $retorno['beneficio'], 'data_nascimento' => $retorno['nascto'], 'especie' => $retorno['especie'], 'nome_mae' => $retorno['mae'], 'endereco' => $endereco['logradouro'], 'complemento' => $endereco['complemento'], 'bairro' => $endereco['bairro'], 'cidade' => $endereco['cidade'], 'uf' => $endereco['uf'], 'cep' => $endereco['cep'], 'celular' => '', 'fax' => '', 'fone' => '', 'telefone_comercial' => '', 'banco_beneficiado' => $retorno['banco_pagto'], 'agencia_beneficiado' => $retorno['agencia_pagto'], 'conta_beneficiado' => $retorno['conta_pagto'], 'valor_beneficio' => number_format($retorno['mr'], 2, ',', '.'), 'beneficio' => $retorno['beneficio'], 'valor_prestacao' => number_format($retorno['margem'], 2, ',', '.') ]; } public function getMaiorMargem($cpf) { $beneficios = $this->getConsignadoPorCpf($cpf); $consultas = null; $margem = 0; foreach ( $beneficios as $registro ) { $beneficio = $registro['beneficio']; $this->setCpf($cpf); try { $consultas[$beneficio] = $this->getConsignadoPorBeneficio(trim($beneficio)); } catch (Exception $e) { continue; } } $retorno = current($consultas); foreach ($consultas as $consulta) { if ($consulta['margem'] > $margem) { $margem = $consulta['margem']; $retorno = $consulta; } } $endereco = current($retorno['itens']['enderecos']); $telefone = current($retorno['itens']['telefones']); $retorno = array_merge($retorno, $endereco, ['celular' => $telefone]); unset($retorno['itens']); return $retorno; } }
💾 保存文件
← 返回文件管理器