✏️ 正在编辑: Cliente.php
路径:
/srv/systems_dir/yuppiecred/application/models/DbTable/Cliente.php
提示:
您可以编辑任何文件(包括二进制文件),但请注意不当修改可能导致文件损坏。
<?php class Model_DbTable_Cliente extends Core_DbTable { protected $_name = 'tb_clientes'; protected static $_viewName = 'vw_clientes'; protected $_dependentTables = array( 'Model_DbTable_Contrato' ); protected $_referenceMap = array( 'Empresa' => array( 'columns' => array( 'empresa_id' ), 'refTableClass' => 'Model_DbTable_Empresa', 'refColumns' => array( 'id' ) ) ); public static function getViewName() { return self::$_viewName; } /** * Verifica se o cpf já está cadastrado * @param string $cpf * @return boolean */ public function existeCpf($cpf) { if ($this->fetchRow("cpf = '" . String_Refatorar::formatarCpf($cpf) . "'") != null) { return true; } return false; } public function insert(array $data) { if (empty($data['nome']) || empty($data['cpf'])) { return null; } //verifica se o cpf está sendo passado if (!empty($data['cpf'])) { //verifica se o cpf já está cadastrado if ($this->existeCpf($data['cpf'])) { return null; } } return parent::insert($data); } public function update(array $data, $where) { if (!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']) { return null; } } } return parent::update($data, $where); } 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-clientes-filiais')) { $and = " AND empresa_id = " . Yuppie_Auth::getIdentity()->empresa_id; } if (($where instanceof Zend_Db_Table_Select)) { $strWhere = "tipo_registro = 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 tipo_registro = 1 " . $and; } else { $where = "tipo_registro = 1 " . $and; } return parent::fetchAll($where, $order, $count, $offset); } public function fetchRow($where = null, $order = null, $offset = null) { if (($where instanceof Zend_Db_Table_Select)) { $strWhere = "tipo_registro = 1"; 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 = 1"; } elseif ($where != null) { $where = $where . " AND tipo_registro = 1"; } else { $where = "tipo_registro = 1"; } return parent::fetchRow($where, $order, $offset); } public function fetchAllClientesProspectos($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-clientes-filiais') ){ $and = " AND empresa_id = " . Yuppie_Auth::getIdentity()->empresa_id; } 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 = "excluido<>1 AND (DATE_FORMAT(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(data_nascimento, '%d%m') = '" . $data->get('ddMM') . "'"; $data->addDay(1); // domingo $where .= " OR DATE_FORMAT(data_nascimento, '%d%m') = '" . $data->get('ddMM') . "'"; } $where .= ")"; $order = ["DATE_FORMAT(data_nascimento, '%m%d')", "nome"]; $select = $this->getAdapter()->select()->from($this->_name, array('data_nascimento', 'uf', 'nome', 'id')); $select->where($where); $select->order($order); return $this->getAdapter()->fetchAll($select); } }
💾 保存文件
← 返回文件管理器