✏️ 正在编辑: Proposta.php
路径:
/srv/systems_dir/yuppiecred-lidernegocios/application/models/DbTable/Proposta.php
提示:
您可以编辑任何文件(包括二进制文件),但请注意不当修改可能导致文件损坏。
<?php class Model_DbTable_Proposta extends Core_DbTable { protected $_primary = 'id'; protected $_name = 'tb_contratos'; protected static $_viewName = 'vw_contratos'; protected $_referenceMap = array( 'Cliente' => array( 'columns' => array( 'cliente_id' ), 'refTableClass' => 'Model_DbTable_Cliente', 'refColumns' => array( 'id' ) ), 'Corretor' => array( 'columns' => array( 'corretor_id' ), 'refTableClass' => 'Model_DbTable_Corretor', 'refColumns' => array( 'id' ) ), 'Banco' => array( 'columns' => array( 'banco_id' ), 'refTableClass' => 'Model_DbTable_Banco', 'refColumns' => array( 'id' ) ), 'Tabela' => array( 'columns' => array( 'tabela_id' ), 'refTableClass' => 'Model_DbTable_Tabela', 'refColumns' => array( 'id' ) ), 'Orgao' => array( 'columns' => array( 'convenio_id' ), 'refTableClass' => 'Model_DbTable_Convenio', 'refColumns' => array( 'id' ) ), 'StatusProposta' => array( 'columns' => array( 'status_proposta' ), 'refTableClass' => 'Model_DbTable_Tipos', 'refColumns' => array( 'id' ) ), 'Empresa' => array( 'columns' => array( 'empresa_id' ), 'refTableClass' => 'Model_DbTable_Empresa', 'refColumns' => array( 'id' ) ), ); public static function getViewName() { return self::$_viewName; } public function fetchAll($where = null, $order = null, $count = null, $offset = null) { $and = ""; if( Yuppie_Auth::getIdentity()->grupo == "Corretor" ){ $and = " AND corretor_id = " . Yuppie_Auth::getIdentity()->id; } if( ($where instanceof Zend_Db_Table_Select ) ){ $strWhere = "tipo_registro = 0 AND excluido<>1" . $and; foreach ( $where->getPart(Zend_Db_Table_Select::WHERE) as $w ) { $strWhere .= " AND " . $w; } $where->where($strWhere); } elseif( $where != null ){ $where = $where . " AND tipo_registro = 0 AND excluido<>1" . $and; } else { $where = "tipo_registro = 0 AND excluido<>1" . $and; } return parent::fetchAll($where, $order, $count, $offset); } public function fetchRow($where = null, $order = null, $offset = null) { $and = ""; if (!empty(Yuppie_Auth::getIdentity()->grupo) && Yuppie_Auth::getIdentity()->grupo == "Corretor") { $and = " AND corretor_id = " . Yuppie_Auth::getIdentity()->id; } if (($where instanceof Zend_Db_Table_Select )) { $strWhere = "tipo_registro = 0 AND excluido<>1" . $and; foreach ( $where->getPart(Zend_Db_Table_Select::WHERE) as $w ) { $strWhere .= " AND " . $w; } $where->where($strWhere); } elseif(is_array($where)) { $where[] = "{$this->_name}.tipo_registro = 0 AND {$this->_name}.excluido<>1"; } elseif($where != null ) { $where = $where . " AND tipo_registro = 0 AND excluido<>1" . $and; } else { $where = "tipo_registro = 0 AND excluido<>1" . $and; } return parent::fetchRow($where, $order, $offset); } public function insert(array $data) { $data['tipo_registro'] = 0; if (Yuppie_Auth::getIdentity() && Yuppie_Auth::getIdentity()->grupo == "Corretor") { $data['status_proposta'] = 70; //Digitado pelo corretor } else { $data['status_proposta'] = 66; //Digitado } $data = $this->_formatDecimal($data); if( isset($data['numero_contrato']) && !empty($data['numero_contrato']) && isset($data['banco_id']) && !empty($data['banco_id']) ){ if( $this->existeNumeroContrato($data['banco_id'], $data['numero_contrato']) ){ return null; } } if (empty($data['digitador'])) { $data['digitador'] = Yuppie_Auth::getIdentity() ? Yuppie_Auth::getIdentity()->login : NULL; } if (!empty($data['tabela_id'])) { $data['tipo_formalizacao'] = (new Model_Tabela())->getTipoFormalizacaoById($data['tabela_id']); } Yuppie_Log::write("Tentativa de inserção da proposta com os dados => " . print_r($data, true), $this); return parent::insert($data); } public function update(array $data, $where) { unset($data['cliente_id']); unset($data['status_proposta']); if( array_key_exists('digitado_banco', $data) && $data['digitado_banco'] != 1 ){ $proposta = $this->fetchRow($where); if ($proposta['digitado_banco'] == 1){ unset($data['digitado_banco']); #throw new Core_Exception('Atenção! Proposta já digitada no banco.'); } } $data = $this->_formatDecimal($data); if( isset($data['numero_contrato']) && !empty($data['numero_contrato']) && isset($data['banco_id']) && !empty($data['banco_id']) ){ if( $dadosContrato = $this->existeNumeroContrato($data['banco_id'], $data['numero_contrato']) ){ $dados = $this->fetchRow($where); $dadosContrato = parent::fetchRow("banco_id = " . $data['banco_id'] . " AND numero_contrato = '" . $data['numero_contrato'] . "' AND tipo_registro = 1"); if( $dadosContrato && $dados['id'] != $dadosContrato['id'] ){ throw new Core_Exception('Atenção! O número do contrato já existe.'); } } } if( isset($data['digitacao_rapida']) && empty($data['digitacao_rapida']) ){ unset($data['digitacao_rapida']); } if( isset($data['status']) && empty($data['status']) ){ unset($data['status']); } if( isset($data['usuario_fraude']) && empty($data['usuario_fraude']) ){ unset($data['usuario_fraude']); } if( isset($data['data_validacao_fraude']) && empty($data['data_validacao_fraude']) ){ unset($data['data_validacao_fraude']); } if( isset($data['reanexo']) && empty($data['reanexo']) ){ unset($data['reanexo']); } if (!empty($data['tabela_id'])) { $data['tipo_formalizacao'] = (new Model_Tabela())->getTipoFormalizacaoById($data['tabela_id']); } return parent::update($data, $where); } protected function _formatDecimal($data) { $filter = new Core_FilterValor(); if( isset($data['valor_beneficio']) ){ $data['valor_beneficio'] = $filter->filter($data['valor_beneficio']); } if( isset($data['valor_bruto']) ){ $data['valor_bruto'] = $filter->filter($data['valor_bruto']); } if( isset($data['valor_liquido']) ){ $data['valor_liquido'] = $filter->filter($data['valor_liquido']); } if( isset($data['base_comissao_valor']) ){ $data['base_comissao_valor'] = $filter->filter($data['base_comissao_valor']); } if( isset($data['base_comissao_adiantamento']) ){ $data['base_comissao_adiantamento'] = $filter->filter($data['base_comissao_adiantamento']); } if( isset($data['base_comissao_diferimento']) ){ $data['base_comissao_diferimento'] = $filter->filter($data['base_comissao_diferimento']); } if( isset($data['base_comissao_bonus']) ){ $data['base_comissao_bonus'] = $filter->filter($data['base_comissao_bonus']); } if( isset($data['base_comissao_empresa_valor']) ){ $data['base_comissao_empresa_valor'] = $filter->filter($data['base_comissao_empresa_valor']); } if( isset($data['base_comissao_empresa_adiantamento']) ){ $data['base_comissao_empresa_adiantamento'] = $filter->filter($data['base_comissao_empresa_adiantamento']); } if( isset($data['base_comissao_empresa_bonus']) ){ $data['base_comissao_empresa_bonus'] = $filter->filter($data['base_comissao_empresa_bonus']); } if( isset($data['comissao_corretor']) ){ $data['comissao_corretor'] = $filter->filter($data['comissao_corretor']); } if( isset($data['comissao_empresa']) ){ $data['comissao_empresa'] = $filter->filter($data['comissao_empresa']); } if( isset($data['valor_prestacao']) ){ $data['valor_prestacao'] = $filter->filter($data['valor_prestacao']); } if( isset($data['saldo_banco']) ){ $data['saldo_banco'] = $filter->filter($data['saldo_banco']); } if( isset($data['anterior_saldo_devedor']) ){ $data['anterior_saldo_devedor'] = $filter->filter($data['anterior_saldo_devedor']); } if( isset($data['anterior_valor_parcela']) ){ $data['anterior_valor_parcela'] = $filter->filter($data['anterior_valor_parcela']); } if( isset($data['valor_reducao']) ){ $data['valor_reducao'] = $filter->filter($data['valor_reducao']); } return $data; } public function existeNumeroContrato($bancoId, $numero) { return (parent::fetchRow("banco_id = " . $bancoId . " AND numero_contrato = '" . $numero . "'") != null) ? true : false; } public function registrarImpressao($dataImpressao, $usuarioImpressao, $id) { $data = array( 'data_impressao' => $dataImpressao, 'usuario_impressao' => $usuarioImpressao ); $where = [ 'id = ?' => $id, 'usuario_impressao IS NULL' ]; return parent::update($data, $where, false); } public function existeTokenAplicativo($token, $corretorId) { return (parent::fetchRow("corretor_id = " . $corretorId . " AND token_proposta = '" . $token . "'") != null) ? true : false; } public function retirarReAnexo($propostaId) { return parent::update(array( 'reanexo' => 0 ), "id = {$propostaId}"); } /** * Verifica se a proposta pode ser efetivada * @param int $id Id da proposta * @return boolean Retorna true caso possa efetivar * @throws Core_Exception */ public function podeEfetivar($id) { $proposta = $this->fetchRow("id = {$id}"); //checa se a proposta existe if( !$proposta ){ throw new Core_Exception("ID de proposta não localizado."); } if( empty($proposta->numero_contrato) ){ throw new Core_Exception("Você precisa informar um número de contrato válido!"); } $dados['numero_contrato'] = addslashes($proposta->numero_contrato); $dados['numero_ade'] = addslashes($proposta->numero_ade); //Checa se já existe um contrato cadastrado com essas informações $where = "(numero_contrato = '{$dados['numero_contrato']}'"; if( !empty($dados['numero_ade']) ){ $where .= " OR numero_ade = '{$dados['numero_ade']}'"; } $where .= ") AND banco_id = {$proposta->banco_id}"; $dbContrato = new Model_DbTable_Contrato(); $contrato = $dbContrato->fetchRow($where); if( $contrato ){ throw new Core_Exception("Já existe um contrato efetivado com essas informações."); } return true; } public function efetivarProposta($id, $statusEfetivacao = 66) { $data = [ 'tipo_registro' => 1, 'status_proposta' => $statusEfetivacao, 'usuario_efetivacao' => Yuppie_Auth::getIdentity()->login, 'data_efetivacao' => date('Y-m-d') ]; if ($statusEfetivacao == 43) { $data['data_liberacao'] = date('Y-m-d'); } return parent::update($data, ["id = ?" => $id]); } }
💾 保存文件
← 返回文件管理器