✏️ 正在编辑: AutomacoesController.php
路径:
/srv/systems_dir/yuppiecred-lidernegocios/application/controllers/AutomacoesController.php
提示:
您可以编辑任何文件(包括二进制文件),但请注意不当修改可能导致文件损坏。
<?php use Yuppie_Core_Secret as Secret; use Zend_Controller_Action as ZendController; use Modules\Automatizacao\Service\AutomacoesService; use Modules\Relatorio\Service\RelatorioSemanalService; use Modules\Automatizacao\Model\DbTable\AutomatizacaoTable; use Modules\SimulacaoAberta\Service\SimulacaoAbertaService; /** * @sem_permissao */ class AutomacoesController extends ZendController { /** @var string */ public const ERRO = 'Ocorreu um erro durante a solicitação.'; public function init() { try { Secret::valid($this->getRequest(), 'yuppiecred'); } catch (Throwable $throwable) { echo $throwable->getMessage(); die(); } $this->_helper->viewRenderer->setNoRender(); $this->_helper->layout->disableLayout(); parent::init(); } public function oportunidadesNegociosAction() { try { $this->_helper->json(['success' => AutomacoesService::oportunidadesNegocio()]); } catch (Throwable $throwable) { $this->_helper->json(['erro' => $throwable->getTraceAsString()]); } } public function desempenhoGerenteSemanalAction() { try { if ((new AutomatizacaoTable())->first()->isProdutividadeSupervisores()) { (new RelatorioSemanalService())->sendProdutividadeSupervisor(); } } catch (Throwable $throwable) { echo $throwable->getMessage(); die(); } } public function importacaoDiretaFactaAction() { try { AutomacoesService::importacaoDiretaApi('FACTA'); } catch (Throwable $throwable) { Yuppie_Log::write('Falha na importação direta FACTA. ' . $throwable->getMessage()); } } public function atualizacaoStatusPanAction() { try { AutomacoesService::importacaoDiretaApi('PAN'); } catch (Throwable $throwable) { Yuppie_Log::write('Falha na atualização do status PAN . ' . $throwable->getMessage()); } } public function enviarNotificacoesAction() { try { AutomacoesService::enviarNotificacoes(); } catch (Throwable $throwable) { Yuppie_Log::write('Falha no envio das notificações . ' . $throwable->getMessage()); } } public function atualizarContratosMercantilAction() { try { AutomacoesService::importacaoDiretaApi('MERCANTIL'); } catch (Throwable $throwable) { Yuppie_Log::write('Falha na atualização dos contratos Mercantil . ' . $throwable->getMessage()); } } public function atualizarContratosC6bankAction() { try { AutomacoesService::importacaoDiretaApi('C6 BANK'); } catch (Throwable $throwable) { Yuppie_Log::write('Falha na atualização dos contratos C6 BANK . ' . $throwable->getMessage()); } } public function importacaoDiretaBevicredAction() { try { AutomacoesService::importacaoDiretaApi('BEVICRED'); } catch (Throwable $throwable) { Yuppie_Log::write('Falha na importação direta BEVICRED. ' . $throwable->getMessage()); } } public function importacaoDiretaCredfrancoAction() { try { AutomacoesService::importacaoDiretaApi('CREDFRANCO'); } catch (Throwable $throwable) { Yuppie_Log::write('Falha na importação direta CREDFRANCO. ' . $throwable->getMessage()); } } public function importacaoDiretaIcredAction() { try { AutomacoesService::importacaoDiretaApi('ICRED'); } catch (Throwable $throwable) { Yuppie_Log::write('Falha na importação direta ICRED. ' . $throwable->getMessage()); } } public function importarConveniosOrgaosLogosCredcestaAction() { try { AutomacoesService::importarConveniosOrgaosLogosCredcesta(); } catch (\Throwable $th) { Yuppie_Log::write('Falha na importação dos convênios CREDCESTA. ' . $th->getMessage()); } } public function sincronizarYuppiesAction() { set_time_limit(0); try { AutomacoesService::sincronizarYuppies(); } catch (\Throwable $th) { Yuppie_Log::write('Falha na sincronização entre yuppies. ' . $th->getMessage()); } } public function sincronizarYuppiesComissionamentoAction() { set_time_limit(0); try { AutomacoesService::sincronizarYuppiesComissionamento(); } catch (\Throwable $th) { Yuppie_Log::write('Falha na sincronização de comissionamento entre yuppies. ' . $th->getMessage()); } } public function higienizarFgtsAction() { set_time_limit(0); $campanhas = (new Model_CallcenterCampanha())->getCampanhasHigienizacaoAutomatica(); $horaInicial = (new Zend_Date())->now()->setHour(20)->setMinute(0)->setSecond(0); $horaFinal = (new Zend_Date())->now()->addDay(1)->setHour(5)->setMinute(0)->setSecond(0); if (empty($campanhas)) { $this->_helper->json(['alert' => 'Nenhuma campanha habilitada para higienização.']); } try { $service = new \Core_Banco_Service_Autocontratacao_Fgts(); $bancosHabilitados = $service->getBancosHabilitados('auto-higienizacao'); } catch (Exception $e) { $this->_helper->json([ 'error' => $e->getMessage() ]); return; } foreach ($campanhas as $campanha) { if (!(Zend_Date::now()->getTimestamp() > $horaInicial->getTimestamp() && Zend_Date::now()->getTimestamp() < $horaFinal->getTimestamp())) { Yuppie_Log::write("Higienização FGTS encerrada às " . Zend_Date::now()->get('HH:mm') ." por ultrapassar o horário"); $campanha->ultima_higienizacao = date('Y-m-d'); $campanha->save(); break; } $modelCampanha = new Model_CallcenterCampanha(); $modelCampanha->setId($campanha->id); $clientes = $modelCampanha->getBase(); if (!$clientes) { $this->_helper->json([ 'error' => "Campanha não retornou clientes para a consulta." ]); continue; } foreach ($bancosHabilitados as $banco) { $resultadoHigienizacao = $modelCampanha->higienizarFgts($clientes, $banco['metodo']); } $campanha->ultima_higienizacao = date('Y-m-d'); $campanha->save(); } $this->_helper->json($resultadoHigienizacao); } public function digitacaoEmLoteAction() { set_time_limit(0); $service = new SimulacaoAbertaService(); $table = new Model_DbTable_DigitacaoAutomatica(); $propostas = $table->fetchAll("status_digitacao = 'A DIGITAR'"); $digitados = 0; if (empty($propostas)) { return; } $propostas = $propostas->toArray(); array_map(function($proposta){ (new Model_DbTable_DigitacaoAutomatica())->update(["status_digitacao" => "PROCESSANDO"], "id = " . $proposta['id']); }, $propostas); foreach ($propostas as $proposta) { $serviceDigitacao = stristr($proposta['convenio'], 'FGTS') ? new Core_Banco_Service_Autocontratacao_Fgts() : new Core_Banco_Service_Autocontratacao_Inss(); $idEsteira = $proposta['id']; try { $service->salvarCliente($proposta); $baseId = $service->getDados()['cliente_id']; Model_DbTable_DigitacaoAutomatica::complementarDados($proposta); if (stristr($proposta['convenio'], 'FGTS')) { $metodoInclusao = 'inclusaoFgts'; $retorno = $serviceDigitacao->consultar($proposta['cpf'], $baseId, $proposta['consulta_banco']); } else { $metodoInclusao = 'inclusaoConsignado'; $retorno = $serviceDigitacao->consultar($proposta, $baseId); } $condicoesCredito = current($retorno->condicoes_credito); $bancoId = Model_Banco::bancoPorNome($proposta['banco']); $api = $serviceDigitacao->getBancoFromClass($proposta['banco']); $propostaModel = new Model_Proposta(['banco_id' => $bancoId]); $propostaId = $propostaModel->saveByInclusaoAutocontratacao($proposta, $condicoesCredito, $proposta['convenio'], $proposta['tipo_operacao']); Yuppie_Log::write("Dados enviados para inclusao: " . print_r($proposta, true) . "\n" . 'Condicoes de credito: ' . print_r($condicoesCredito, true), $this); $retornoInclusao = $api->$metodoInclusao($proposta, (array)$condicoesCredito, $propostaId); $efetivado = (new Model_Proposta())->efetivarPropostaInclusao($propostaId, current($retornoInclusao)); $api->enviarLinkFormalizacao(current($retornoInclusao)->numero_proposta ?? null, $proposta['cpf'], $proposta['fone']); $api->tratarMensagemErro($baseId, $retornoInclusao); Yuppie_Log::write(print_r($retornoInclusao, true), $this); if (empty($efetivado)) { Yuppie_Log::write("Houve um erro ao efetivar a proposta. " . print_r(['post' => $proposta, 'retorno' => $retornoInclusao, 'condicoes_credito' => $condicoesCredito], true), $this); $service->adicionarPendencia($propostaId, "Erro na autocontratação ao efetivar a proposta"); continue; } $table->update(["status_digitacao" => 'DIGITADO'], "id = " . $idEsteira); $digitados++; } catch (Throwable $erro) { $table->update([ "status_digitacao" => 'ERRO', "descricao_andamento" => $erro->getMessage() ], "id = " . $idEsteira); Yuppie_Log::write("Proposta não inserida! " . $erro->getMessage() . "\n" . $erro->getTraceAsString(), $this); } } Yuppie_Log::write("Foram digitados " . $digitados . " de um total de " . count($propostas) . '.', $this); } }
💾 保存文件
← 返回文件管理器