✏️ 正在编辑: AtendimentoCorretor.php
路径:
/srv/systems_dir/yuppiecred-lidernegocios/application/models/AtendimentoCorretor.php
提示:
您可以编辑任何文件(包括二进制文件),但请注意不当修改可能导致文件损坏。
<?php class Model_AtendimentoCorretor { private $_id; private $_corretorId; private $_usuarioAtendimento; private $_dataLigacao; private $_motivoLigacao; private $_descricao; private $_dataProximoContato; private $_gerenteComercialId; private $_statusResolucaoId; private $_sinalizarSupervisor; private $_horaProximoContato; public function getId() { return $this->_id; } public function getCorretorId() { return $this->_corretorId; } function getHoraProximoContato() { return $this->_horaProximoContato; } function setHoraProximoContato($horaProximoContato) { $this->_horaProximoContato = $horaProximoContato; } public function getUsuarioAtendimento() { return $this->_usuarioAtendimento; } public function getDataLigacao() { return $this->_dataLigacao; } public function getMotivoLigacao() { return $this->_motivoLigacao; } public function getDescricao() { return $this->_descricao; } public function getDataProximoContato() { return $this->_dataProximoContato; } public function getGerenteComercialId() { return $this->_gerenteComercialId; } public function setId($id) { $this->_id = $id; } public function setCorretorId($corretorId) { $this->_corretorId = $corretorId; } public function setUsuarioAtendimento($usuarioAtendimento) { $this->_usuarioAtendimento = $usuarioAtendimento; } public function setDataLigacao($dataLigacao) { if( !empty($dataLigacao) ){ try { $data = new Zend_Date($dataLigacao, Zend_Date::DATES, 'pt'); $dataLigacao = $data->toString('yyyy-MM-dd'); } catch ( Zend_Date_Exception $e ) { echo $e->getMessage(); $dataLigacao = null; } } else { $dataLigacao = null; } $this->_dataLigacao = $dataLigacao; } public function setMotivoLigacao($motivoLigacao) { $this->_motivoLigacao = $motivoLigacao; } public function setDescricao($descricao) { $this->_descricao = $descricao; } public function setDataProximoContato($dataProximoContato) { if( !empty($dataProximoContato) ){ try { $data = new Zend_Date($dataProximoContato, Zend_Date::DATES, 'pt'); $dataProximoContato = $data->toString('yyyy-MM-dd'); } catch ( Zend_Date_Exception $e ) { echo $e->getMessage(); $dataProximoContato = null; } } else { $dataProximoContato = null; } $this->_dataProximoContato = $dataProximoContato; } public function setGerenteComercialId($gerenteComercialId) { $this->_gerenteComercialId = $gerenteComercialId; } public function getStatusResolucaoId() { return $this->_statusResolucaoId; } public function setStatusResolucaoId($statusResolucaoId) { $this->_statusResolucaoId = $statusResolucaoId; } public function getSinalizarSupervisor() { return $this->_sinalizarSupervisor; } public function setSinalizarSupervisor($sinalizarSupervisor) { $this->_sinalizarSupervisor = $sinalizarSupervisor; } 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_AtendimentoCorretor(); $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_AtendimentoCorretor $atendimentoCorretor */ public function salvar(Model_AtendimentoCorretor $atendimentoCorretor) { $dbtable = new Model_DbTable_AtendimentoCorretor(); if( $atendimentoCorretor->getId() > 0 ){ $dbtable->update($atendimentoCorretor->_toArray(), "id = " . $atendimentoCorretor->getId()); return $atendimentoCorretor->getId(); } else { return $dbtable->insert($atendimentoCorretor->_toArray()); } } /** * 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_AtendimentoCorretor(); return $dbtable->delete('id = ' . $id); } } /** * 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['nome']) && !empty($fields['nome']) ){ $params[] = "nome LIKE '%" . $fields['nome'] . "%'"; } if( count($params) > 0 ) $where = implode(' AND ', $params); $dbtable = new Model_DbTable_AtendimentoCorretor(); return $dbtable->fetchAll($where, $order); } /** * 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_AtendimentoCorretor(); return $dbtable->fetchRow('id = ' . $id); } /** * verifica se o corretor está em atendimento. * @param type $corretorId * @return type * @throws Exception */ public function verificarCorretorAtendimento($corretorId) { $dbtable = new Model_DbTable_AtendimentoCorretor(); if( $corretorId > 0 ){ $atendimento = Model_DbTable_Tipos::statusResolucaoPorNome("EM ATENDIMENTO"); $usuarioId = Yuppie_Auth::getIdentity()->id; $dados = $dbtable->fetchRow("corretor_id = $corretorId AND (status_resolucao_id = '$atendimento' OR status_resolucao_id IS NULL)"); if( $dados ){ //ha atendimento agendado para outro dia if( is_null($dados->status_resolucao_id) && $dados->data_proximo_contato > date('Y-m-d') ){ $proxContato = date('d/m/Y', strtotime($dados['data_proximo_contato'])); $usuario = $dados->findParentRow("Model_DbTable_Usuario"); throw new Exception("O atendimento ao corretor foi agendado para $proxContato"); } //dia de agendamento mas agendado para outro usuario if( is_null($dados->status_resolucao_id) && $dados->data_proximo_contato == date('Y-m-d') && $dados->usuario_atendimento != $usuarioId ){ $proxContato = date('d/m/Y', strtotime($dados['data_proximo_contato'])); $usuario = $dados->findParentRow("Model_DbTable_Usuario"); throw new Exception("O atendimento ao corretor foi agendado para outro usuário"); } //atendimento de outro usuario // if( $dados->usuario_atendimento != $usuarioId ){ // // $usuario = $dados->findParentRow("Model_DbTable_Usuario"); // throw new Exception("O corretor já está em atendimento para o usuário \"$usuario->nome\""); // } return $dados->toArray(); } else { $dadosInsert = array( 'usuario_atendimento' => $usuarioId, 'corretor_id' => $corretorId, 'data_ligacao' => Zend_Date::now()->get('yyyy-MM-dd'), 'status_resolucao_id' => $atendimento ); $dadosInsert['id'] = $dbtable->insert($dadosInsert); return $dadosInsert; } } } public function getHistoricoAtendimento($corretorId) { $dbtable = new Model_DbTable_Contrato(); $select = $dbtable->getAdapter()->select()->from(array( 'corretores' => 'tb_corretores' ), array( 'id', 'corretor' => 'corretores.nome' )) ->joinInner(array( "atendimento_corretor" => "tb_atendimento_corretor" ), "corretores.id = atendimento_corretor.corretor_id", array( 'descricao', 'data_ligacao', 'data_proximo_contato' )) ->joinLeft(array( 'status_resolucoes' => 'tb_tipos' ), 'atendimento_corretor.status_resolucao_id = status_resolucoes.id', array( 'status' => 'status_resolucoes.descricao' )) ->joinLeft(array( "motivos" => "tb_tipos" ), "motivos.id = atendimento_corretor.motivo_ligacao", array( 'motivo' => 'motivos.descricao' )) ->joinLeft(array( "usuarios" => "tb_usuarios" ), "usuarios.id = atendimento_corretor.usuario_atendimento", array( 'login' => 'usuarios.nome' )) ->where("corretores.excluido<>1") ->where("corretores.id = {$corretorId}"); return $dbtable->getAdapter()->fetchAll($select); } public function getLigacoesAnalitico(array $fields, $page = null, $limit = null, $order = null, $range = null) { $dbtable = new Model_DbTable_Contrato(); $select = $dbtable->getAdapter()->select()->from(array( 'corretores' => 'tb_corretores' ), array( 'id', 'corretor' => 'corretores.nome' )) ->joinInner(array( "atendimento_corretor" => "tb_atendimento_corretor" ), "corretores.id = atendimento_corretor.corretor_id", array( 'descricao', 'data_ligacao' )) ->joinLeft(array( 'status_resolucoes' => 'tb_tipos' ), 'atendimento_corretor.status_resolucao_id = status_resolucoes.id', array( 'status' => 'status_resolucoes.descricao' )) ->joinLeft(array( "motivos" => "tb_tipos" ), "motivos.id = atendimento_corretor.motivo_ligacao", array( 'motivo' => 'motivos.descricao' )) ->joinLeft(array( "usuarios" => "tb_usuarios" ), "usuarios.id = atendimento_corretor.usuario_atendimento", array( 'login' => 'usuarios.nome' )) ->where("corretores.excluido<>1 AND atendimento_corretor.excluido <> 1") ->group("atendimento_corretor.id") ->order(array( "atendimento_corretor.usuario_atendimento", "atendimento_corretor.id DESC" )); $this->_prepareFilterSelectAtendimento($fields, $select); if( $page ){ $paginator = Zend_Paginator::factory($select); $paginator->setCurrentPageNumber($page); if( $limit && is_numeric($limit) ){ $paginator->setItemCountPerPage($limit); } if( $range && is_numeric($range) ){ $paginator->setPageRange($range); } return $paginator; } return $dbtable->getAdapter()->fetchAll($select, '', Zend_Db::FETCH_OBJ); } public function getLigacoesSintetico(array $fields, $page = null, $limit = null, $order = null, $range = null) { $dbtable = new Model_DbTable_Contrato(); $select = $dbtable->getAdapter()->select()->from(['atendimento_corretor' => 'tb_atendimento_corretor'], ['qtd_atendimentos' => 'COUNT(atendimento_corretor.id)', 'usuario_atendimento']) ->columns(['data' => "DATE_FORMAT(data_ligacao, '%d/%m/%Y')"]) ->joinInner(["usuarios" => "tb_usuarios"], "usuarios.id = atendimento_corretor.usuario_atendimento", ['login' => 'usuarios.nome']) ->joinInner(["corretores" => "tb_corretores"], "atendimento_corretor.corretor_id = corretores.id", []) ->where("atendimento_corretor.excluido <> 1") ->group(["data", "atendimento_corretor.usuario_atendimento"]); $this->_prepareFilterSelectAtendimento($fields, $select); if( $order ){ $select->order($order); } else { $select->order("qtd_atendimentos DESC"); } $result = $dbtable->getAdapter()->fetchAll($select, '', Zend_Db::FETCH_OBJ); $atendimentoCorretor = array(); if( $result ){ foreach ( $result as $values ) { if( !isset($atendimentoCorretor[$values->usuario_atendimento]) ){ $atendimentoCorretor[$values->usuario_atendimento] = array( 'qtd_atendimento' => 0, 'media_diaria' => 0, 'login' => null ); } $dt = new Zend_Date(); $qtdDiasConsulta = $dt->get(Zend_Date::DAY); $ligacaoMediaDiaria = $values->qtd_atendimentos / $qtdDiasConsulta; $atendimentoCorretor[$values->usuario_atendimento]['qtd_atendimento'] += $values->qtd_atendimentos; $atendimentoCorretor[$values->usuario_atendimento]['media_diaria'] += $ligacaoMediaDiaria; $atendimentoCorretor[$values->usuario_atendimento]['login'] = $values->login; } } if( $page ){ $paginator = Zend_Paginator::factory($atendimentoCorretor); $paginator->setCurrentPageNumber($page); if( $limit && is_numeric($limit) ){ $paginator->setItemCountPerPage($limit); } if( $range && is_numeric($range) ){ $paginator->setPageRange($range); } return $paginator; } return $atendimentoCorretor; } protected function _prepareFilterSelectAtendimento(array $fields, Zend_Db_Select &$select) { Core_Filters::_prepareFilterAtendimentoCorretor($fields, $select); //verifica as permissoes if( Yuppie_Auth::getIdentity()->grupo == 'Supervisor' ){ if( !array_key_exists('rotas', $select->getPart(Zend_Db_Select::FROM)) ){ $select->joinLeft(array( 'rotas' => 'tb_rotas' ), 'corretores.rota_id = rotas.id', array()); } $select->where('rotas.gerente_id = ' . Yuppie_Auth::getIdentity()->id); } elseif( Yuppie_Auth::getIdentity()->grupo == 'Gerente Regional' ){ if( !array_key_exists('rotas', $select->getPart(Zend_Db_Select::FROM)) ){ $select->joinLeft(array( 'rotas' => 'tb_rotas' ), 'corretores.rota_id = rotas.id', array()); } if( !array_key_exists('supervisores', $select->getPart(Zend_Db_Select::FROM)) ){ $select->joinLeft(array( 'supervisores' => 'tb_gerente_rota' ), 'supervisores.id = rotas.gerente_id', array()); } $select->where('supervisores.gerente_id = ' . Yuppie_Auth::getIdentity()->id); } elseif( Yuppie_Auth::getIdentity()->grupo == 'Corretor' ){ $select->where('corretores.id = ' . Yuppie_Auth::getIdentity()->id); //caso não tenha a permissao de visualizar-corretores-callcenter exibira os clientes do usuário que tenha corretor no seu cadastro } elseif( Yuppie_Auth::getIdentity()->corretor_id > 0 && !$ns->acl->isAllowed(Yuppie_Auth::getIdentity()->grupo, 'visualizar-corretores-callcenter') ){ $select->where('corretores.id = ' . Yuppie_Auth::getIdentity()->corretor_id); } } public function notificarSupervisor() { if( $this->getSinalizarSupervisor() == 1 ){ $dbtable = new Model_DbTable_Corretor(); $select = $dbtable->getAdapter()->select()->from(array( 'corretores' => 'tb_corretores' ), array( 'corretor' => 'corretores.nome' )) ->joinLeft(array( 'rotas' => 'tb_rotas' ), 'corretores.rota_id = rotas.id', array( '' )) ->joinLeft(array( 'supervisores' => 'tb_gerente_rota' ), 'supervisores.id = rotas.gerente_id', array( 'supervisores.email', 'supervisores.nome' )) ->where('corretores.id = ' . $this->getCorretorId()); return $dbtable->getAdapter()->fetchRow($select, '', Zend_Db::FETCH_OBJ); } return false; } }
💾 保存文件
← 返回文件管理器