✏️ 正在编辑: CorretorSenha.php
路径:
/srv/systems_dir/yuppiecred-lidernegocios/application/models/CorretorSenha.php
提示:
您可以编辑任何文件(包括二进制文件),但请注意不当修改可能导致文件损坏。
<?php class Model_CorretorSenha { private $_id; private $_corretorId; private $_bancoId; private $_senha; private $_descricao; public function getId() { return $this->_id; } public function setId($id) { $this->_id = $id; } public function getCorretorId() { return $this->_corretorId; } public function setCorretorId($corretorId) { $this->_corretorId = $corretorId; } public function getBancoId() { return $this->_bancoId; } public function setBancoId($bancoId) { $this->_bancoId = $bancoId; return $this; } public function getSenha() { return $this->_senha; } public function setSenha($senha) { $this->_senha = trim($senha); } public function getDescricao() { return $this->_descricao; } public function setDescricao($descricao) { $this->_descricao = $descricao; } 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_CorretorSenha(); $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_CorretorSenha $corretorSenha */ public function salvar(Model_CorretorSenha $corretorSenha) { $dbtable = new Model_DbTable_CorretorSenha(); if($this->verificaSenhaByCorretor($corretorSenha->_toArray())){ throw new Core_Exception('Banco e Código de Usuário já estão vinculados'); } if( $corretorSenha->getId() > 0 ){ $dbtable->update($corretorSenha->_toArray(), "id = " . $corretorSenha->getId()); $result = $corretorSenha->getId(); } else { $result = $dbtable->insert($corretorSenha->_toArray()); } $count = $this->atualizaContratoPorDigitador($corretorSenha->getSenha(), $corretorSenha->getBancoId(), $corretorSenha->getCorretorId()); if($result){ $msg = $count > 0 ? "Registro adicionado com sucesso! {$count} contrato(s) atualizado(s)!" : "Registro adicionado com sucesso!"; return ['success' => $msg]; }else{ return ['alert' => 'Nenhum registro foi adicionado!']; } } public function verificaSenhaByCorretor($fields) { $dbSenhas = new Model_DbTable_CorretorSenha(); return $dbSenhas->verificaSenhaCadastrada($fields['senha'], $fields['banco_id']); } /** * Retorna uma lista * @param string $where * @param string $order * @param int $count * @param int $offset * @return array */ public function listar($fields, $order = "id ASC") { $params = array(); $where = null; if( isset($fields['corretor_id']) && !empty($fields['corretor_id']) ){ $params[] = "corretor_id = " . $fields['corretor_id']; } if( count($params) > 0 ) $where = implode(" AND ", $params); $dbtable = new Model_DbTable_CorretorSenha(); 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_CorretorSenha(); 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_CorretorSenha(); return $dbtable->fetchRow("id = " . $id); } public function getCorretorBySenha($senha, $bancoId) { $dbtable = new Model_DbTable_CorretorSenha(); $dados = $dbtable->fetchRow("banco_id = '$bancoId' AND corretor_id > 0 AND trim(leading 0 from senha) = '" . ltrim($senha, '0') . "'"); if($dados){ $corretor = new Model_DbTable_Corretor; return $corretor->fetchRow("id = $dados->corretor_id"); } return null; } public function getCorretorIdBySenha($senha, $bancoId) { $dbtable = new Model_DbTable_CorretorSenha(); $dados = $dbtable->fetchRow("banco_id = '{$bancoId}' AND corretor_id > 0 AND trim(leading 0 from senha) = '" . ltrim($senha, '0') . "'"); //caso não encontre o código de usuário com o banco, ele atualiza o banco, onde o banco é nulo. if( empty($dados) && !isset($dados) ){ $result = $dbtable->update(array( 'banco_id' => $bancoId ), "(banco_id IS NULL OR banco_id = 0) AND trim(leading 0 from senha) = '" . ltrim($senha, '0') . "'"); if( $result ){ $dados = $dbtable->fetchRow("banco_id = '{$bancoId}' AND corretor_id > 0 AND trim(leading 0 from senha) = '" . ltrim($senha, '0') . "'"); } } if( $dados != null ){ $this->setOptions($dados->toArray()); return $dados['corretor_id']; } return null; } public function atualizarBancoUsuario($id, $bancoId) { if( $id > 0 && $bancoId != '' ){ $dbtable = new Model_DbTable_CorretorSenha(); $result = $dbtable->update(array( 'banco_id' => $bancoId ), "id = " . $id); return $result; } return null; } public function atualizarDescricaoUsuario($id, $descricao) { if( $id > 0 && $descricao != '' ){ $dbtable = new Model_DbTable_CorretorSenha(); $result = $dbtable->update(array( 'descricao' => $descricao ), "id = " . $id); return $result; } return null; } public function getSenhasByCorretor($corretorId, $bancoId = null, $order = "id ASC") { if( !$corretorId ){ return null; } $dbtable = new Model_DbTable_CorretorSenha(); $select = $dbtable->getAdapter()->select()->from(array( 'corretores_senhas' => 'tb_corretores_senhas' )) ->joinInner(array( 'bancos' => 'tb_bancos' ), 'bancos.id = corretores_senhas.banco_id', array( 'banco' => 'bancos.nome' )) ->where("corretores_senhas.excluido <> 1 AND corretores_senhas.corretor_id = {$corretorId}") ->order($order); if($bancoId != null){ $select->where("corretores_senhas.banco_id = $bancoId"); } return $dbtable->getAdapter()->fetchAll($select); } public function atualizaContratoPorDigitador($senha, $bancoId, $corretorId) { $where = [ "banco_id = ?" => $bancoId, "trim(leading 0 from digitador) = ?" => ltrim($senha, '0'), "coalesce(corretor_id, 0) = 0" ]; $dbContrato = new Model_DbTable_Contrato(); $contratos = $dbContrato->fetchAll($where); $count = 0; if(count($contratos) <= 0){ return; } foreach ($contratos as $contrato){ $updateContrato = $dbContrato->update( ["corretor_id" => $corretorId], ["id = ?" => $contrato->id] ); if ($updateContrato){ $count++; } } return $count; } }
💾 保存文件
← 返回文件管理器