✏️ 正在编辑: Tabela.php
路径:
/srv/systems_dir/yuppiecred-lidernegocios/application/models/DbTable/Tabela.php
提示:
您可以编辑任何文件(包括二进制文件),但请注意不当修改可能导致文件损坏。
<?php class Model_DbTable_Tabela extends Core_DbTable { protected $_primary = 'id'; protected $_name = 'tb_tabelas'; protected static $_viewName = 'vw_tabelas'; protected $_referenceMap = array( 'Convenio' => array( 'columns' => array( 'convenio_id' ), 'refTableClass' => 'Model_DbTable_Convenio', 'refColumns' => array( 'id' ) ), 'Banco' => array( 'columns' => array( 'banco_id' ), 'refTableClass' => 'Model_DbTable_Banco', 'refColumns' => array( 'id' ) ), 'TabelaPai' => array( 'columns' => array( 'parent_id' ), 'refTableClass' => 'Model_DbTable_Tabela', 'refColumns' => array( 'id' ) ) ); public static function getViewName() { return self::$_viewName; } public function insert(array $data) { if( !empty($data['parent_id']) && !empty($data['id'])){ if(!$this->updateWithParent($data['parent_id'],$data['id'])){ unset($data['parent_id']); } } $tratamento = array_filter($data); //trata pelo código e nome if( !empty($tratamento['codigo']) && !empty($tratamento['convenio_id']) && !empty($tratamento['banco_id']) && !empty($tratamento['nome']) ){ if( ($dados = $this->fetchRow( [ "trim(codigo) = ?" => trim($tratamento['codigo']), "trim(nome) = ?" => trim($tratamento['nome']), "convenio_id = ?" => $tratamento['convenio_id'], "banco_id = ?" => $tratamento['banco_id'], ])) != null ){ return $dados->parent_id ?? $dados->id; } } //trata pelo nome, código tem que estar vazio if( !empty($tratamento['nome']) && !empty($tratamento['convenio_id']) && !empty($tratamento['banco_id']) && empty($tratamento['codigo']) ){ if( ($dados = $this->fetchRow( [ "trim(nome) = ?" => trim($tratamento['nome']), "convenio_id = ? " => $tratamento['convenio_id'], "banco_id = ? " => $tratamento['banco_id'], ] )) != null ){ return $dados->parent_id ?? $dados->id; } } $data['usuario_cadastro'] = Yuppie_Auth::getIdentity() ? Yuppie_Auth::getIdentity()->login : "Webservice"; $data['taxa'] = String_Refatorar::parseStringToFloat($data['taxa']); return parent::insert($data); } public function updateWithParent($paiId, $filhoId){ $pai = parent::fetchRow("id = {$paiId}"); $filho = parent::fetchRow("id = {$filhoId}"); if( ($filho->id == $pai->id) || ($filho->banco_id != $pai->banco_id) || ($filho->convenio_id != $pai->convenio_id) ){ return false; }else{ return true; } } public function update(array $data, $where, $registerLog = true) { if (!empty($data['data_desativacao']) && !empty($data['tabela_desativada'])) { $data['data_desativou'] = date('Y-m-d H:i:s'); $data['usuario_desativou'] = Yuppie_Auth::getIdentity()->login; } if( !empty($data['parent_id']) && !empty($data['id'])){ if(!$this->updateWithParent($data['parent_id'],$data['id'])){ unset($data['parent_id']); } } if( empty($data['importacao']) ){ unset($data['importacao']); } if( array_key_exists("parent_id", $data) && $data['parent_id'] == null ){ $data['parent_id'] = 0; } if (!empty($data['taxa'])) { $data['taxa'] = String_Refatorar::parseStringToFloat($data['taxa']); } return parent::update($data, $where, $registerLog); } public function desativar($where) { return $this->update([ 'tabela_desativada' => 1, 'data_desativacao' => date('Y-m-d'), 'usuario_desativou' => Yuppie_Auth::getIdentity()->login, 'data_desativou' => date('Y-m-d'), ], $where); } public function ativar($where) { return $this->update([ 'tabela_desativada' => 0, 'data_desativacao' => null ], $where); } /** * Propaga atualização da tabela pai * @param int $parentId * @param int $tabelaId * @return type */ public function atualizarTabelas($parentId, $tabelaId) { if( empty($parentId) || empty($tabelaId) ){ return; } $dbBonus = new Model_DbTable_Bonus(); $dbBonus->update(array( 'tabela_id' => $parentId ), ['id = ?' => $tabelaId]); $dbCallcenterProposta = new Model_DbTable_CallcenterProposta(); $dbCallcenterProposta->update(array( 'tabela_id' => $parentId ), ['tabela_id = ?' => $tabelaId]); $dbComissionamento = new Model_DbTable_Comissionamento(); $dbComissionamento->updateComissionamento(array( 'tabela_id' => $parentId ), ['tabela_id = ?' => $tabelaId]); $dbComissionamentoCorretor = new Model_DbTable_ComissionamentoCorretor(); $dbComissionamentoCorretor->updateComissionamento(array( 'tabela_id' => $parentId ), ['tabela_id = ?' => $tabelaId]); $dbComissionamentoGrupo = new Model_DbTable_ComissionamentoGrupo(); $dbComissionamentoGrupo->updateComissionamento(array( 'tabela_id' => $parentId ), ['tabela_id = ?' => $tabelaId]); $dbContrato = new Model_DbTable_Contrato(); $dbContrato->updateTabela($parentId, $tabelaId); $dbTabelaFator = new Model_DbTable_TabelaFator(); $dbTabelaFator->update(array( 'tabela_id' => $parentId ), ['tabela_id = ?' => $tabelaId]); } 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()->setIntegrityCheck(false) ->from($this->_name, array( "{$this->_name}.$key", $field )) ->joinLeft('tb_convenios', "{$this->_name}.convenio_id = tb_convenios.id", array()) ->joinLeft('tb_bancos', "{$this->_name}.banco_id = tb_bancos.id", array()); 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); } } }else{ $select->where($where); } $select->where("{$this->_name}.excluido <> 1"); $select->order($order ? $order : $field); return $this->getAdapter()->fetchPairs($select); } }
💾 保存文件
← 返回文件管理器