✏️ 正在编辑: LeadController.php
路径:
/srv/systems_dir/oakberry/application/controllers/LeadController.php
提示:
您可以编辑任何文件(包括二进制文件),但请注意不当修改可能导致文件损坏。
<?php class LeadController extends Yuppie_Controller_Crud { protected $title = 'Clientes'; protected $titleIcon = 'glyphicon-reg glyphicon-reg-edit'; protected $sideMenu = null; public function init() { $this->formFiltro = 'Form_Filtro_Lead'; $this->formSave = 'Form_Lead'; parent::init(); } public function saveAction() { $request = $this->getRequest(); $id = (int) $request->getParam('id'); $form = new $this->formSave; if ($request->getPost('back')) { $this->_helper->redirector('listar'); } 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()); $model->refresh(); $model->setReadOnly(false); } if ($request->isPost()) { if ($form->isValid($request->getPost())) { try { if (!$model) { $model = $this->dbtable->createRow(); } $params = $form->getValues(); $params['grupo_id'] = $params['grupo_id'] ?: 1;//Balcão $model->setFromArray($params); $id = $model->save(); if ($id) { $alerts->addSuccess('Dados salvos com sucesso.'); $this->_helper->redirector('save', $request->getControllerName(), $request->getModuleName(), array('id' => $id)); } else { $alerts->addDanger('Nenhum registro foi alterado.'); } } catch (Exception $e) { $alerts->addDanger($e->getMessage()); } } else { $alerts->addDanger('Dados inválidos ou faltando'); } } $this->view->form = $form; $this->view->model = $model; $this->view->tab = $this->_getParam('tab', 0); } public function addAction() { $this->_helper->layout->setLayout('layout_popup'); $this->view->title = "Cadastre-se! É rapidinho!"; $form = new Form_LeadAdd(); $request = $this->getRequest(); $params = $request->getParams(); if ($request->isPost()) { if (!$form->isValid($request->getPost())) { $this->_helper->json(['status' => 0, "alert" => "Favor preencha todos os campos!"]); } try { $empresa = Model_Container::getEmpresa()->findById((int)$params['empresa_id'] ?: 1); $params['grupo_id'] = $params['grupo_id'] ?: $empresa->grupo_lead_padrao; $model = (new Model_DbTable_Lead())->createRow($params); $save = $model->save(); if ($save instanceof Model_Lead) { (new Model_LeadEmpresa())->vincularLead($save->id, $empresa->id, $params['grupo_id']); $cupom = $model->notificaBoasVindas($save->id, $empresa->id); $this->view->gtag = $empresa->script_html; $this->view->cupom = $cupom ?: null; $this->_helper->json(['status' => 1, "msg" => $this->view->render("lead/sucesso.phtml")]); } elseif ($save) { // (new Model_LeadEmpresa())->vincularLead($save, $empresa->id, $params['grupo_id']); $cupom = $model->notificaBoasVindas($save, $empresa->id); $this->view->cupom = $cupom ?: null; $this->view->gtag = $empresa->script_html; $this->_helper->json(['status' => 1, "msg" => $this->view->render("lead/sucesso.phtml")]); } else { $this->_helper->json(['status' => 0, "msg" => $this->view->render("lead/erro.phtml")]); } } catch (Core_Exception $e) { $this->_helper->json(['status' => 0, "alert" => $e->getMessage()]); } catch (Exception $e) { Yuppie_Log::write($e->getMessage() . $e->getTraceAsString(), $this); $this->_helper->json(['status' => 0, "alert" => "Falha na execução"]); } } $this->view->form = $form; } public function naoPerturbeAction() { $request = $this->getRequest(); $leadId = $request->getParam('id', 0); if (empty($leadId)) { $this->_helper->json(['status' => 0, "alert" => "Lead não identificado"]); } try { $result = (new Model_LeadEmpresa())->inverterNaoPerturbe($leadId); if ($result) { $this->_helper->json(['status' => 1, "alert" => 'Cliente alterado com sucesso!']); } } catch (\Throwable $th) { Yuppie_Log::write("Falha ao alterar o não perturbe do lead => " . $th->getMessage() . $th->getTraceAsString()); $this->_helper->json(['status' => 0, "alert" => "Falha ao alterar o não perturbe do cliente!"]); } $this->_helper->json(['status' => 0, "alert" => 'Cliente não foi alterado!']); } public function deleteAction() { $request = $this->getRequest(); $this->dbtable = Model_Container::getLeadEmpresa(); if ($request->getPost('back')) { $this->_helper->redirector('listar'); } $id = (int) $request->getParam('id'); $empresaId = Yuppie_Auth::getIdentity()->empresa_id; $alerts = $this->getHelper('Alerts'); if (!$id) { $alerts->addWarning('Id inválido.'); $this->_helper->redirector('listar'); } if (!$empresaId) { $alerts->addWarning('Empresa inválida.'); $this->_helper->redirector('listar'); } $model = $this->dbtable->findByLeadId($id, $empresaId); if (!$model) { $alerts->addWarning('Registro inválido.'); $this->_helper->redirector('listar'); } $model->refresh(); $model->setReadOnly(false); try { if ($model->delete()) { $alerts->addSuccess('Registro excluído com sucesso.'); } else { $alerts->addDanger('Erro ao tentar excluir registro.'); } } catch(Exception $e) { $alerts->addDanger($e->getMessage()); $this->_helper->redirector('listar'); } $this->_helper->redirector('listar'); $this->view->model = $model; } public function historicoPontosAction() { $pedidoId = (int) $this->getRequest()->getParam('id'); $leadId = (int) $this->getRequest()->getParam('lead_id'); $lead = Model_Container::getLead()->findById($leadId); $pedido = Model_Container::getPedido()->findById($pedidoId); $this->view->paginator = $pedido->findDependentRowset('Model_DbTable_Pontos'); $this->view->pedido = $pedido; $this->view->lead = $lead; } public function historicoPedidosAction() { $leadId = (int) $this->getRequest()->getParam('id'); $lead = Model_Container::getLead()->findById($leadId); $this->view->paginator = Model_Container::getPedido()->fetchAll(['lead_id = ?' => $leadId, 'empresa_id = ?' => Yuppie_Auth::getIdentity()->empresa_id], 'id DESC'); $this->view->lead = $lead; } public function notificarBoasVindasAction() { $params = $this->getRequest()->getParams(); $leadId = (int)$params['id']; if (empty($leadId)) { $this->_helper->json(['status' => false, 'alert' => 'Lead não informado!']); } $leadEmpresa = Model_Container::getLeadEmpresa()->findByLeadId($leadId, Yuppie_Auth::getIdentity()->empresa_id); if ((new DateTime('now'))->diff(new DateTime($leadEmpresa->data_cadastro))->days > 1) { $this->_helper->json(['status' => false, 'alert' => 'Não é possível enviar notificação para este cliente.']); } (new Model_Lead())->notificaBoasVindas($leadId, Yuppie_Auth::getIdentity()->empresa_id); $this->_helper->json(['status' => true, 'alert' => 'Notificação enviada com sucesso!']); } public function alterarGrupoAction() { $request = $this->getRequest(); $leadId = (int)$request->getParam('cliente_id', 0); $grupoId = $request->getParam('grupo_id'); if (empty($leadId)) { $this->_helper->json(['status' => 0, "alert" => "Cliente não informado!"]); } if (empty($grupoId)) { $this->_helper->json(['status' => 0, "alert" => "Grupo não informado!"]); } try { $leadEmpresa = Model_Container::getLeadEmpresa()->findByLeadId($leadId, Yuppie_Auth::getIdentity()->empresa_id); if (!$leadEmpresa) { $this->_helper->json(['status' => 1, "alert" => "Não localizado para essa empresa."]); } $leadEmpresa->grupo_id = $grupoId; if ($leadEmpresa->save()) { $this->_helper->json(['status' => 1, "alert" => "Grupo alterado com sucesso!"]); } else { $this->_helper->json(['status' => 0, "alert" => "O grupo não foi alterado."]); } } catch (Core_Exception $e) { $this->_helper->json(['status' => 0, "alert" => $e->getMessage()]); } catch (Exception $e) { Yuppie_Log::write($e->getMessage() . $e->getTraceAsString(), $this); $this->_helper->json(['status' => 0, "alert" => "Falha na execução"]); } } }
💾 保存文件
← 返回文件管理器