✏️ 正在编辑: Cliente.php
路径:
/srv/systems_dir/yuppiecred/application/models/Cliente.php
提示:
您可以编辑任何文件(包括二进制文件),但请注意不当修改可能导致文件损坏。
<?php class Model_Cliente extends Model_PessoaFisica { private $_empresaId; private $_obs; private $_senhaContracheque; private $_anexoCpf; private $_anexoRg; private $_anexoContraCheque; private $_renda; private $_profissao; private $_anosServicos; private $_mesesServicos; private $_tipoComprovante; private $_orgaoPagador; private $_numeroDependentes; private $_compoeRenda; private $_tipoMoradia; private $_empresaBeneficiado; private $_matricula; private $_orgao; private $_representanteLegal; private $_nomeRepresentante; private $_cpfRepresentante; public function getEmpresaId() { return $this->_empresaId; } public function setEmpresaId($empresaId) { $this->_empresaId = $empresaId; } public function getObs() { return $this->_obs; } public function setObs($obs) { $this->_obs = $obs; } public function getSenhaContracheque() { return $this->_senhaContracheque; } public function setSenhaContracheque($senhaContracheque) { $this->_senhaContracheque = $senhaContracheque; } public function getAnexoCpf() { return $this->_anexoCpf; } public function getAnexoRg() { return $this->_anexoRg; } public function getAnexoContraCheque() { return $this->_anexoContraCheque; } public function setAnexoCpf($anexoCpf) { $this->_anexoCpf = $anexoCpf; } public function setAnexoRg($anexoRg) { $this->_anexoRg = $anexoRg; } public function setAnexoContraCheque($anexoContraCheque) { $this->_anexoContraCheque = $anexoContraCheque; } public function getRenda() { return $this->_renda; } public function setRenda($renda) { $rendaTratada = empty($renda) ? 0.0 : $renda; return $this->setFloat(trim($rendaTratada)); } public function __construct($options = null) { if( is_array($options) ){ $this->setOptions($options); } } public function getProfissao() { return $this->_profissao; } public function getAnosServicos() { return $this->_anosServicos; } public function getMesesServicos() { return $this->_mesesServicos; } public function getTipoComprovante() { return $this->_tipoComprovante; } public function getOrgaoPagador() { return $this->_orgaoPagador; } public function getNumeroDependentes() { return $this->_numeroDependentes; } public function getCompoeRenda() { return $this->_compoeRenda; } public function getTipoMoradia() { return $this->_tipoMoradia; } public function getEmpresaBeneficiado() { return $this->_empresaBeneficiado; } public function setProfissao($profissao) { $this->_profissao = $profissao; } public function setAnosServicos($anosServicos) { $this->_anosServicos = $anosServicos; } public function setMesesServicos($mesesServicos) { $this->_mesesServicos = $mesesServicos; } public function setTipoComprovante($tipoComprovante) { $this->_tipoComprovante = $tipoComprovante; } public function setOrgaoPagador($orgaoPagador) { $this->_orgaoPagador = $orgaoPagador; } public function setNumeroDependentes($numeroDependentes) { $this->_numeroDependentes = $numeroDependentes; } public function setCompoeRenda($compoeRenda) { $this->_compoeRenda = $compoeRenda; } public function setTipoMoradia($tipoMoradia) { $this->_tipoMoradia = $tipoMoradia; } public function setEmpresaBeneficiado($empresaBeneficiado) { $this->_empresaBeneficiado = $empresaBeneficiado; } public function getMatricula() { return $this->_matricula; } public function setMatricula($matricula): void { $this->_matricula = $matricula; } public function getOrgao() { return $this->_orgao; } public function setOrgao($orgao): void { $this->_orgao = $orgao; } public function getRepresentanteLegal() { return $this->_representanteLegal; } public function setRepresentanteLegal($representanteLegal): void { $this->_representanteLegal = $representanteLegal; } public function getNomeRepresentante() { return $this->_nomeRepresentante; } public function setNomeRepresentante($nomeRepresentante): void { $this->_nomeRepresentante = $nomeRepresentante; } public function getCpfRepresentante() { return $this->_cpfRepresentante; } public function setCpfRepresentante($cpfRepresentante): void { $this->_cpfRepresentante = $cpfRepresentante; } 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_Cliente(); $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 corretor passado por parâmetro * @param Model_Cliente $cliente */ public function salvar(Model_Cliente $cliente) { $dbtable = new Model_DbTable_Cliente(); if( $cliente->getId() > 0 ){ $dbtable->update($cliente->_toArray(), "id = " . $cliente->getId()); return $cliente->getId(); } else { return $dbtable->insert($cliente->_toArray()); } } /** * Exclui o corretor 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_Cliente(); return $dbtable->delete("id = " . $id); } return null; } /** * Retorna uma lista de corretores * @param string $where * @param string $order * @param int $count * @param int $offset * @return array */ public function listar($where = null, $order = null, $count = null, $offset = null) { $dbtable = new Model_DbTable_Cliente(); return $dbtable->fetchAll($where, $order, $count, $offset); } /** * 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_Cliente(); return $dbtable->fetchRow("id = " . $id); } /** * Verifica se o registro passado por parâmetro existe * @param string $cpf * @return Zend_Db_Table_Row_Abstract|null The row results per the * Zend_Db_Adapter fetch mode, or null if no row found. */ public function existe($cpf) { $dbtable = new Model_DbTable_Cliente(); return $dbtable->fetchRow("cpf = '" . String_Refatorar::formatarCpf($cpf) . "'"); } public function getContratos($fields, $order = "id ASC") { $params = array(); $where = null; if( isset($fields['cliente_id']) && $fields['cliente_id'] > 0 ){ $params[] = "cliente_id = " . $fields['cliente_id']; } if( count($params) > 0 ) $where = implode( " AND ", $params); $contrato = new Model_Contrato(); return $contrato->listar($where, $order); } public function getPropostas($fields, $order = "id ASC") { $proposta = new Model_Proposta(); return $proposta->listar($fields, $order); } public function getCpfs() { $dbtable = new Model_DbTable_Cliente(); $values = $dbtable->fetchAll(); $cpfs = array(); foreach( $values as $value ){ $cpfs[$value['id']] = $value['cpf']; } return $cpfs; } public function salvarAnexos(array $anexos, $clienteId) { $dbCliente = new Model_DbTable_Cliente(); $params = array(); if(count($anexos) > 0){ if(isset($anexos['anexo_cpf'])){ $params['anexo_cpf'] = $anexos['anexo_cpf']; } if(isset($anexos['anexo_rg'])){ $params['anexo_rg'] = $anexos['anexo_rg']; } if(isset($anexos['anexo_contra_cheque'])){ $params['anexo_contra_cheque'] = $anexos['anexo_contra_cheque']; } $result = $dbCliente->update($params, 'id = '. $clienteId); return $result; } return false; } public function getDadosUltimaProposta(int $clienteId) : ?array { $dadosProposta = (new Model_DbTable_Proposta())->fetchRow(['cliente_id = ?' => $clienteId], 'id DESC'); $dadosCliente = (new Model_DbTable_Cliente())->fetchRow("id = " . $clienteId); if (!empty($dadosProposta)) { $dadosProposta = array_filter($dadosProposta->toArray(), function($value) { return ($value !== null && $value !== false && $value !== '' && $value != '0.00'); }); } if (!empty($dadosCliente)) { $dadosCliente = array_filter($dadosCliente->toArray(), function($value) { return ($value !== null && $value !== false && $value !== '' && $value != '0'); }); } if (!empty($dadosCliente) && !empty($dadosProposta)) { unset($dadosCliente['empresa_id']); unset($dadosCliente['data_cadastro']); unset($dadosCliente['tipo_registro']); unset($dadosProposta['id']); unset($dadosProposta['cliente_id']); unset($dadosProposta['empresa_id']); unset($dadosProposta['banco_id']); unset($dadosProposta['tabela_id']); unset($dadosProposta['corretor_id']); unset($dadosProposta['tipo']); unset($dadosProposta['data_emissao']); unset($dadosProposta['prazo']); unset($dadosProposta['produto']); unset($dadosProposta['status_proposta']); unset($dadosProposta['digitador']); unset($dadosProposta['tipo_formalizacao']); unset($dadosProposta['tipo_registro']); unset($dadosProposta['pendente']); foreach ($dadosProposta as $key => $value) { if (stristr($key, "convenio_id") || stristr($key, "base_") || stristr($key, "valor_") || stristr($key, "data_")) { unset($dadosProposta[$key]); } } return array_merge($dadosCliente, $dadosProposta); } if (!empty($dadosCliente)) { return $dadosCliente; } if (!empty($dadosProposta)) { return $dadosProposta; } } public static function salvarClienteOportunidade($idClienteBase) { $dadosCliente = (new Model_DbTable_CallcenterBase())->fetchRow(['id = ?' => $idClienteBase])->toArray(); unset($dadosCliente['id']); $dadosCliente['empresa_id'] = Yuppie_Auth::getIdentity()->empresa_id; $cliente = new Model_Cliente($dadosCliente); $cliente->salvar($cliente); return $cliente->_toArray(); } public function getOrCreateByCpf() { $dadosCliente = $this->existe($this->getCpf()); $model = $this; if ($dadosCliente) { $model = new Model_Cliente(array_merge($dadosCliente->toArray(), array_filter($this->_toArray()))); } return $model->salvar($model); } }
💾 保存文件
← 返回文件管理器