✏️ 正在编辑: Corretor.php
路径:
/srv/systems_dir/yuppiecred-lidernegocios/application/models/DbTable/Corretor.php
提示:
您可以编辑任何文件(包括二进制文件),但请注意不当修改可能导致文件损坏。
<?php use Modules\Core\Exception\CPFJaCadastradoException; class Model_DbTable_Corretor extends Zend_Db_Table_Abstract { protected $_primary = 'id'; protected $_name = 'tb_corretores'; protected static $_viewName = 'vw_corretores'; protected $_dependentTables = array( 'Model_DbTable_Contrato' ); protected $_referenceMap = array( 'Empresa' => array( 'columns' => array( 'empresa_id' ), 'refTableClass' => 'Model_DbTable_Empresa', 'refColumns' => array( 'id' ) ), 'Rota' => array( 'columns' => array( 'rota_id' ), 'refTableClass' => 'Model_DbTable_Rota', 'refColumns' => array( 'id' ) ), 'BancoFebraban' => array( 'columns' => array( 'banco' ), 'refTableClass' => 'Model_DbTable_BancoFebraban', 'refColumns' => array( 'codigo' ) ), 'GrupoComissao' => array( 'columns' => array( 'grupo_comissao' ), 'refTableClass' => 'Model_DbTable_Tipos', 'refColumns' => array( 'id' ) ) ); public function getPrimaryKey() { return $this->_primary; } public static function getViewName() { return self::$_viewName; } /** * Verifica se o cpf já está cadastrado * @param string $cpf * @return boolean */ public function existeCpf($cpf): bool { if ($this->fetchRow("cpf = '" . String_Refatorar::formatarCpf($cpf) . "'") != null) { return true; } return false; } public function insert(array $data) { //verifica se o cpf está sendo passado if( isset($data['cpf']) && !empty($data['cpf']) ){ //verifica se o cpf já está cadastrado if( $this->existeCpf($data['cpf']) ) throw new CPFJaCadastradoException(); } if( isset($data['senha']) ){ if( (empty($data['senha']) || $data['senha'] == null ) ){ unset($data['senha']); } else { $data['senha'] = md5($data['senha']); } } //verifica se está liberando o acesso ao app if( isset($data['acesso_aplicativo']) && $data['acesso_aplicativo'] == 1 && $data['acesso_temporario'] != 1 ){ if( $this->getLimitApp() <= 0 ){ throw new Core_Exception('Você já atingiu o seu limite de acesso ' . 'ao aplicativo. Entre em contato com a Yuppie.'); } } if (!empty($data['email'])) { Model_Corretor::validarEmail($data['email']); } $id = parent::insert($data); //grava inserção no log if( $id > 0 ){ $log = new Model_DbTable_Log(); $log->save($this, $data, 'insert', $id); } return $id; } public function update(array $data, $where) { if( isset($data['cpf']) && !empty($data['cpf']) ){ //verifica se o cpf já existe if( $this->existeCpf($data['cpf']) ){ $dados = $this->fetchRow($where); $dadosCpf = $this->fetchRow("cpf = '" . String_Refatorar::formatarCpf($data['cpf']) . "'"); //se o registro que está tentando alterar é diferente do registro do cpf existente, //não permite a alteração if( $dadosCpf['id'] != $dados['id'] ) throw new Core_Exception('CPF/CNPJ já está sendo utilizado'); } } if( isset($data['senha']) ){ if( (empty($data['senha']) || $data['senha'] == null ) ){ unset($data['senha']); } else { $data['senha'] = md5($data['senha']); } } $ns = new Zend_Session_Namespace(); if( Yuppie_Auth::getIdentity() && !$ns->acl->isAllowed( Yuppie_Auth::getIdentity()->grupo, 'alterar-prazo-fisico') ){ unset($data['prazo_fisico']); } //verifica se está liberando o acesso ao app if( isset($data['acesso_aplicativo']) && $data['acesso_aplicativo'] == 1 && $data['acesso_temporario'] != 1 ){ if( $this->getLimitApp() <= 0 ){ throw new Core_Exception('Você já atingiu o seu limite de ( ' . $this->getLimitApp() . ') licenças ' . 'para o aplicativo. Entre em contato com a Yuppie para adquirir mais licenças.'); } } if( array_key_exists('data_temporario_app', $data) && is_null($data['data_temporario_app']) ){ unset($data['data_temporario_app']); } if( empty($data['data_ultima_atualizacao']) ){ unset($data['data_ultima_atualizacao']); } if( array_key_exists("corretor_desativado", $data) && $data['corretor_desativado'] == null ){ $data['corretor_desativado'] = 0; } if(isset($data['obedecer_id']) && $data['obedecer_id'] == 2){ $data['obedecer_id'] = 0; } if(isset($data['descontar_taxa_transf']) && $data['descontar_taxa_transf'] == 2){ $data['descontar_taxa_transf'] = 0; } if ( Yuppie_Auth::getIdentity() && !$ns->acl->isAllowed(Yuppie_Auth::getIdentity()->grupo, 'bloquear-desbloquear-pagamento-corretor') ) { unset($data['bloquear_pagamento']); unset($data['motivo']); } if ( Yuppie_Auth::getIdentity() && !$ns->acl->isAllowed(Yuppie_Auth::getIdentity()->grupo, 'corretor', 'alterar-status-cadastro-corretor') ) { unset($data['status_cadastro']); } $result = parent::update($data, $where); //grava alteracao no log if( $result > 0 ){ $log = new Model_DbTable_Log(); $log->save($this, $data, $where, $this->_primary[1]); } return $result; } public function delete($where) { $data = array( 'excluido' => 1 ); $result = parent::update($data, $where); //grava alteracao no log if( $result > 0 ){ $log = new Model_DbTable_Log(); $log->save($this, $data, $where); } return $result; } public function fetchAll($where = null, $order = null, $count = null, $offset = null) { //verifica as permissoes $ns = new Zend_Session_Namespace(); $and = ""; if( !$ns->acl->isAllowed(Yuppie_Auth::getIdentity()->grupo, 'visualizar-corretores-filiais') ){ $and = " AND empresa_id = " . Yuppie_Auth::getIdentity()->empresa_id; } if( Yuppie_Auth::getIdentity()->grupo == "Corretor" ){ $and .= " AND id = " . Yuppie_Auth::getIdentity()->id; } elseif( isset(Yuppie_Auth::getIdentity()->corretor_id) && Yuppie_Auth::getIdentity()->corretor_id > 0 && !$ns->acl->isAllowed(Yuppie_Auth::getIdentity()->grupo, 'contrato', 'contratos-verificar') ){ $and .= " AND id = " . Yuppie_Auth::getIdentity()->corretor_id; } elseif( Yuppie_Auth::getIdentity()->grupo == "Supervisor" ){ $rota = new Model_Rota(); $rotas = $rota->getRotasIdBySupervisor(Yuppie_Auth::getIdentity()->id); if( !empty($rotas) ){ $and .= " AND rota_id in (" . implode(", ", $rotas) . ")"; } } if( ($where instanceof Zend_Db_Table_Select ) ){ $strWhere = "excluido<>1 " . $and; foreach ( $where->getPart(Zend_Db_Table_Select::WHERE) as $w ) { $strWhere .= " AND " . $w; } $where->where($strWhere . $and); } elseif( $where != null ){ $where = $where . " AND excluido<>1 " . $and; } else { $where = "excluido<>1 " . $and; } return parent::fetchAll($where, $order, $count, $offset); } public function getAniversariantesDoDia($count = null, $offset = null) { $data = Zend_Date::now(); $where = "tb_corretores.excluido<>1 AND DATE_FORMAT(tb_corretores.data_nascimento, '%d%m') = '" . $data->get('ddMM') . "'"; // se hoje for sexta-feira, pega aniversariantes do fim de semana também if( $data->get(Zend_Date::WEEKDAY_DIGIT) == 5 ){ $data->addDay(1); // sábado $where .= " OR DATE_FORMAT(tb_corretores.data_nascimento, '%d%m') = '" . $data->get('ddMM') . "'"; $data->addDay(1); // domingo $where .= " OR DATE_FORMAT(tb_corretores.data_nascimento, '%d%m') = '" . $data->get('ddMM') . "'"; } $where = "({$where})"; $order = 'nome'; $select = $this->getAdapter()->select()->from('tb_corretores') ->joinLeft('tb_rotas', 'tb_rotas.id = tb_corretores.rota_id', array( '' )) ->joinLeft('tb_gerente_rota', 'tb_gerente_rota.id = tb_rotas.gerente_id', array( 'supervisor' => 'nome' )) ->where($where) ->order($order); return $this->getAdapter()->fetchAll($select); } public function fetchRow($where = null, $order = null, $offset = null) { if( ($where instanceof Zend_Db_Table_Select ) ){ $strWhere = "excluido<>1"; foreach ( $where->getPart(Zend_Db_Table_Select::WHERE) as $w ) { $strWhere .= " AND " . $w; } $where->where($strWhere); } elseif( is_array($where) ){ $where[] = 'excluido<>1'; } elseif( $where != null ){ $where = $where . " AND excluido<>1"; } else { $where = "excluido<>1"; } return parent::fetchRow($where, $order, $offset); } public function getPaginatorAdapter($fields = null, $order = null) { $params = array( "corretores.excluido<>1" ); //verifica as permissoes $ns = new Zend_Session_Namespace(); $and = ""; if( !$ns->acl->isAllowed(Yuppie_Auth::getIdentity()->grupo, 'visualizar-corretores-filiais') ){ $and = " AND contratos.empresa_id = " . Yuppie_Auth::getIdentity()->empresa_id; } if( Yuppie_Auth::getIdentity()->grupo == "Supervisor" ){ $params[] = "rotas.gerente_id = " . Yuppie_Auth::getIdentity()->id; } $select = $this->getAdapter()->select()->from(array( "corretores" => "tb_corretores" ), array( "corretores.*" )) ->joinLeft(array( "rotas" => "tb_rotas" ), "corretores.rota_id = rotas.id", array( "rota" => "nome" )) ->joinLeft(array( "gerentes" => "tb_gerente_rota" ), "rotas.gerente_id = gerentes.id", array()) ->joinLeft(array( "senhas" => "tb_corretores_senhas" ), "corretores.id = senhas.corretor_id", array()); //trata os filtros if( isset($fields['id']) && !empty($fields['id']) ){ $params[] = "corretores.id = " . $fields['id']; } if( isset($fields['corretor_id']) && !empty($fields['corretor_id']) ){ $params[] = "corretores.id = " . $fields['corretor_id']; } if( isset($fields['rota_id']) && !empty($fields['rota_id']) ){ $params[] = "corretores.rota_id = " . $fields['rota_id']; } if( isset($fields['nome']) && !empty($fields['nome']) ){ $params[] = "corretores.nome LIKE '%" . $fields['nome'] . "%'"; } if( isset($fields['apelido']) && !empty($fields['apelido']) ){ $params[] = "corretores.apelido LIKE '%" . $fields['apelido'] . "%'"; } if( isset($fields['cpf']) && !empty($fields['cpf']) ){ $params[] = "corretores.cpf = '" . $fields['cpf'] . "'"; } if( isset($fields['senha']) && !empty($fields['senha']) ){ $params[] = "trim(leading 0 from senhas.senha) = '" . ltrim($fields['senha'], '0') . "'"; } if( isset($fields['acesso']) && !empty($fields['acesso']) ){ if( $fields['acesso'] == 0 ){ $params[] = "corretores.login IS NULL"; } else { $params[] = "corretores.login IS NOT NULL"; } } $where = implode(" AND ", $params); if( $where != null ) $select->where($where); $select->group("corretores.id"); if( $order != null ){ $select->order($order); } return new Zend_Paginator_Adapter_DbSelect($select); } public function fetchAllDependents($fields = null, $columns = array( 'corretores.*' ), $order = 'corretores.nome ASC') { if( count($fields) > 0 ){ $fields = array_filter($fields, function ($field) { return !is_null($field) && $field !== ""; }); foreach( $fields as $field => $value ){ if( !is_numeric($fields[$field]) && !is_array($fields[$field]) ){ $fields[$field] = addslashes($value); } } } $select = $this->getAdapter()->select()->from(array( 'corretores' => 'tb_corretores' ), $columns) ->joinLeft(array( 'rotas' => 'tb_rotas' ), 'corretores.rota_id = rotas.id', array( 'rota' => 'nome' )) ->joinLeft(array( 'gerentes' => 'tb_gerente_rota' ), 'rotas.gerente_id = gerentes.id', array( 'supervisor' => 'nome' )) ->where("corretores.excluido<>1"); //verifica as permissoes $ns = new Zend_Session_Namespace(); if( !$ns->acl->isAllowed(Yuppie_Auth::getIdentity()->grupo, 'visualizar-corretores-filiais') ){ $select->where(' corretores.empresa_id = ' . Yuppie_Auth::getIdentity()->empresa_id); } if( Yuppie_Auth::getIdentity()->grupo == 'Supervisor' ){ $select->where('rotas.gerente_id = ' . Yuppie_Auth::getIdentity()->id); } elseif( Yuppie_Auth::getIdentity()->grupo == 'Gerente Regional' ){ $select->where('gerentes.gerente_id = ' . Yuppie_Auth::getIdentity()->id); } elseif( Yuppie_Auth::getIdentity()->grupo == 'Corretor' ){ $select->where('corretores.id = ' . Yuppie_Auth::getIdentity()->id); } //trata os filtros if( !empty($fields['id']) ){ $fields['id'] = (int)$fields['id']; $select->where("corretores.id = ? ", $fields['id']); } if( !empty($fields['corretor_id']) ){ $select->where("corretores.id = ? ", $fields['corretor_id']); } if( !empty($fields['rota_id']) ){ $select->where('corretores.rota_id = ?', $fields['rota_id']); } if( !empty($fields['data_cadastro_de']) ){ $data = new Zend_Date($fields['data_cadastro_de']); $select->where("corretores.data_cadastro >= '{$data->get('yyyy-MM-dd')} 00:00:00'"); } if( !empty($fields['data_cadastro_a']) ){ $data = new Zend_Date($fields['data_cadastro_a']); $select->where("corretores.data_cadastro <= '{$data->get('yyyy-MM-dd')} 23:59:59'"); } if(!empty($fields['tipo_venda'])){ $select->where('corretores.tipo_venda = ?', $fields['tipo_venda']); } if( !empty($fields['usuario_id']) ){ $select->joinLeft(array( 'rede_atendimento' => 'tb_usuarios_rede_atendimento' ), 'rede_atendimento.corretor_id = corretores.id AND rede_atendimento.excluido <> 1', array()); $select->where('rede_atendimento.usuario_id = ? ', $fields['usuario_id']); } if( !empty($fields['nome']) ){ $select->where("corretores.nome LIKE ?", "%{$fields['nome']}%"); } if( !empty($fields['apelido']) ){ $select->where("corretores.apelido LIKE ? ", "%{$fields['apelido']}%"); } if( !empty($fields['cpf']) ){ $select->where("corretores.cpf = ? ", $fields['cpf']); } if( !empty($fields['nivel_esteira']) ){ $select->where("corretores.nivel_esteira = ? ", $fields['nivel_esteira']); } if( !empty($fields['senha']) ){ if( !array_key_exists('senhas', $select->getPart(Zend_Db_Select::FROM)) ){ $select->joinLeft(array( 'senhas' => 'tb_corretores_senhas' ), 'corretores.id = senhas.corretor_id AND senhas.excluido <> 1', array()); } $select->where("trim(leading 0 from senhas.senha) = ? ", ltrim($fields['senha'], '0')); } if( !empty($fields['acesso']) ){ if( $fields['acesso'] == -1 ){ $select->where('corretores.login IS NULL'); } else { $select->where('corretores.login IS NOT NULL'); } } if( !empty($fields['supervisor_id']) ){ $select->where('gerentes.id = ? ', $fields['supervisor_id']); } if( !empty($fields['cidade']) ){ $select->where("corretores.cidade LIKE ? ", "%{$fields['cidade']}%"); } if( !empty($fields['uf']) ){ $select->where("corretores.uf LIKE ? ", "%{$fields['uf']}%"); } if( !empty($fields['grupo_comissao']) ){ $select->where("corretores.grupo_comissao = ?", $fields['grupo_comissao']); } if( !empty($fields['login']) ){ $select->where("corretores.login LIKE ? ", "%{$fields['login']}%"); } if (!empty($fields['status_corretor'])) { switch ($fields['status_corretor']) { case 1: $select->where("corretores.corretor_desativado <> 1"); break; case 2: $select->where("corretores.corretor_desativado = 1"); break; case 3: $select->where("corretores.bloquear_pagamento = 1 AND motivo = 'CADASTRO EM ANÁLISE'"); break; case 4: $select->where("corretores.bloquear_pagamento = 1 AND motivo <> 'CADASTRO EM ANÁLISE'"); break; } } if (!empty($fields['status_cadastro'])) { $select->where('status_cadastro = ?', (int) $fields['status_cadastro']); } if( !empty($fields['acesso_aplicativo']) ){ if( $fields['acesso_aplicativo'] == 0 ){ $select->where('(corretores.acesso_aplicativo <= 0 or corretores.acesso_aplicativo is null)'); } else { $select->where('corretores.acesso_aplicativo = 1'); } } if( !empty($fields['empresa_id']) ){ $select->where('corretores.empresa_id = ? ', $fields['empresa_id']); } if( !empty($fields['banco_id']) ){ if( !array_key_exists('senhas', $select->getPart(Zend_Db_Select::FROM)) ){ $select->joinLeft(array( 'senhas' => 'tb_corretores_senhas' ), 'corretores.id = senhas.corretor_id AND senhas.excluido <> 1', array()); } if( is_array($fields['banco_id']) ){ $fields['banco_id'] = array_filter($fields['banco_id']); $select->where("senhas.banco_id IN ('" . implode("','", $fields['banco_id']) . "')"); } else { $select->where("senhas.banco_id = ? ", $fields['banco_id']); } } if( !empty($fields['possui_codigo_usuario']) ){ if( !array_key_exists('senhas', $select->getPart(Zend_Db_Select::FROM)) ){ $select->joinLeft(array( 'senhas' => 'tb_corretores_senhas' ), 'corretores.id = senhas.corretor_id AND senhas.excluido <> 1', array()); } if( $fields['possui_codigo_usuario'] == "SIM" ){ $select->where("(senhas.id IS NOT NULL AND senhas.excluido<>1)"); } elseif( $fields['possui_codigo_usuario'] == "NAO" ){ $select->where("(senhas.id IS NULL)"); } } if( !empty($fields['validade_certificado_de']) ){ $select->where("corretores.validade_certificado >= STR_TO_DATE('" . $fields['validade_certificado_de'] . "', '%d/%m/%Y')"); } if( !empty($fields['validade_certificado_a']) ){ $select->where("corretores.validade_certificado <= STR_TO_DATE('" . $fields['validade_certificado_a'] . "', '%d/%m/%Y')"); } if (isset($fields['termo_assinado'])) { $select->joinLeft(['termo_assinado' => 'tb_corretor_assinatura_termo'], 'termo_assinado.corretor_id = corretores.id AND termo_assinado.excluido = 0', [] ); $fields['termo_assinado'] > 0 ? $select->where('termo_assinado.data_assinatura IS NOT NULL') : $select->where('termo_assinado.data_assinatura IS NULL'); } if (!empty($fields['automatizacao_oportunidades_negocios'])) { if ($fields['automatizacao_oportunidades_negocios'] == 1) { $select->where("automatizacao_oportunidades_negocios = 1"); } else { $select->where("automatizacao_oportunidades_negocios = 0"); } } if (!empty($fields['mes_aniversario'])) { $select->where("MONTH(corretores.data_nascimento) = ?", $fields['mes_aniversario']); } $select->group('corretores.id'); if( $order != null ){ $select->order($order); } return $this->getAdapter()->fetchAll($select); } public function listarPorCidade($uf = null) { $select = $this->select() ->from(array( 'corretores' => 'tb_corretores' ), array( 'uf', 'cidade', 'qtde' => 'COUNT(id)' )) ->order(array( 'uf', 'cidade' )) ->group(array( 'uf', 'cidade' )); if( $uf ){ $select->where('uf = ?', $uf); } return $this->getAdapter()->fetchAll($select); } public function findByLogin($login) { $login = preg_replace('/[\x00-\x1F\x7F]/u', '', strip_tags($login)); return $this->fetchRow(["login LIKE ?" => $login]); } /** * @param string $email * @return array|null */ public function findByEmail(string $email): ?array { $sql = $this->getAdapter()->select() ->from(['c' => $this->_name]) ->where('email = ?', $email) ->where('excluido<>1'); $data = $this->getAdapter()->fetchRow($sql); return !empty($data) ? $data : []; } public function findAll($where = null, $order = null, $count = null, $offset = null) { if( ($where instanceof Zend_Db_Table_Select ) ){ $strWhere = "excluido<>1 "; foreach ( $where->getPart(Zend_Db_Table_Select::WHERE) as $w ) { $strWhere .= " AND " . $w; } $where->where($strWhere); } elseif( is_array($where) ){ $where[] = "excluido<>1"; } elseif( $where != null ){ $where = $where . " AND excluido<>1"; } else { $where = "excluido<>1"; } return parent::fetchAll($where, $order, $count, $offset); } public function changePassword($dados = null, $where = null) { $result = null; unset($dados['confirmar_senha']); $dados['data_alteracao_senha'] = Zend_Date::now()->get('yyyy-MM-dd'); $dados['mudar_senha'] = null; if( count($dados) > 0 ){ $result = $this->update($dados, "id = " . $where->id); } return $result; } public function findExistToken($corretorId) { if( ($result = $this->fetchRow("token_aplicativo IS NOT NULL AND id = '" . $corretorId . "'")) != null ){ return $result->token_aplicativo; } return false; } /** * Retorna a quantidade de licenças disponíveis para o uso do aplicativo */ public function getLimitApp() { $config = new Zend_Config_Ini(CLIENT_PATH . '/configs/application.ini', APPLICATION_ENV); $select = $this->getAdapter()->select()->from($this->_name, array( 'COUNT(id)' )) ->where("excluido<>1") ->where("acesso_aplicativo = 1"); $fetch = $this->getAdapter()->fetchCol($select); if( $fetch ){ return ($config->yuppie->app_licenses - $fetch[0]); } return $config->yuppie->app_licenses; } public function fetchPairs($field, $where = null, $order = null, $key = null) { if( !$key ){ $key = $this->getPrimaryKey(); if( is_array($key) ){ if( count($key) != 1 ){ throw new Yuppie_Exception( 'can not fetchPairs with array as $_primary'); } $key = current($key); } } $select = $this->select() ->from($this->_name, array( $key, $field )); if( is_array($where) ){ $where[] = "{$this->_name}.excluido <> 1"; foreach ( $where as $cond => $value ) { if( is_numeric($cond) ){ $select->where($value); } else { $select->where($cond, $value); } } }elseif($where != null ){ $select->where($where); } $select->where("{$this->_name}.excluido <> 1"); $select->order($order ? $order : $field); return $this->getAdapter()->fetchPairs($select); } public function fetchColumns($columns, $where = null, $order = null, $key = null){ if( !$key ){ $key = $this->getPrimaryKey(); if( is_array($key) ){ if( count($key) != 1 ){ throw new Yuppie_Exception( 'can not fetchColumns with array as $_primary'); } $key = current($key); } } $select = $this->select() ->from($this->_name, $columns); if (is_array($where)) { $where[] = "{$this->_name}.excluido <> 1"; foreach ( $where as $cond => $value ) { if( is_numeric($cond) ){ $select->where($value); } else { $select->where($cond, $value); } } } elseif($where != null ) { $select->where($where, "{$this->_name}.excluido <> 1"); } else { $select->where("excluido<>1"); } $select->order($order); return $this->getAdapter()->fetchAll($select); } public function fetchPairsPagarComissao($field, $where = null, $order = null, $invert = false, $key = null) { if( !$key ){ $key = $this->getPrimaryKey(); if( is_array($key) ){ if( count($key) != 1 ){ throw new Yuppie_Exception( 'can not fetchPairs with array as $_primary'); } $key = current($key); } } $columns = $invert ? array($field, new Zend_Db_Expr("CASE WHEN bloquear_pagamento <> 1 THEN $key ELSE CONCAT('block_', id) END")) : array(new Zend_Db_Expr("CASE WHEN bloquear_pagamento <> 1 THEN $key ELSE CONCAT('block_', id) END"), $field); $select = $this->select() ->from($this->_name, $columns); if( is_array($where) ){ $where[] = "{$this->_name}.excluido <> 1"; foreach ( $where as $cond => $value ) { if( is_numeric($cond) ){ $select->where($value); } else { $select->where($cond, $value); } } }elseif($where != null ){ $select->where($where); } $select->where("{$this->_name}.excluido <> 1"); $select->order($order ? $order : $field); return $this->getAdapter()->fetchPairs($select); } public function selectCorretorPorNome($nome) { $select = $this->getAdapter()->select() ->from($this->_name) ->where("nome = ?", $nome) ->where('excluido = 0'); return $this->getAdapter()->fetchRow($select); } public function selectCorretorCertificadoAVencer($idCorretor = null) { $dataFinal = Zend_Date::now()->addDay(45)->get('yyyy-MM-dd'); $select = $this->getAdapter()->select() ->from($this->_name, [ 'id', 'nome', 'email', 'validade_certificado', 'numero_certificado', 'dias_restantes' => new Zend_Db_Expr("DATEDIFF(`validade_certificado`, CURDATE())") ]) ->where("validade_certificado <= '{$dataFinal}'") ->where('excluido = 0') ->order('dias_restantes'); if ($idCorretor) { $select->where('id = ?', $idCorretor); return $this->getAdapter()->fetchRow($select); } return $this->getAdapter()->fetchAll($select); } /** * @param int $corretorId * @return array */ public function getCamposDadosBancarios(int $corretorId): array { $select = $this->getAdapter()->select() ->from($this->_name, [ 'banco', 'agencia', 'conta', 'titular', 'cpf_titular', 'tipo_conta', 'chave_pix' ] ) ->where("id = {$corretorId} AND excluido = 0"); return $this->getAdapter()->fetchRow($select); } /** * @param int $corretorId * @return mixed */ public function getGerenteRota(int $corretorId) { $select = $this->getAdapter()->select()->from(['gerentes' => 'tb_gerente_rota']) ->join(['rotas' => 'tb_rotas'], 'rotas.gerente_id = gerentes.id', []) ->join(['corretores' => 'tb_corretores'], 'corretores.rota_id = rotas.id', ['corretor_nome' => 'nome']) ->where('corretores.id = ?', $corretorId) ->where('corretores.excluido <> 1') ; return $this->getAdapter()->fetchRow($select); } }
💾 保存文件
← 返回文件管理器