✏️ 正在编辑: CallcenterCampanha.php
路径:
/srv/systems_dir/yuppiecred/application/models/DbTable/CallcenterCampanha.php
提示:
您可以编辑任何文件(包括二进制文件),但请注意不当修改可能导致文件损坏。
<?php use Model_DbTable_CallcenterBase as Base; use Modules\Callcenter\Dto\CallcenterCampanhaDto; use Modules\Callcenter\Model\DbTable\{AtendimentosResetadosTable, ReprocessamentoTable}; class Model_DbTable_CallcenterCampanha extends Core_DbTable { protected $_name = 'tb_callcenter_campanhas'; public function loadCsvToDatabase($fileName) { $tableTmp = "tmp_import_callcenter"; $this->closeConnection(); $db = new Zend_Db_Table(); $db->getAdapter()->query("TRUNCATE {$tableTmp}"); $profiler = $db->getAdapter()->getProfiler(); $profiler->setEnabled(true); //Para conexao com outro servidor deve-se passar o parametro LOCAL $queryCreate = "SET AUTOCOMMIT=0; TRUNCATE {$tableTmp}; LOAD DATA LOCAL INFILE '" . $fileName . "'" . " INTO TABLE {$tableTmp}" . " CHARACTER SET utf8" . " FIELDS TERMINATED BY ';'" . " LINES TERMINATED BY '\n'" . " IGNORE 1 LINES" . ";" . " COMMIT; SET AUTOCOMMIT=1;"; $db->getAdapter()->query($queryCreate); unlink($fileName); $this->closeConnection(); $db = new Zend_Db_Table(); return $db->getAdapter()->fetchAll("SELECT * FROM {$tableTmp}"); } public function lockTmpTable() { $db = new Zend_Db_Table(); return $db->getAdapter()->query("LOCK TABLE tab_temp2 READ;"); } public function unLockTmpTable() { $db = new Zend_Db_Table(); return $db->getAdapter()->query("UNLOCK TABLES"); } public function update(array $data, $where, $registerLog = true) { $data = $this->_naoModificar($where, $data); return parent::update($data, $where, $registerLog); } public function delete($where) { $this->_naoModificar($where); return parent::delete($where); } protected function _naoModificar($where, ?array $data = null) { $campanha = $this->fetchRow($where); if( $campanha && ($campanha->nome == "IMPORTACAO CONSULTA")){ throw new Core_Exception("Este campanha não pode ser modificada."); } if (isset($data['nome']) && (stristr($campanha->nome, "- OPORTUNIDADES DE NEGÓCIOS") || stristr($campanha->nome, "CAMPANHA SIMULACAO ABERTA"))) { unset($data['nome']); } return $data; } public function insert(array $data) { $data['nome'] = trim($data['nome']); if( $data['nome'] == "IMPORTACAO CONSULTA" ){ $this->_naoModificar("nome LIKE '{$data['nome']}'"); } return parent::insert($data); } public function selectCampanhaInfo(int $campanhaId) { $select = $this->getAdapter()->select() ->from($this->_name) ->where('id = ?', $campanhaId); return $this->getAdapter()->fetchRow($select); } public function selectCodigoDiscadorEmCampanha($params) { if (empty($params['codigo'])) { return; } $select = $this->select() ->from($this->_name, 'codigo') ->where("$this->_name.codigo = ?", $params['codigo']) ->where("$this->_name.id <> ?", $params['id']) ->where("$this->_name.excluido = 0"); return $this->getAdapter()->fetchRow($select)['codigo']; } /** * @param int $campanha * @return mixed */ public function selectCampanhaAtendimentos(int $campanha): CallcenterCampanhaDto { $base = new Base(); $baseSql = $base->sqlCountBase($campanha); $atendidosSql = $base->sqlCountBase($campanha, true); $reprocessamentoSql = (new AtendimentosResetadosTable())->sqlCountCampanha($campanha); $sql = $this->getAdapter() ->select() ->from(['c' => $this->_name]) ->joinLeft(['base' => $baseSql], 'base.campanha_id = c.id', ['clientes']) ->joinLeft(['atendidos' => $atendidosSql], 'atendidos.campanha_id = c.id', ['clientes_atendidos']) ->joinLeft(['reproc' => $reprocessamentoSql], 'reproc.campanha_id = c.id', ['reprocessamentos_realizados']) ->where('c.id = ?', $campanha) ->where('c.excluido <> ?', 1); return $this->fetchDto($sql, CallcenterCampanhaDto::class); } /** * @param string $campanha * @return array|mixed|null */ public function findByNome(string $campanha): ?array { $select = $this->select() ->from($this->_name) ->where("nome = ?", $campanha) ->where("excluido = 0"); return $this->fetchOrNull($select); } public function getOrCreate(string $nomeCampanha) { $dados = $this->fetchRow("nome LIKE '{$nomeCampanha}'"); if ($dados) { return $dados->id; } return $this->insert([ 'nome' => $nomeCampanha, 'codigo' => '0', 'situacao' => 'ATIVA', ]); } public function getCampanhaExportar($campanhaId) { $columns = [ //TABELA CAMPANHA 'campanha_nome' => 'campanha.nome', //TABELA BASE 'cliente' => 'base.nome', 'rg' => 'base.rg', 'cpf' => 'base.cpf', 'data_nascimento' => 'DATE_FORMAT(base.data_nascimento, "%d/%m/%Y")', 'sexo' => 'base.sexo', 'responsavel' => 'base.nome_responsavel', 'cpf_responsavel' => 'base.cpf_responsavel', 'cep' => 'base.cep', 'endereco' => 'base.endereco', 'numero' => 'base.numero', 'bairro' => 'base.bairro', 'cidade' => 'base.cidade', 'estado' => 'base.uf', 'complemento' => 'base.complemento', 'obs_endereco' => 'base.obs_endereco', 'email' => 'base.email', 'mae' => 'base.nome_mae', 'pai' => 'base.nome_pai', 'saldo' => 'base.valor_saque', //TABELA BENEFICIOS 'beneficio' => 'beneficios.beneficio', 'margem_livre' => 'beneficios.margem_livre', 'margem_cartao' => 'beneficios.margem_cartao', 'margem_rcc' => 'beneficios.margem_rcc', 'renda' => 'beneficios.mr', 'situacao' => 'beneficios.situacao', 'banco' => 'beneficios.banco_pagto', 'agencia' => 'beneficios.agencia_pagto', 'conta' => 'beneficios.conta_pagto', 'orgao' => 'beneficios.orgao_pagador', 'tipo' => 'beneficios.tipo_pagto', 'especie' => 'beneficios.especie', 'data_inclusao' => 'DATE_FORMAT(beneficios.dib, "%d/%m/%Y")', //TABELA EMPRESTIMOS 'banco_emprestimo' => 'emprestimos.banco', 'contrato' => 'emprestimos.numero_contrato', 'taxa' => 'emprestimos.taxa', 'valor_emprestimo' => 'emprestimos.valor_emprestimo', 'valor_parcela' => 'emprestimos.valor_parcela', 'parcelas' => 'emprestimos.qtd_parcelas', 'pagas' => 'emprestimos.parcelas_pagas', 'abertas' => 'emprestimos.parcelas_abertas', 'quitacao' => 'emprestimos.quitacao', 'inicio_contrato' => 'DATE_FORMAT(emprestimos.inicio_contrato, "%d/%m/%Y")', 'termino_contrato' => 'DATE_FORMAT(emprestimos.termino_contrato, "%d/%m/%Y")', //TABELA TELEFONES 'telefones' => 'GROUP_CONCAT(distinct telefones.fone SEPARATOR " - ")', 'origem' => 'telefones.origem', 'whatsapp' => 'IF(telefones.whatsapp = 1, "Sim", "Nao")', 'nao_perturbe' => 'IF(telefones.nao_perturbe = 1, "Sim", "Nao")' ]; $select = $this->getAdapter()->select()->from(['campanha' => 'tb_callcenter_campanhas'], $columns) ->joinInner(['base' => 'tb_callcenter_base'], 'base.campanha_id = campanha.id', []) ->joinLeft(['beneficios' => 'tb_callcenter_beneficios'], 'beneficios.base_cliente_id = base.id OR beneficios.cpf_cliente = base.cpf', []) ->joinLeft(['emprestimos' => 'tb_callcenter_emprestimos_clientes'], 'emprestimos.beneficio = beneficios.beneficio AND (emprestimos.base_cliente_id = base.id OR emprestimos.cpf_cliente = base.cpf)', []) ->joinLeft(['telefones' => 'tb_callcenter_telefones'], 'telefones.cliente_id = base.id AND telefones.excluido = 0', []) ->where("campanha.id = {$campanhaId}") ->where('campanha.excluido<>1') ->order("base.nome") ->group(["base.id", "beneficios.id", "emprestimos.id"]); return $this->getAdapter()->fetchAll($select); } }
💾 保存文件
← 返回文件管理器