✏️ 正在编辑: AutomacoesController.php
路径:
/srv/systems_dir/yuppiecred/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(); } private function _logarWebService() { $usuario = new stdClass(); $usuario->{'id'} = 9999; $usuario->{'grupo_id'} = 1; $usuario->{'empresa_id'} = 1; $usuario->{'nome'} = "Web Service"; $usuario->{'login'} = "Web Service"; $usuario->{'grupo'} = "Administradores"; $usuario->{'dias'} = "0,1,2,3,4,5,6"; $usuario->{'hora_inicio'} = "08:00"; $usuario->{'hora_fim'} = "23:59"; Yuppie_Auth::writeStorage($usuario); $acl = new Core_LibraryAcl($usuario->grupo); $ns = new Zend_Session_Namespace(); $ns->acl = $acl; } 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 importacaoDiretaCredleveAction() { try { AutomacoesService::importacaoDiretaApi('CREDLEVE'); } catch (Throwable $throwable) { Yuppie_Log::write('Falha na importação direta CREDLEVE. ' . $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 importacaoDiretaDaycovalAction() { try { AutomacoesService::importacaoDiretaApi('DAYCOVAL'); } catch (Throwable $throwable) { Yuppie_Log::write('Falha na importação direta DAYCOVAL. ' . $throwable->getMessage()); } } public function importacaoDiretaWorkbankAction() { try { AutomacoesService::importacaoDiretaApi('WORKBANK'); } catch (Throwable $throwable) { Yuppie_Log::write('Falha na importação direta WORKBANK. ' . $throwable->getMessage()); } } public function atualizarContratosV8Action() { try { AutomacoesService::importacaoDiretaApi('V8'); } catch (Throwable $throwable) { Yuppie_Log::write('Falha na atualização dos contratos V8 . ' . $throwable->getMessage()); } } public function importacaoDiretaLotusAction() { try { AutomacoesService::importacaoDiretaApi('LOTUS'); } catch (Throwable $throwable) { Yuppie_Log::write('Falha na importação direta LOTUS. ' . $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 importacaoDiretaFuturoPrevidenciaAction() { try { AutomacoesService::importacaoDiretaApi('FUTURO PREVIDENCIA'); } catch (Throwable $throwable) { Yuppie_Log::write('Falha na importação direta FUTURO PREVIDENCIA. ' . $throwable->getMessage()); } } public function importacaoDiretaVctexAction() { try { AutomacoesService::importacaoDiretaApi('VCTEX'); } catch (Throwable $throwable) { Yuppie_Log::write('Falha na importação direta VCTEX. ' . $throwable->getMessage()); } } public function sincronizarYuppiesAction() { set_time_limit(0); try { $this->_logarWebService(); AutomacoesService::sincronizarYuppies(); } catch (\Throwable $th) { Yuppie_Log::write('Falha na sincronização entre yuppies. ' . $th->getMessage()); } } public function sincronizarYuppiesComissionamentoAction() { set_time_limit(0); try { $this->_logarWebService(); AutomacoesService::sincronizarYuppiesComissionamento(date('Y-m-d')); } catch (\Throwable $th) { Yuppie_Log::write('Falha na sincronização de comissionamento entre yuppies. ' . $th->getMessage() . " - " . $th->getTraceAsString()); } } 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(); $digitadosPorCorretor = []; 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']); } elseif ($proposta['tipo_operacao'] == 'REFINANCIAMENTO') { (new Model_DigitacaoAutomatica())->digitarRefins($proposta, $service, $digitados, $digitadosPorCorretor, $idEsteira); continue; } 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((array)$condicoesCredito, true), $this); $retornoInclusao = $api->$metodoInclusao($proposta, (array)$condicoesCredito, $propostaId); $efetivado = (new Model_Proposta())->efetivarPropostaInclusao($propostaId, current($retornoInclusao)); $linkformalizacao = $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 digitação ao efetivar a proposta"); continue; } $table->update(["status_digitacao" => 'DIGITADO'], "id = " . $idEsteira); $digitadosPorCorretor[$proposta['corretor_id']][] = [ 'cliente' => $proposta['nome'], 'cpf' => $proposta['cpf'], 'numero_contrato' => current($retornoInclusao)->numero_proposta, 'banco_id' => $bancoId, 'banco' => $proposta['banco'], 'link_formalizacao' => $linkformalizacao ]; $digitados++; } catch (Core_Exception $erro) { (new Model_DbTable_DigitacaoAutomatica())->update([ "status_digitacao" => 'ERRO', "descricao_andamento" => $erro->getMessage() ], "id = " . $idEsteira); Yuppie_Log::write("Proposta não inserida! " . $erro->getMessage() . "\n" . $erro->getTraceAsString(), $this); } catch (Throwable $erro) { (new Model_DbTable_DigitacaoAutomatica())->update([ "status_digitacao" => 'ERRO', "descricao_andamento" => "Erro interno" ], "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); (new Model_DigitacaoAutomatica())->notificarCorretorDigitacoes($digitadosPorCorretor); } public function enviarNotificacaoAlteracaoComissaoAction() { $fields['data_cadastro'] = date('Y-m-d'); $gruposNotificacoes = (new Model_NotificacaoComissionamento())->getGruposNotificaoes($fields); //Grupo foreach ($gruposNotificacoes as $grupo) { $fields['grupo_id'] = $grupo['grupo_id']; $notificacoesGrupo = AutomacoesService::enviarNotificacaoAlteracaoComissao($fields); if (empty($notificacoesGrupo)) { continue; } array_map(function($notificacao) { (new Model_NotificacaoComissionamento())->setNotificacaoEnviada($notificacao['id']); }, $notificacoesGrupo); $corretores = (new Model_Corretor())->getCorretoresByGrupoComissao($fields['grupo_id']); if (empty($corretores)) { continue; } foreach ($corretores as $corretor) { $this->view->alteracoes = $notificacoesGrupo; Model_NotificacaoComissionamento::enviarEmail($corretor['nome'], $corretor['email'], $this->view->render('automatizacao/alteracao-comissao.phtml')); // Model_NotificacaoComissionamento::enviarWhats($notificacao, $corretor['celular'], $url); sleep(1); } } //Corretor unset($fields['grupo_id']); $corretoresNotificacoes = (new Model_NotificacaoComissionamento())->getCorretoresNotificaoes($fields); foreach ($corretoresNotificacoes as $corretor) { $fields['corretor_id'] = $corretor['corretor_id']; $notificacoesCorretor = AutomacoesService::enviarNotificacaoAlteracaoComissao($fields); if (empty($notificacoesCorretor)) { continue; } array_map(function($notificacao) { (new Model_NotificacaoComissionamento())->setNotificacaoEnviada($notificacao['id']); }, $notificacoesCorretor); $dadosCorretor = (new Model_Corretor())->exibir($fields['corretor_id']); $this->view->alteracoes = $notificacoesCorretor; Model_NotificacaoComissionamento::enviarEmail($dadosCorretor->nome, $dadosCorretor->email, $this->view->render('automatizacao/alteracao-comissao.phtml')); // Model_NotificacaoComissionamento::enviarWhats($notificacao, $corretor->celular, $url); sleep(1); } } }
💾 保存文件
← 返回文件管理器