✏️ 正在编辑: Usuario.php
路径:
/srv/systems_dir/yuppiecred-lidernegocios/application/models/DbTable/Usuario.php
提示:
您可以编辑任何文件(包括二进制文件),但请注意不当修改可能导致文件损坏。
<?php class Model_DbTable_Usuario extends Core_DbTable { protected $_primary = 'id'; protected $_name = 'tb_usuarios'; protected static $_viewName = 'vw_usuarios'; protected $_referenceMap = array( 'Grupo' => array( 'columns' => array( 'grupo_id' ), 'refTableClass' => 'Model_DbTable_GrupoUsuario', 'refColumns' => array( 'id' ) ), 'Empresa' => array( 'columns' => array( 'empresa_id' ), 'refTableClass' => 'Model_DbTable_Empresa', 'refColumns' => array( 'id' ) ), 'Corretor' => array( 'columns' => array( 'corretor_id' ), 'refTableClass' => 'Model_DbTable_Corretor', 'refColumns' => array( 'id' ) ) ); public static function getViewName() { return self::$_viewName; } public function delete($where) { $dados = $this->fetchRow($where); if( $dados['login'] == "yuppie" ){ return; } return parent::delete($where); } public function update(array $data, $where) { $dados = $this->fetchRow($where); if( $dados['login'] == "yuppie" ){ $camposLiberados = [ 'empresa_id' => '', 'email' => '', 'assuntos_chamados' => '', 'assuntos_proposta' => '', 'assuntos_simulacao' => '', 'ramal_status' => '', 'secret_gauth' => '', ]; $data = array_intersect_key($data, $camposLiberados); if (empty($data)) { return; } } if( isset($data['senha']) ){ if( (empty($data['senha']) || $data['senha'] == null ) ){ unset($data['senha']); } else { $data['senha'] = md5($data['senha']); } } return parent::update($data, $where); } public function insert(array $data) { if( isset($data['senha']) ){ if( (empty($data['senha']) || $data['senha'] == null ) ){ unset($data['senha']); } else { $data['senha'] = md5($data['senha']); } } if( Yuppie_Auth::getIdentity()->grupo == "Corretor" ){ $data['parent_corretor'] = Yuppie_Auth::getIdentity()->id; } return parent::insert($data); } public function fetchAllView($where = null, $order = null, $count = null, $offset = null) { $select = $this->getAdapter()->select()->from($this->getViewName(), array( '*' )); if( $where != null ){ $select->where($where); } if( $order != null ){ $select->order($order); } $select->limit($count, $offset); return parent::getAdapter()->fetchAll($select); } public function fetchAll($where = null, $order = null, $count = null, $offset = null) { $dbtable = new Model_DbTable_Usuario(); $select = $dbtable->getAdapter() ->select() ->from(['u' => 'tb_usuarios'], ['*']) ->joinInner(['gu' => 'tb_grupos_usuarios'], 'gu.id = u.grupo_id', ['grupo' => 'nome', 'email_grupo' => 'email', 'forma_equipe']) ->joinLeft(['c' => 'tb_corretores'], 'c.id = u.corretor_id', []) ->joinLeft(['r' => 'tb_rotas'], 'r.id = c.rota_id', ['rota' => 'id']) ->where('gu.excluido<>1') ->where('u.excluido<>1'); if( $where != null ) $select->where($where); if( $order != null ) $select->order($order); if( $count != null && $offset != null ) $select->limit($count, $offset); $data = array( 'table' => $dbtable, 'rowClass' => $dbtable->getRowClass(), 'stored' => true, 'data' => $dbtable->getAdapter()->fetchAll($select) ); $rowsetClass = $dbtable->getRowsetClass(); return new $rowsetClass($data); } public function changePassword($dados = null, $where = null) { $result = null; unset($dados['confirmar_senha']); $tipoAcesso = $where->grupo; switch ( $tipoAcesso ) { case "Corretor": //corretor $dados['data_alteracao_senha'] = Zend_Date::now()->get('yyyy-MM-dd'); $dados['mudar_senha'] = null; $corretor = new Model_DbTable_Corretor(); $result = $corretor->update($dados, "id = " . $where->id); break; case "Gerente Regional": //gerente $gerente = new Model_DbTable_Gerente(); $result = $gerente->update($dados, "id = " . $where->id); break; case "Supervisor": //supervisor $gerenteRota = new Model_DbTable_GerenteRota(); $result = $gerenteRota->update($dados, "id = " . $where->id); break; case "Administradores": // Model_Usuario default: $usuario = new Model_DbTable_Usuario(); $result = $usuario->update($dados, "id = " . $where->id); break; } return $result; } public function selectNumeroRamal($coluna, $valor) { $select = $this->select() ->from($this->_name, 'ramal_numero') ->where("$coluna = ?", $valor) ->where('excluido = 0'); return $this->getAdapter()->fetchRow($select)['ramal_numero']; } public function fetchOperadores($where = null, $order = null) { $select = $this->getAdapter()->select()->from(["usuarios" => $this->getViewName()], ['*']); $select->joinInner(['corretores' => 'tb_corretores'], "usuarios.corretor_id = corretores.id and corretores.excluido<>1 and corretores.corretor_desativado<>1", ['corretor' => 'nome']) ->joinLeft(['campanha_op' => 'tb_callcenter_campanha_operadores'], 'usuarios.id = campanha_op.operador_id and campanha_op.excluido<>1', []) ->where("usuarios.excluido<>1") ->group('usuarios.id'); if( $where != null ){ $select->where($where); } if( $order != null ){ $select->order($order); } return $this->getAdapter()->fetchAll($select); } public function selectRamalOperador() { $select = $this->getAdapter()->select() ->from($this->_name, 'ramal_numero') ->where('id = ?', Yuppie_Auth::getIdentity()->id); return $this->getAdapter()->fetchRow($select); } /** * @param int $funcionario * @return array */ public function findJornadaTrabalho(int $funcionario): array { $campos = [ 'TIMEDIFF(hora_fim, hora_inicio) as jornada', 'dias' ]; $select = $this->getAdapter()->select() ->from($this->_name, $campos) ->joinInner(['tb_fornecedores'], 'tb_usuarios.funcionario_id = tb_fornecedores.id', []) ->where("tb_usuarios.funcionario_id = ?", $funcionario) ->where('tb_usuarios.excluido = 0') ; $data = $this->getAdapter()->fetchRow($select); return !empty($data) ? $data : []; } }
💾 保存文件
← 返回文件管理器