✏️ 正在编辑: TransactionsController.php
路径:
/srv/systems_dir/koruspay/application/controllers/TransactionsController.php
提示:
您可以编辑任何文件(包括二进制文件),但请注意不当修改可能导致文件损坏。
<?php class TransactionsController extends Yuppie_Controller_Crud { protected $title = 'Transações'; protected $titleIcon = 'glyphicon-reg glyphicon-reg-money'; protected $sideMenu = null; public function extractAction() { $this->_helper->layout->setLayout('layout'); $this->view->title = 'Extrato'; $request = $this->getRequest(); $form = new Form_Filtro_Extract(); if ($request->isPost()) { $extract = $form->search(); } $this->view->form = $form; $this->view->extract = $extract; } public function balanceAction() { $this->_helper->layout->setLayout('layout'); $this->view->title = 'Saldo'; $this->view->titleIcon = 'glyphicon-reg glyphicon-reg-money'; $alerts = $this->getHelper('Alerts'); try { $model = new Model_Transactions(); $movements = $model->balance(Yuppie_Auth::getIdentity()->company_id); $movements['tax_withdraw'] = $movements['type_tax_pix'] ? $movements['tax_pix'] : ($movements['tax_pix'] / 100) * $movements['balance']; $movements['subtotal'] = $movements['balance'] <= 0 ? 0 : $movements['balance'] - $movements['tax_withdraw']; $token = "twkp_" . bin2hex(random_bytes(16)); $movements['token'] = $token; // Guarda o subtotal em sessão para "aguardar" processamento posterior $ns = new Zend_Session_Namespace($token); $ns->tax_withdraw = $movements['tax_withdraw']; $ns->subtotal = $movements['subtotal']; $ns->createdAt = time(); } catch (Exception $e) { $alerts->addDanger($e->getMessage()); } $this->view->balance = $movements; } public function withdrawAction() { $request = $this->getRequest(); $companyId = Yuppie_Auth::getIdentity()->company_id; $token = (string) $request->getPost('token'); if (empty($token)) { $this->_helper->json(['error' => 'Token não informado.']); } $ns = new Zend_Session_Namespace($token); if (!isset($ns->subtotal) || !isset($ns->tax_withdraw) || !isset($ns->createdAt)) { $this->_helper->json(['error' => 'Sessão inválida ou expirada.']); } $ttlSeconds = 600; if (time() - (int)$ns->createdAt > $ttlSeconds) { unset($ns->tax_withdraw, $ns->subtotal, $ns->createdAt); $this->_helper->json(['error' => 'Sessão expirada. Realize uma nova busca para atualizar o saldo.']); } $subtotal = $ns->subtotal; $tax = $ns->tax_withdraw; if (!is_numeric($subtotal) || $subtotal <= 0) { $this->_helper->json(['error' => 'Valor para saque inválido.']); } if (!is_numeric($tax) || $tax < 0) { $this->_helper->json(['error' => 'Tarifa inválida.']); } try { $model = new Model_Transactions(); $withdraw = $model->withdraw($companyId, (float)$subtotal, (float)$tax); if (empty($withdraw)) { $this->_helper->json(['error' => 'Ocorreu um erro ao solicitar o saque.']); } // limpa sessão somente após confirmação de sucesso $ns->unsetAll(); $this->_helper->json([ 'success' => true, 'message' => 'Em alguns minutos o processamento será concluído!' ]); } catch (Throwable $tr) { $this->_helper->json([ 'error' => $tr->getMessage() ]); } } public function checkTaxDebitedAction() { $request = $this->getRequest(); $splitId = $request->getPost('split_id'); $tbTransaction = Model_Container::getTransactions(); $debited = $tbTransaction->fetchRow([ 'MD5(split_id) = ?' => $splitId, 'type = ?' => 'TARIFA', 'situation = ?' => 'CONCLUIDO', 'deleted = ?' => 0 ]); if ($debited) { $this->_helper->json([ 'success' => true, 'message' => 'Validação realizada com sucesso.' ]); } $receipt = $tbTransaction->fetchRow([ 'MD5(split_id) = ?' => $splitId, 'type = ?' => 'CREDITO', 'situation = ?' => 'RECEBIDO', 'deleted = ?' => 0 ]); try { if (empty($receipt)) { $this->_helper->json([ 'error' => "Erro ao validar a liberação: Crédito não encontrado ou não está como RECEBIDO." ]); } (new Model_Transactions())->createTax($receipt); $this->_helper->json([ 'success' => true, 'message' => 'Validação em andamento.' ]); } catch (Throwable $tr) { $this->_helper->json([ 'error' => "Erro ao validar a liberação: " . $tr->getMessage() ]); } } }
💾 保存文件
← 返回文件管理器