✏️ 正在编辑: PosvendaPerguntaController.php
路径:
/srv/systems_dir/oakberry/application/controllers/PosvendaPerguntaController.php
提示:
您可以编辑任何文件(包括二进制文件),但请注意不当修改可能导致文件损坏。
<?php class PosvendaPerguntaController extends Yuppie_Controller_Crud { protected $title = 'Pesquisas'; protected $titleIcon = 'glyphicon glyphicon-question-sign'; protected $sideMenu = null; protected $_url = null; public function init() { $this->_url = "https://" . $_SERVER['SERVER_NAME'] . $this->getRequest()->getBaseUrl(); $this->formFiltro = 'Form_Filtro_PosvendaPergunta'; $this->formSave = 'Form_PosvendaPergunta'; parent::init(); } public function saveAction() { $request = $this->getRequest(); $id = (int) $request->getParam('id'); $form = new $this->formSave; $formOpcao = new Form_PosvendaAdicionarOpcao(); if ($request->getPost('back')) { $this->_helper->redirector('listar', $request->getControllerName(), $request->getModuleName(), ['page' => $this->_getParam('page', 1)]); } if ($request->getPost('new')) { $this->_helper->redirector('save'); } $alerts = $this->getHelper('Alerts'); $model = null; if ($id) { $model = $this->dbtable->findById($id); if (!$model) { $alerts->addWarning('Id inválido.'); $this->_helper->redirector('listar'); } $form->populate($model->toArray()); $formOpcao->populate(array('contrato_id' => $id)); $this->view->tabs = [ 'dados_pergunta' => 'Identificação', 'opcoes' => 'Opções', ]; } if ($request->isPost()) { if ($form->isValid($request->getPost())) { try { if (!$model) { $model = $this->dbtable->createRow(); } $model->setFromArray($form->getValues()); $id = $model->save(); if ($id) { $alerts->addSuccess('Dados salvos com sucesso.'); $this->_helper->redirector('save', $request->getControllerName(), $request->getModuleName(), ['id' => $id]); } else { $alerts->addDanger('Nenhum registro foi alterado.'); } } catch (Exception $e) { //$alerts->addDanger($e->getMessage()); $this->_helper->redirector('listar', null, null, ['id' => $id, 'tab' => 1]); } } else { $alerts->addDanger('Dados inválidos ou faltando.'); } } $this->view->formOpcao = $formOpcao; $this->view->form = $form; $this->view->model = $model; $this->view->tab = $this->_getParam('tab', 0); } public function adicionarOpcaoAction() { $request = $this->getRequest(); $form = new Form_PosvendaAdicionarOpcao(); $alerts = $this->getHelper('Alerts'); if ($request->isPost() && $form->isValid($request->getPost())) { $opcao = Model_Container::getPosvendaOpcao(); $model = $opcao->createRow(); $model->setFromArray($form->getValues()); $id = $model->save(); if ($id) { $alerts->addSuccess('Dados salvos com sucesso.'); } else { $alerts->addDanger('Nenhum registro foi alterado.'); } } $this->_helper->redirector('save', null, null, array( 'id' => $this->getRequest()->getParam('pergunta_id'), 'tab' => 1 )); } public function deleteOpcaoAction() { $id = (int) $this->getRequest()->getParam('id'); if( $id > 0 ){ $opcao = Model_Container::getPosvendaOpcao(); $opcao->delete("id = " . $id); } $this->_helper->redirector('save', null, null, array( 'id' => $this->getRequest()->getParam('pergunta_id'), 'tab' => 1 )); } public function listarLeadsAction() { $request = $this->getRequest(); $perguntaId = $request->getParam('pergunta_id'); $alerts = $this->getHelper('Alerts'); if (empty($perguntaId)) { $alerts->addDanger("Pesquisa não identificada."); $this->_helper->redirector('index'); } $form = new Form_Filtro_EnviarPesquisa(); $paginator = $form->search(); $this->view->pergunta_id = $perguntaId; $this->view->paginator = $paginator; $this->view->form = $form; } public function enviarPerguntaAction() { $request = $this->getRequest(); $perguntaId = (int) $request->getParam('pergunta_id'); $alerts = $this->getHelper('Alerts'); $empresa = Model_Container::getEmpresa()->findById(Yuppie_Auth::getIdentity()->empresa_id); $params = json_encode($request->getParams() + ['empresa_id' => $empresa->id]); $secret = md5(Yuppie_Core_Secret::SECRETS['oakberry']); if (empty($perguntaId)) { $alerts->addDanger("Pesquisa não identificada!"); $this->_redirect('/posvenda-pergunta/listar'); } try { $whatsapp = \Yuppie_Service_Whatsapp_Factory::load($empresa); } catch (\Throwable $e) { $whatsapp = null; Yuppie_Log::write($e->getMessage() . $e->getTraceAsString(), $this); $alerts->addDanger("Sistema não possui whatsapp configurado"); $this->_redirect('/posvenda-pergunta/listar'); } $pergunta = Model_Container::getPosvendaPergunta()->findById($perguntaId); if (!$pergunta) { $alerts->addDanger("Pesquisa não localizada!"); $this->_redirect('/posvenda-pergunta/listar'); } $pergunta->status_envio = "PROCESSANDO"; $pergunta->save(); $curlString = "curl --location '{$this->_url}/automacoes/enviar-pergunta?secret={$secret}' " . "--header 'Content-Type: application/json' " . "--data '{$params}' > /dev/null 2>&1 &"; shell_exec($curlString); Yuppie_Log::write($curlString); $alerts->addInfo("Envio em processamento"); $this->_redirect('/posvenda-pergunta/listar'); } public function respostasAction() { $request = $this->getRequest(); $form = new Form_Filtro_PosvendaResposta(); $this->view->form = $form; } public function showQuestChartAction() { $perguntaId = $this->getRequest()->getParam('pergunta_id'); if (empty($perguntaId)) { $this->_helper->json(['status' => false, 'message' => 'Nenhuma pergunta informada.']); } $this->view->quests = Model_Container::getPosvendaPergunta()->fetchChartQuest(false, $perguntaId); $this->_helper->json(['status' => true, 'html' => $this->view->render('posvenda-pergunta/show-quest-chart.phtml')]); } }
💾 保存文件
← 返回文件管理器