✏️ 正在编辑: CampanhaController.php
路径:
/srv/systems_dir/yuppiecred-lidernegocios/application/controllers/CampanhaController.php
提示:
您可以编辑任何文件(包括二进制文件),但请注意不当修改可能导致文件损坏。
<?php class CampanhaController extends Zend_Controller_Action { public function init() { $request = $this->getRequest()->getParam('tab'); $this->view->tab = isset($request) ? $request : 0; } public function indexAction() { $form = new Form_Filtro_Campanha(); $dbtable = new Model_DbTable_Campanha(); $select = $dbtable->fetchAll(null, 'data_inicial ASC'); $paginator = new Zend_Paginator(new Zend_Paginator_Adapter_Array($select->toArray())); $paginator->setCurrentPageNumber($this->_getParam('page', 1)); $this->view->paginator = $paginator; $this->view->form = $form; } public function saveAction() { $request = $this->getRequest(); $id = (int) $request->getParam('id'); $form = new Form_Campanha(); if( $request->isPost() ){ if( $form->isValid($request->getPost()) ){ $campanha = new Model_Campanha($request->getPost()); try { $id = $campanha->salvar($campanha); $this->_helper->flashMessenger( array('success' => 'Dados salvos com sucesso.')); } catch ( Zend_Exception $e ) { $this->_helper->flashMessenger($e->getMessage()); } } } if( $id > 0 ){ $campanha = new Model_Campanha(); $dados = $campanha->exibir($id); $dados['data_inicial'] = $dados['data_inicial'] != '0000-00-00' ? date('d/m/Y', strtotime($dados['data_inicial'])) : ""; $dados['data_final'] = $dados['data_final'] != '0000-00-00' ? date('d/m/Y', strtotime($dados['data_final'])) : ""; $dados['valor_ponto'] = number_format($dados['valor_ponto'], 2, ',', '.'); $dados['producao_media'] = number_format($dados['producao_media'], 2, ',', '.'); $form->populate($dados->toArray()); $form_convenio = new Form_CampanhaConvenio(); $this->view->form_convenio = $form_convenio; $convenio = new Model_CampanhaConvenio(); $this->view->convenios = $convenio->listar('campanha_id = ' . $id); $form_tabela = new Form_CampanhaTabela(); $this->view->form_tabela = $form_tabela; $tabela = new Model_CampanhaTabela(); $this->view->tabelas = $tabela->listar('campanha_id = ' . $id); $form_status = new Form_CampanhaStatus(); $this->view->form_status = $form_status; $status = new Model_CampanhaStatus(); $this->view->status = $status->listar('campanha_id = ' . $id); $formValores = new Form_CampanhaFaixaValores(); $this->view->faixaValores = $formValores; $faixaValores = new Model_CampanhaFaixaValor(); $this->view->valores = $faixaValores->listar('campanha_id = ' . $id); $formRegras = new Form_CampanhaRegras(); $formRegras->populate($dados->toArray()); $this->view->regras = $formRegras; $this->view->dados = $dados->toArray(); } $this->view->form = $form; } public function deleteAction() { $request = $this->getRequest(); $id = (int) $request->getParam('id'); if( $id > 0 ){ $campanha = new Model_Campanha(); $campanha->excluir($id); } $this->_redirect('/campanha'); } public function resgateAction() { $request = $this->getRequest(); $form = new Form_ResgatePontos(); if( $request->isPost() && $form->isValid($request->getPost()) ){ $form->populate($request->getPost()); $resgate = new Model_ResgatePonto($form->getValues()); $campanha = new Model_Corretor(); $pontuacaoCorretor = $campanha->getPontuacaoGeral(array( 'corretor_id' => $request->getPost('corretor_id'), 'campanha_id' => $request->getPost('campanha_id') )); if ((string) $resgate->getValorResgate() > (string) $pontuacaoCorretor) { $this->_helper->flashMessenger(array('alert' => "Atenção! O valor solicitado ultrapassa o saldo do corretor.")); } else { $result = $resgate->salvar($resgate); if( $result > 0 ){ $this->_helper->flashMessenger(array('success' => "Resgate efetuado com sucesso.")); }else{ $this->_helper->flashMessenger(array('alert' => "Não foi possível registrar o resgate.")); } } } $this->view->form = $form; } public function resgatesAction() { $request = $this->getRequest(); $form = new Form_Filtro_Resgate(); if( $request->isPost() ){ $fields = $request->getPost(); $form->populate($fields); $model = new Model_ResgatePonto(); $this->view->resgates = $model->listar($fields); } $this->view->form = $form; } public function deleteResgateAction() { $request = $this->getRequest(); $id = (int) $request->getParam('id'); if( $id > 0 ){ $resgate = new Model_ResgatePonto(); $resgate->excluir($id); } $this->_helper->redirector('resgates'); } public function addConvenioAction() { $request = $this->getRequest(); $params = $request->getParams(); $form = new Form_CampanhaConvenio(); if( $request->isPost() && $form->isValid($params) ){ $convenios = $params['convenio_id']; foreach ($convenios as $convenioId){ $data = array( 'convenio_id' => $convenioId, 'campanha_id' => $params['campanha_id'] ); $convenio = new Model_CampanhaConvenio($data); $convenio->salvar($convenio); } } $this->_helper->redirector('save', null, null, array( 'id' => $request->getParam('campanha_id'), 'tab' => 1 )); } public function deleteConvenioAction() { $request = $this->getRequest(); $id = (int) $request->getParam('id'); if( $id > 0 ){ $convenio = new Model_CampanhaConvenio(); $convenio->excluir($id); } $this->_helper->redirector('save', null, null, array( 'id' => $request->getParam('campanha_id'), 'tab' => 1 )); } public function addTabelaAction() { $request = $this->getRequest(); $params = $request->getParams(); if( $request->isPost()){ $tabelas = $params['tabela_id']; foreach ($tabelas as $tabelaId){ $data = array( 'tabela_id' => $tabelaId, 'campanha_id' => $params['campanha_id'] ); $tabela = new Model_CampanhaTabela($data); $tabela->salvar($tabela); } } $this->_helper->redirector('save', null, null, array( 'id' => $request->getParam('campanha_id'), 'tab' => 2 )); } public function deleteTabelaAction() { $request = $this->getRequest(); $id = (int) $request->getParam('id'); if( $id > 0 ){ $tabela = new Model_CampanhaTabela(); $tabela->excluir($id); } $this->_helper->redirector('save', null, null, array( 'id' => $request->getParam('campanha_id'), 'tab' => 2 )); } public function addStatusAction() { $request = $this->getRequest(); if( $request->isPost() ){ $status = new Model_CampanhaStatus($request->getPost()); $status->salvar($status); } $this->_helper->redirector('save', null, null, array( 'id' => $request->getParam('campanha_id'), 'tab' => 3 )); } public function deleteStatusAction() { $request = $this->getRequest(); $id = (int) $request->getParam('id'); if( $id > 0 ){ $status = new Model_CampanhaStatus(); $status->excluir($id); } $this->_helper->redirector('save', null, null, array( 'id' => $request->getParam('campanha_id'), 'tab' => 3 )); } public function auditoriaAction() { $request = $this->getRequest(); $form = new Form_Filtro_CampanhaAuditoria(); if($request->isPost() && $form->isValid($request->getPost())){ $fields = $request->getPost(); $form->populate($fields); $campanha = new Model_Campanha(); $relatorio = $campanha->auditoriaCampanha($fields); $this->view->relatorio = $relatorio; } $this->view->form = $form; } public function addFaixaValorAction() { $request = $this->getRequest(); $params = $request->getParams(); if( $request->isPost()){ $params['campanha_id'] = $params['id']; unset($params['id']); $faixaValor = new Model_CampanhaFaixaValor($params); $faixaValor->salvar($faixaValor); } $this->_helper->redirector('save', null, null, array( 'id' => $request->getParam('id') )); } public function deleteFaixaValorAction() { $request = $this->getRequest(); $id = (int) $request->getParam('id'); if( $id > 0 ){ $faixa = new Model_CampanhaFaixaValor(); $faixa->excluir($id); } $this->_helper->redirector('save', null, null, array( 'id' => $request->getParam('campanha_id'), 'tab' => 3 )); } public function atualizarRegrasAction() { $request = $this->getRequest(); $params = $request->getParams(); if( $request->isPost()){ $params['id'] = $params['campanha_id']; unset($params['campanha_id']); try{ Upload::save((new Zend_File_Transfer_Adapter_Http()), $params, 'campanhas'); } catch (Exception $ex) { $this->_helper->flashMessenger(['error' => $ex->getMessage()]); $this->_helper->redirector('save', null, null, ['id' => $params['id']]); } $dbtable = new Model_DbTable_Campanha(); $result = $dbtable->update([ 'regras' => $params['regras'], 'anexo' => $params['arquivo'] ], "id = " . $params['id']); if ($result) { $this->_helper->flashMessenger(['success' => "Dados atualizados com sucesso."]); } } $this->_helper->redirector('save', null, null, ['id' => $request->getParam('campanha_id')]); } public function viewAction() { $anexoUrl = $this->getRequest()->getParam('anexo_url'); Upload::download($anexoUrl, 'campanhas'); } }
💾 保存文件
← 返回文件管理器