✏️ 正在编辑: CorretorMeta.php
路径:
/srv/systems_dir/yuppiecred-lidernegocios/application/models/CorretorMeta.php
提示:
您可以编辑任何文件(包括二进制文件),但请注意不当修改可能导致文件损坏。
<?php class Model_CorretorMeta { private $_id; private $_corretorId; private $_statusMetaId; private $_protocoloFisico; private $_dataInicial; private $_dataFinal; private $_meta; private $_bancoId; private $_producao_final; private $_producao_inicial; private $_producao_comissao; private $_incidirSobre; public function getId() { return $this->_id; } public function setId($id) { $this->_id = $id; } public function getCorretorId() { return $this->_corretorId; } public function getStatusMetaId() { return $this->_statusMetaId; } public function getProtocoloFisico() { return $this->_protocoloFisico; } public function setCorretorId($corretorId) { $this->_corretorId = $corretorId; } public function setStatusMetaId($statusMetaId) { $this->_statusMetaId = $statusMetaId; } public function setProtocoloFisico($protocoloFisico) { $this->_protocoloFisico = $protocoloFisico; } public function getProducaoFinal() { return $this->_producao_final; } public function setProducaoFinal($producao_final) { $this->_producao_final = str_replace(array( '.', ',' ), array( '', '.' ), $producao_final); } public function getProducaoInicial() { return $this->_producao_inicial; } public function setProducaoInicial($producao_inicial) { $this->_producao_inicial = str_replace(array( '.', ',' ), array( '', '.' ), $producao_inicial); } public function getProducaoComissao() { return $this->_producao_comissao; } public function setProducaoComissao($producao_comissao) { $this->_producao_comissao = str_replace(array( '.', ',' ), array( '', '.' ), $producao_comissao); } public function getMeta() { return $this->_meta; } public function setMeta($meta) { $this->_meta = str_replace(array( '.', ',' ), array( '', '.' ), $meta); } public function getDataInicial() { return $this->_dataInicial; } public function setDataInicial($dataInicial) { if( !empty($dataInicial) ){ try { $data = new Zend_Date($dataInicial, Zend_Date::DATES, 'pt'); $dataInicial = $data->toString('yyyy-MM-dd'); } catch ( Zend_Date_Exception $e ) { echo $e->getMessage(); $dataInicial = null; } } else { $dataInicial = null; } $this->_dataInicial = $dataInicial; } public function getDataFinal() { return $this->_dataFinal; } public function setDataFinal($dataFinal) { if( !empty($dataFinal) ){ try { $data = new Zend_Date($dataFinal, Zend_Date::DATES, 'pt'); $dataFinal = $data->toString('yyyy-MM-dd'); } catch ( Zend_Date_Exception $e ) { echo $e->getMessage(); $dataFinal = null; } } else { $dataFinal = null; } $this->_dataFinal = $dataFinal; } public function getBancoId() { return $this->_bancoId; } public function setBancoId($bancoId) { $this->_bancoId = $bancoId; } public function getIncidirSobre() { return $this->_incidirSobre; } public function setIncidirSobre($incidirSobre) { $this->_incidirSobre = $incidirSobre; } public function __construct($options = null) { if( is_array($options) ){ $this->setOptions($options); } } 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_CorretorMeta(); $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 registro passado por parâmetro * @param Model_CorretorMeta $corretorMeta */ public function salvar(Model_CorretorMeta $corretorMeta) { $dbtable = new Model_DbTable_CorretorMeta(); if( $corretorMeta->getId() > 0 ){ $dbtable->update($corretorMeta->_toArray(), 'id = ' . $corretorMeta->getId()); return $corretorMeta->getId(); } else { return $dbtable->insert($corretorMeta->_toArray()); } } /** * Exclui o registro 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_CorretorMeta(); return $dbtable->delete("id = {$id}"); } return null; } /** * Retorna uma lista * @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_CorretorMeta(); return $dbtable->fetchAll($where, $order, $count, $offset); } public function fetchUltimaMeta($corretorId, $rota = false) { $dbtable = new Model_DbTable_CorretorMeta(); $where = "corretor_id = {$corretorId}"; return $dbtable->fetchRow($where, 'data_final DESC'); } /** * 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_GerenteMeta(); return $dbtable->fetchRow("id = {$id}"); } public function stats($id, $order = null) { $sql = "SELECT gm.*, b.nome as banco, (SELECT SUM(valor_liquido) FROM tb_contratos as con LEFT JOIN tb_corretores as c ON c.id = con.corretor_id LEFT JOIN tb_rotas as r ON r.id = c.rota_id WHERE c.id = gm.corretor_id AND con.banco_id = gm.banco_id AND con.data_emissao >= gm.data_inicial AND con.data_emissao <= gm.data_final AND con.excluido<>1) as contratos FROM tb_corretores_metas gm LEFT JOIN tb_bancos as b ON b.id = gm.banco_id WHERE gm.excluido<>1 "; $sql .= " AND gm.corretor_id = {$id}"; if( $order ){ $sql .= " ORDER BY {$order}"; } $dbtable = new Model_DbTable_CorretorMeta(); $result = $dbtable->getAdapter()->fetchAll($sql); return $result; } public function getProducao($fields = array(), $order = null) { $dbtable = new Model_DbTable_CorretorMeta(); $selectMeta = $dbtable->getAdapter()->select()->from(array( 'corretor_meta' => 'tb_corretores_metas' ), array( 'total_meta' => 'SUM(corretor_meta.meta)', 'banco_id', 'id', 'corretor_id', 'data_inicial', 'data_final', 'protocolo_fisico' )) ->joinLeft(array( 'bancos' => 'tb_bancos' ), 'bancos.id = corretor_meta.banco_id', array( 'banco' => 'bancos.nome', 'teto_producao' )) ->where('corretor_meta.excluido <> 1') ->group('corretor_meta.id') ->order($order); if( isset($fields['corretor_id']) && $fields['corretor_id'] > 0 ){ $selectMeta->where('corretor_id = ' . $fields['corretor_id']); } return $dbtable->getAdapter()->fetchAll($selectMeta); } public function findStatusProposta($fields = array()) { $dbtable = new Model_DbTable_CorretorMeta(); $select = $dbtable->getAdapter()->select()->from(array( 'corretor_meta' => 'tb_corretores_metas' ), array()) ->joinInner(array( 'corretor_meta_status' => 'tb_corretores_metas_status' ), 'corretor_meta_status.corretor_meta_id = corretor_meta.id', array( 'status_proposta' )) ->joinLeft(array( 'status' => 'tb_tipos' ), 'corretor_meta_status.status_proposta = status.id', array()) ->joinLeft(array( 'bancos' => 'tb_bancos' ), 'bancos.id = corretor_meta.banco_id', array()) ->where('corretor_meta.excluido<>1 AND corretor_meta_status.excluido <> 1') ->group('corretor_meta_status.status_proposta'); if( isset($fields['corretor_id']) && $fields['corretor_id'] > 0 ){ $select->where('corretor_id = ' . $fields['corretor_id']); } return $dbtable->getAdapter()->fetchCol($select); } public function fetchMetas($where = null) { $dbtable = new Model_DbTable_CorretorMeta(); return $dbtable->fetchAll($where, 'data_final DESC'); } public function getMetaProducao($params) { $dbtable = new Model_DbTable_CorretorMeta(); $select = $dbtable->getAdapter()->select()->from(array( 'corretor_meta' => 'tb_corretores_metas' ), array('corretor_id', 'banco_id', 'protocolo_fisico', 'producao_inicial', 'producao_final', 'producao_comissao', 'incidir_sobre' )) ->joinLeft(array( 'tb_corretores_metas_status' ), 'tb_corretores_metas_status.corretor_meta_id = corretor_meta.id', array('status_proposta')); if( !empty($params['corretor_id']) ){ $select->where('corretor_meta.corretor_id IN (?)', $params['corretor_id']); } if( !empty($params['banco_id']) ){ $select->where('corretor_meta.banco_id = ?', $params['banco_id']); } $select->where('corretor_meta.excluido <> 1'); $select->where('tb_corretores_metas_status.excluido <> 1'); return $dbtable->getAdapter()->fetchAll($select); } public function verificarDuplicidadeFaixa($data) { $dbtable = new Model_DbTable_CorretorMeta(); $data['producao_inicial'] = str_replace(array( '.', ',' ), array( '', '.' ), $data['producao_inicial']); $data['producao_final'] = str_replace(array( '.', ',' ), array( '', '.' ), $data['producao_final']); $select = $dbtable->getAdapter()->select()->from(array( 'corretor_meta' => 'tb_corretores_metas' )) ->where('excluido <> 1') ->where("producao_inicial >= '" . $data['producao_inicial'] . "' AND " . "producao_final >= '" . $data['producao_inicial'] . "' OR " . "producao_inicial >= '" . $data['producao_final'] . "' AND " . "producao_final >= '" . $data['producao_final'] . "'" ); if( isset($data['banco_id']) && !empty($data['banco_id']) ){ $select->where("banco_id = ?", $data['banco_id']); } if( isset($data['corretor_id']) && !empty($data['corretor_id']) ){ $select->where("corretor_id = ?", $data['corretor_id']); } return $dbtable->getAdapter()->fetchRow($select); } public function cadastrarProjecao(array $dados) { $bancos = isset($dados['banco_id']) ? $dados['banco_id'] : null; $bancoId = null; $result = null; if( $bancos ){ foreach ( $bancos as $bancoId ) { $result = $this->_prepareProjecaoESaveProposta($dados, $bancoId); } } else { $result = $this->_prepareProjecaoESaveProposta($dados, $bancoId); } return $result; } public function _prepareProjecaoESaveProposta($dados, $bancoId) { $statusMeta = new Model_DbTable_CorretorMetaStatus(); $contConflitos = 0; $contSuccess = 0; $data['banco_id'] = !empty($bancoId) ? $bancoId : null; $data['protocolo_fisico'] = isset($dados['protocolo_fisico']) ? $dados['protocolo_fisico'] : 0; $data['corretor_id'] = $dados['corretor_id']; $data['incidir_sobre'] = $dados['incidir_sobre']; for ( $i = 0; $i < sizeOf($dados['producao_inicial']); $i++ ) { $data['producao_inicial'] = $dados['producao_inicial'][$i]; $data['producao_final'] = $dados['producao_final'][$i]; $data['producao_comissao'] = $dados['producao_comissao'][$i]; $this->setOptions($data); $duplicado = $this->verificarDuplicidadeFaixa($data); if (!$duplicado) { $metaId = $this->salvar($this); if( isset($dados['status_proposta']) && !empty($dados['status_proposta']) ){ foreach ( $dados['status_proposta'] as $statusPropostaId ) { $data = array( 'corretor_meta_id' => $metaId, 'status_proposta' => $statusPropostaId ); $statusMeta->insert($data); } } $contSuccess++; } else { $contConflitos++; } } return array( 'count_success' => $contSuccess, 'count_conflitos' => $contConflitos ); } }
💾 保存文件
← 返回文件管理器