✏️ 正在编辑: CallcenterAtendimento.php
路径:
/srv/systems_dir/yuppiecred/application/models/CallcenterAtendimento.php
提示:
您可以编辑任何文件(包括二进制文件),但请注意不当修改可能导致文件损坏。
<?php class Model_CallcenterAtendimento { private $_id; private $_campanhaId; private $_clienteId; private $_dataAtendimento; private $_usuario; private $_statusAtendimento; private $_comentario; private $_ignorar; private $_telefoneChamada; private $_tempoAtendimento; public function getId() { return $this->_id; } public function setId($id) { $this->_id = $id; } public function getCampanhaId() { return $this->_campanhaId; } public function setCampanhaId($campanhaId) { $this->_campanhaId = $campanhaId; } public function getClienteId() { return $this->_clienteId; } public function setClienteId($clienteId) { $this->_clienteId = $clienteId; } public function getDataAtendimento() { return $this->_dataAtendimento; } public function setDataAtendimento($dataAtendimento) { if( !empty($dataAtendimento) ){ try { $data = new Zend_Date($dataAtendimento, Zend_Date::DATES, 'pt'); $dataAtendimento = $data->toString('yyyy-MM-dd'); } catch ( Zend_Date_Exception $e ) { echo $e->getMessage(); $dataAtendimento = null; } } else { $dataAtendimento = Zend_Date::now()->get('yyyy-MM-dd'); } $this->_dataAtendimento = $dataAtendimento; } public function getUsuario() { return $this->_usuario; } public function setUsuario($usuario) { $this->_usuario = $usuario; } public function getStatusAtendimento() { return $this->_statusAtendimento; } public function setStatusAtendimento($statusAtendimento) { $this->_statusAtendimento = $statusAtendimento; } public function getComentario() { return $this->_comentario; } public function setComentario($comentario) { $this->_comentario = $comentario; } public function getIgnorar() { return (int) $this->_ignorar; } public function setIgnorar($bool) { $this->_ignorar = (int) $bool; } public function getTelefoneChamada() { return $this->_telefoneChamada; } public function setTelefoneChamada($telefoneChamada) { $this->_telefoneChamada = $telefoneChamada; } public function getTempoAtendimento() { return $this->_tempoAtendimento; } public function setTempoAtendimento($tempoAtendimento) { $this->_tempoAtendimento = $tempoAtendimento; } public function __construct($options = null) { if( is_array($options) ){ $this->setOptions($options); } } public function setOptions(array $options) { $methods = get_class_methods($this); foreach ( $options as $key => $value ) { $explode = explode("_", $key); $methodName = ''; foreach ( $explode as $v ) { $methodName .= ucfirst($v); } $key = $methodName != '' ? $methodName : $key; $method = 'set' . ucfirst($key); if( in_array($method, $methods) ){ $this->$method($value); } } return $this; } public function _toArray() { $dbtable = new Model_DbTable_CallcenterAtendimento(); $info = $dbtable->info(); $methods = get_class_methods($this); $data = array(); foreach ( $info['cols'] as $key ) { $col = $key; $explode = explode("_", $key); $methodName = ''; foreach ( $explode as $v ) { $methodName .= ucfirst($v); } $key = $methodName != '' ? $methodName : $key; $method = 'get' . ucfirst($key); if( in_array($method, $methods) ){ $data[$col] = $this->$method(); } } return $data; } /** * Insere ou altera o registro passado por parâmetro * @param Model_CallcenterAtendimento $atendimento */ public function salvar(Model_CallcenterAtendimento $atendimento) { $dbtable = new Model_DbTable_CallcenterAtendimento(); if( $atendimento->getId() > 0 ){ $dbtable->update($atendimento->_toArray(), "id = " . $atendimento->getId()); return $atendimento->getId(); } else { return $dbtable->insert($atendimento->_toArray()); } } /** * Retorna uma lista * @param string $where * @param string $order * @param int $count * @param int $offset * @return array */ public function listar($fields = null, $order = null) { $params = array(); $where = null; if( isset($fields['cliente_id']) && !empty($fields['cliente_id']) ){ $params[] = "cliente_id = " . $fields['cliente_id']; } if (!empty($fields['corretor_id'])) { $params[] = "corretor_id = " . $fields['corretor_id']; } if( isset($fields['campanha_id']) && !empty($fields['campanha_id']) ){ $params[] = 'campanha_id = ' . $fields['campanha_id']; } if( isset($fields['usuario']) && !empty($fields['usuario']) ){ $params[] = 'usuario = ' . $fields['usuario']; } if( isset($fields['status_atendimento']) && !empty($fields['status_atendimento']) ){ $params[] = "status_atendimento = '" . $fields['status_atendimento'] . "'"; } if( isset($fields['data_inicial']) && $fields['data_inicial'] ){ $dataInicial = $fields['data_inicial'] . ' ' . (isset($fields['hora_inicial']) && $fields['hora_inicial'] ? $fields['hora_inicial'] : '00:00'); $data = new Zend_Date($dataInicial, 'dd/MM/yyyy HH:mm'); $params[] = "data_atendimento >= '" . $data->get('yyyy-MM-dd HH:mm:ss') . "'"; } else if( isset($fields['hora_inicial']) && $fields['hora_inicial'] ){ $params[] = "TIME(data_atendimento) >= '" . $fields['hora_inicial'] . ":00'"; } if( isset($fields['data_final']) && $fields['data_final'] ){ $dataFinal = $fields['data_final'] . ' ' . (isset($fields['hora_final']) && $fields['hora_final'] ? $fields['hora_final'] : '23:59'); $data = new Zend_Date($dataFinal, 'dd/MM/yyyy HH:mm'); $params[] = "data_atendimento <= '" . $data->get('yyyy-MM-dd HH:mm:ss') . "'"; } else if( isset($fields['hora_final']) && $fields['hora_final'] ){ $params[] = "TIME(data_atendimento) <= '" . $fields['hora_final'] . ":00'"; } if( count($params) > 0 ){ $where = implode(' AND ', $params); } $dbtable = new Model_DbTable_CallcenterAtendimento(); return $dbtable->fetchAll($where, $order); } /** * Exclui o registro passado por parâmetro * @param int $id * @return int The number of rows deleted */ public function excluir($id) { if( $id > 0 ){ $dbtable = new Model_DbTable_CallcenterAtendimento(); return $dbtable->delete("id = " . $id); } return null; } /** * Retorna um fetchRow do item passado por parâmetro * @param int $id * @return Zend_Db_Table_Row_Abstract | null */ public function exibir($id) { $dbtable = new Model_DbTable_CallcenterAtendimento(); return $dbtable->fetchRow("id = " . $id); } public function usuarioPodeAgendar($clienteId, $data, $hora) { $configFile = CLIENT_PATH . '/configs/callcenter.php'; if (file_exists($configFile)) { $cfg = include $configFile; if (!empty($cfg['dias']) && !empty($cfg['retornos'])) { $dataHora = new Zend_Date("$data $hora", 'dd/MM/yyyy HH:mm'); $dataHora = $dataHora->get('yyyy-MM-dd HH:mm:ss'); $dbtable = new Model_DbTable_CallcenterAtendimento(); $where = "cliente_id = {$clienteId} AND " . "usuario = " . Yuppie_Auth::getIdentity()->id . " AND " . "status_atendimento = 'RETORNAR' AND " . "data_atendimento >= SUBDATE('$dataHora',{$cfg['dias']})"; $results = $dbtable->fetchAll($where); if( $results->count() >= $cfg['retornos'] ){ return false; } } } return true; } /** * Indica se o máximo de retornos permitido foi atingido * @param int $usuario * @param string $data * @return boolean */ public function maximoRetornos($usuario, $data) { $configFile = CLIENT_PATH . '/configs/callcenter.php'; if( file_exists($configFile) ){ $cfg = include $configFile; $dbtable = new Model_DbTable_CallcenterBase(); $atendimentos = $dbtable->fetchAll("usuario_ultimo_atendimento = {$usuario} AND status_atendimento = 'RETORNAR'" . " AND agendado_para = '{$data}'"); if( count($atendimentos) >= $cfg['maximo_retornos'] ){ return true; } else { return false; } } } public function getAtendimentosCliente($clienteId) { $ns = new Zend_Session_Namespace(); $dbtable = new Model_DbTable_CallcenterAtendimento(); $select = $dbtable->getAdapter()->select()->from(array( 'ca' => 'tb_callcenter_atendimentos' ), array( 'ca.*' )) ->joinInner(array( 'u' => 'tb_usuarios' ), "ca.usuario = u.id", array( 'login' )) ->joinLeft(array( 'c' => 'tb_callcenter_campanhas' ), "ca.campanha_id = c.id", array( 'campanha' => 'nome' )) ->where("cliente_id = {$clienteId}") ->order("data_atendimento ASC"); if( $ns->acl->isAllowed(Yuppie_Auth::getIdentity()->grupo, 'nao-visualizar-historico-callcenter') ){ $select->joinInner(['b' => 'tb_callcenter_base'], 'b.id = ca.cliente_id', []) ->where("data_atendimento >= b.data_ultimo_reset OR b.data_ultimo_reset IS NULL"); } return $dbtable->getAdapter()->fetchAll($select); } public function getAtendimentos(array $fields, $order = 'data_atendimento ASC') { $dbtable = new Model_DbTable_CallcenterAtendimento(); $select = $dbtable->getAdapter()->select()->from(['ca' => 'tb_callcenter_atendimentos'], [ 'ca.*']) ->joinInner(['campanhas' => 'tb_callcenter_campanhas'], "ca.campanha_id = campanhas.id", [ 'campanha' => 'nome']) ->joinInner(['b' => 'tb_callcenter_base'], "b.id = ca.cliente_id", [ 'cliente' => 'nome', 'status_atendimento_atual' => 'status_atendimento', 'cpf', 'uf' ]) ->joinLeft(['u1' => 'tb_usuarios'], "u1.id = ca.usuario", ['operador_atendimento' => 'login']) ->joinLeft([ 'c' => 'tb_corretores' ], 'u1.corretor_id = c.id', ['corretor' => 'c.nome']) ->joinLeft(['r' => 'tb_rotas' ], 'c.rota_id = r.id', []) ->joinLeft(['u2' => 'tb_usuarios'], "u2.id = b.usuario_ultimo_atendimento", [ 'operador_atual' => 'login']); if (!empty($fields['cpf'])){ $select->where("b.cpf = ?", String_Refatorar::formatarCpf($fields['cpf'])); } if (!empty($fields['cliente_id'])){ $select->where("ca.cliente_id = ?", $fields['cliente_id']); } if (!empty($fields['campanha_id'])){ $select->where("campanhas.id IN (?)", $fields['campanha_id']); } if (!empty($fields['usuario'])){ $select->where('b.usuario_ultimo_atendimento = ?', $fields['usuario']); } if (!empty($fields['status_anterior'])){ $select->where("ca.status_atendimento = ?", $fields['status_anterior']); } if (!empty($fields['status_atual'])){ $select->where("b.status_atendimento = ?", $fields['status_atual']); } if ( !empty($fields['data_inicial']) ){ $dataInicial = new Zend_Date("{$fields['data_inicial']} 00:00:00", 'dd/MM/yyyy HH:mm:ss'); if (!empty($fields['hora_inicial'])){ $dataInicial->setTime($fields['hora_inicial'], 'HH:mm:ss'); } $select->where("ca.data_atendimento >= ?", "{$dataInicial->get('yyyy-MM-dd HH:mm:ss')}"); } if ( !empty($fields['data_final']) ){ $dataFinal = new Zend_Date("{$fields['data_final']} 23:59:59", 'dd/MM/yyyy HH:mm:ss'); if ( !empty($fields['hora_final']) ){ $dataFinal->setTime($fields['hora_final'], 'HH:mm:ss'); } $select->where("ca.data_atendimento <= ?" , "{$dataFinal->get('yyyy-MM-dd HH:mm:ss')}"); } if ( !empty($fields['rota_id']) ){ $select->where("r.id = ?" , $fields['rota_id']); } if (!empty($fields['gerente_id'])){ $select->where("r.gerente_id = ?" , $fields['gerente_id']); } if( $order != null ){ $select->order($order); } return $dbtable->getAdapter()->fetchAll($select); } public static function pausarRamalDiscadorPreditivo() { self::acoesRamalDiscadorPreditivo('pausar'); } public static function removerPausaRamalDiscadorPreditivo() { $usuario = (new Model_DbTable_Usuario)->fetchRow(['id = ?' => Yuppie_Auth::getIdentity()->id]); Model_CallcenterPausaOperador::realizarPausa($usuario->ramal_status); } public static function acoesRamalDiscadorPreditivo($acao) { $discadorId = (int) Yuppie_Auth::getIdentity()->discador_id; $class = Core_Discador_Factory::load(); if ( !empty($discadorId) && $class ) { $class->atendentePausaOuRetorno($acao, $discadorId); } } public function getAtendimentosTelefones(array $fields) { $dbtable = new Model_DbTable_CallcenterAtendimento(); $select = $dbtable->getAdapter()->select()->from(array( 'atendimentos' => 'tb_callcenter_atendimentos' ), ['status_atendimento', 'data_atendimento']) ->joinInner(['clientes' => 'tb_callcenter_base'],'clientes.id = atendimentos.cliente_id',['cliente' => 'nome', 'cpf']) ->joinInner(['campanhas' => 'tb_callcenter_campanhas'],'campanhas.id = atendimentos.campanha_id',['campanha' => 'nome']) ->joinInner(['telefones' => 'tb_callcenter_telefones'], 'telefones.cliente_id = atendimentos.cliente_id',['fone','discador_status']) ->where('telefones.excluido<>1 AND atendimentos.excluido<>1'); if (!empty($fields['campanha_id'])){ $campanhas = is_array($fields['campanha_id']) ? implode(",", $fields['campanha_id']) : $fields['campanha_id']; $select->where("campanhas.id IN ({$campanhas})"); } if (!empty($fields['status_cliente'])){ $select->where("clientes.status_atendimento = '" . $fields['status_cliente'] . "'"); } if (!empty($fields['discador_status'])){ $select->where("discador_status = '" . $fields['discador_status'] . "'"); } if ( !empty($fields['data_atendimento_de']) ){ $dataInicial = new Zend_Date("{$fields['data_atendimento_de']} 00:00:00", 'dd/MM/yyyy HH:mm:ss'); $select->where("data_atendimento >= ?", "{$dataInicial->get('yyyy-MM-dd HH:mm:ss')}"); } if ( !empty($fields['data_atendimento_a']) ){ $dataFinal = new Zend_Date("{$fields['data_atendimento_a']} 23:59:59", 'dd/MM/yyyy HH:mm:ss'); $select->where("data_atendimento <= ?" , "{$dataFinal->get('yyyy-MM-dd HH:mm:ss')}"); } return $dbtable->getAdapter()->fetchAll($select); } public static function baixarGravacaoDiscadorPreditivo($chamadaId) { $class = Core_Discador_Factory::load(); return $class->getGravacao($chamadaId); } public static function calcularTempoDeAtendimento($clienteId) { $cliente = (new Model_DbTable_CallcenterBase())->fetchRow(['id = ?' => $clienteId]); $dataHoraChamada = strtotime($cliente['data_ultimo_atendimento']); $dataHoraAtual = strtotime(Zend_Date::now()->get('yyyy-MM-dd HH:mm:ss')); $diferenca = ($dataHoraAtual-$dataHoraChamada); return $diferenca; } public function enviarOportunidade($parametros) { $modelFatores = new Model_TabelaFator(); $fator = $modelFatores->exibir($parametros['fator']); $nomeBanco = (new Model_Banco())->exibir($fator->banco_id)->nome; $result = false; $formatacao = [ 'negrito' => [ 'email' => [ 'abre' => '<strong>', 'fecha' => '</strong>', ], 'whatsapp' => [ 'abre' => '*', 'fecha' => '*', ] ] ]; $tipoEnvio = $parametros['tipo_envio']; $mensagem = "Olá {$parametros['nome']}, segue proposta conforme conversado por telefone: \n\n " . "{$formatacao['negrito'][$tipoEnvio]['abre']}Valor do empréstimo:{$formatacao['negrito'][$tipoEnvio]['fecha']} R$ {$parametros['valor_solicitado']} \n " . "{$formatacao['negrito'][$tipoEnvio]['abre']}Valor da parcela:{$formatacao['negrito'][$tipoEnvio]['fecha']} R$ {$parametros['valor_parcela']} \n " . "{$formatacao['negrito'][$tipoEnvio]['abre']}Qtd. Parcelas:{$formatacao['negrito'][$tipoEnvio]['fecha']} {$fator->prazo} \n " . "{$formatacao['negrito'][$tipoEnvio]['abre']}Banco:{$formatacao['negrito'][$tipoEnvio]['fecha']} {$nomeBanco} \n " . "{$formatacao['negrito'][$tipoEnvio]['abre']}Tipo de Operação:{$formatacao['negrito'][$tipoEnvio]['fecha']} {$fator['tipo']} \n "; if ($tipoEnvio == 'email') { try { $email = new Core_Mail(); $result = $email->enviarMensagemHtml( $parametros['nome'], $parametros['enviar_para'], "Proposta Banco {$nomeBanco}", nl2br($mensagem) ); return $result['msg']; } catch ( Exception $e ) { return $result; } } if ($tipoEnvio == 'whatsapp') { try { if ($whatsapp = Core_Whatsapp_Factory::load()) $result = $whatsapp->sendMessage(String_Refatorar::formatarTelefone($parametros['enviar_para']), $mensagem); if ($result) { return 'Mensagem enviada com sucesso.'; } } catch (Exception $e) { return $result; } } return $result; } }
💾 保存文件
← 返回文件管理器