card action
This commit is contained in:
@ -12,11 +12,16 @@ class TgBotRestController extends \kernel\app_modules\tgbot\controllers\TgBotRes
|
||||
public function actionGetScanBtn(int $id): void
|
||||
{
|
||||
$dialog = Tgbot::where("dialog_id", $id)->first();
|
||||
$html = "";
|
||||
if ($dialog){
|
||||
$this->renderApi([
|
||||
'html' => '<a class="btn btn-primary" href="/miniapp/scanner">Сканировать</a>',
|
||||
]);
|
||||
if ($dialog->status === Tgbot::ADMIN_STATUS){
|
||||
$html = '<a class="btn btn-primary" href="/miniapp/scanner">Сканировать</a>';
|
||||
}
|
||||
}
|
||||
|
||||
$this->renderApi([
|
||||
'html' => $html,
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
|
@ -2,14 +2,19 @@
|
||||
|
||||
namespace app\modules\tgbot\controllers;
|
||||
|
||||
use app\modules\tgbot\models\forms\CardActionStep2Form;
|
||||
use app\modules\tgbot\models\Tgbot;
|
||||
use app\modules\tgbot\services\TgBotService;
|
||||
use Cassandra\Decimal;
|
||||
use kernel\app_modules\card\conditions\CashbackCondition;
|
||||
use kernel\app_modules\card\models\Card;
|
||||
use kernel\app_modules\card\services\CardService;
|
||||
use kernel\app_modules\tag\service\TagService;
|
||||
use kernel\Controller;
|
||||
use kernel\Flash;
|
||||
use kernel\helpers\Debug;
|
||||
use kernel\modules\post\models\Post;
|
||||
use kernel\Request;
|
||||
|
||||
class TgMainController extends Controller
|
||||
{
|
||||
@ -47,11 +52,49 @@ class TgMainController extends Controller
|
||||
$this->cgView->render("scanner.php");
|
||||
}
|
||||
|
||||
public function actionCardAction(int $cardId): void
|
||||
public function actionCardActionStep1(int $cardId): void
|
||||
{
|
||||
$card = Card::where("id", $cardId)->first();
|
||||
|
||||
$this->cgView->render("card_action.php", ['card' => $card]);
|
||||
$this->cgView->render("card_action_step_1.php", ['card' => $card]);
|
||||
}
|
||||
|
||||
public function actionCardActionStep2(): void
|
||||
{
|
||||
$params = new CardActionStep2Form();
|
||||
$request = new Request();
|
||||
$params->load($request->get());
|
||||
|
||||
$this->cgView->render("card_action_step_2.php", ['params' => $params]);
|
||||
}
|
||||
|
||||
public function actionCardActionStep3(): void
|
||||
{
|
||||
$params = new CardActionStep2Form();
|
||||
$request = new Request();
|
||||
$params->load($request->post());
|
||||
|
||||
$card = CardService::getCardById($params->getItem("card_id"));
|
||||
|
||||
if ($params->getItem('type') === 'add_money'){
|
||||
Flash::setMessage("success", "Баланс пополнен на " . $params->getItem('amount'));
|
||||
$transaction = CardService::addMoneyToCard($card, (int)$params->getItem('amount'));
|
||||
}
|
||||
if ($params->getItem('type') === 'withdraw'){
|
||||
Flash::setMessage("success", "С карты списано " . $params->getItem('amount'));
|
||||
$transaction = CardService::withdrawMoneyFromCard($card, (int)$params->getItem('amount'));
|
||||
}
|
||||
if ($params->getItem('type') === 'add_purchase'){
|
||||
// Flash::setMessage("success", "С карты списано " . $params->getItem('amount'));
|
||||
// CardService::withdrawMoneyFromCard($card, (int)$params->getItem('amount'));
|
||||
$cashback = new CashbackCondition();
|
||||
$transaction = $cashback->handler($card, (int)$params->getItem('amount'));
|
||||
Flash::setMessage("success", "Начислено кешбэк " . $transaction->amount);
|
||||
}
|
||||
|
||||
$card = $card->fresh();
|
||||
|
||||
$this->cgView->render("card_action_step_3.php", ['card' => $card, 'transaction' => $transaction ?? null]);
|
||||
}
|
||||
|
||||
}
|
@ -9,7 +9,7 @@ use kernel\Middleware;
|
||||
class TgBotAuthMiddleware extends Middleware
|
||||
{
|
||||
|
||||
function handler(): void
|
||||
public function handler(): void
|
||||
{
|
||||
if(isset($_COOKIE['dialog_id']))
|
||||
{
|
||||
@ -23,4 +23,14 @@ class TgBotAuthMiddleware extends Middleware
|
||||
|
||||
exit();
|
||||
}
|
||||
|
||||
public function isTgAdmin(): void
|
||||
{
|
||||
if (TgBotService::isAdmin()){
|
||||
return;
|
||||
}
|
||||
|
||||
echo "Доступ запрещен";
|
||||
exit();
|
||||
}
|
||||
}
|
23
app/modules/tgbot/models/forms/CardActionStep2Form.php
Normal file
23
app/modules/tgbot/models/forms/CardActionStep2Form.php
Normal file
@ -0,0 +1,23 @@
|
||||
<?php
|
||||
|
||||
namespace app\modules\tgbot\models\forms;
|
||||
|
||||
use kernel\FormModel;
|
||||
|
||||
/**
|
||||
* @property string $type
|
||||
* @property integer $card_id
|
||||
*/
|
||||
class CardActionStep2Form extends FormModel
|
||||
{
|
||||
|
||||
public function rules(): array
|
||||
{
|
||||
return [
|
||||
'type' => 'required|min-str-len:3',
|
||||
'card_id' => 'required|alpha-numeric',
|
||||
'amount' => 'alpha-numeric',
|
||||
];
|
||||
}
|
||||
|
||||
}
|
@ -6,13 +6,18 @@ use kernel\CgRouteCollector;
|
||||
include KERNEL_APP_MODULES_DIR . "/tgbot/routs/tgbot.php";
|
||||
|
||||
App::$collector->filter("tg_bot_auth", [\app\modules\tgbot\middlewares\TgBotAuthMiddleware::class, "handler"]);
|
||||
App::$collector->filter("tg_bot_is_admin", [\app\modules\tgbot\middlewares\TgBotAuthMiddleware::class, "isTgAdmin"]);
|
||||
|
||||
App::$collector->group(["prefix" => "miniapp"], function (CGRouteCollector $router) {
|
||||
App::$collector->get('/', [\app\modules\tgbot\controllers\TgMainController::class, 'actionMain']);
|
||||
App::$collector->group(["before" => "tg_bot_auth"], function (CGRouteCollector $router){
|
||||
App::$collector->get('/news', [\app\modules\tgbot\controllers\TgMainController::class, 'actionNews']);
|
||||
App::$collector->get('/promo', [\app\modules\tgbot\controllers\TgMainController::class, 'actionPromo']);
|
||||
App::$collector->get('/scanner', [\app\modules\tgbot\controllers\TgMainController::class, 'actionScanner']);
|
||||
App::$collector->get('/card_action/{cardId}', [\app\modules\tgbot\controllers\TgMainController::class, 'actionCardAction']);
|
||||
App::$collector->group(["before" => "tg_bot_is_admin"], function (CGRouteCollector $router){
|
||||
App::$collector->get('/scanner', [\app\modules\tgbot\controllers\TgMainController::class, 'actionScanner']);
|
||||
App::$collector->get('/card_action/{cardId}', [\app\modules\tgbot\controllers\TgMainController::class, 'actionCardActionStep1']);
|
||||
App::$collector->get('/card_action_step_2', [\app\modules\tgbot\controllers\TgMainController::class, 'actionCardActionStep2']);
|
||||
App::$collector->post('/card_action_step_3', [\app\modules\tgbot\controllers\TgMainController::class, 'actionCardActionStep3']);
|
||||
});
|
||||
});
|
||||
});
|
@ -12,6 +12,4 @@ use kernel\services\ModuleService;
|
||||
class TgBotService extends \kernel\app_modules\tgbot\services\TgBotService
|
||||
{
|
||||
|
||||
public static null|Tgbot $currentDialog = null;
|
||||
|
||||
}
|
@ -5,7 +5,7 @@
|
||||
* @var string $title
|
||||
* @var \kernel\CgView $view
|
||||
*/
|
||||
\Josantonius\Session\Facades\Session::start();
|
||||
\kernel\Flash::start();
|
||||
?>
|
||||
<!doctype html>
|
||||
<html lang="en">
|
||||
|
@ -1,23 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* @var \kernel\app_modules\card\models\Card $card
|
||||
*/
|
||||
|
||||
|
||||
use kernel\helpers\Html;
|
||||
|
||||
?>
|
||||
|
||||
<div class="row">
|
||||
<div class="col-12 m-1">
|
||||
<?php
|
||||
echo Html::img(src: "data:image/png;base64, " . \kernel\app_modules\card\services\CardFileService::createCardPNG($card, true));
|
||||
?>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="row">
|
||||
<div class="col-12 m-1">
|
||||
<a class="btn btn-primary" href="/miniapp/add_purchase">Добавить покупку</a>
|
||||
</div>
|
||||
</div>
|
38
app/modules/tgbot/views/tgbot/main/card_action_step_1.php
Normal file
38
app/modules/tgbot/views/tgbot/main/card_action_step_1.php
Normal file
@ -0,0 +1,38 @@
|
||||
<?php
|
||||
/**
|
||||
* @var \kernel\app_modules\card\models\Card $card
|
||||
*/
|
||||
|
||||
|
||||
use kernel\helpers\Html;
|
||||
|
||||
?>
|
||||
|
||||
<div class="row">
|
||||
<div class="col-12 m-1">
|
||||
<?php
|
||||
echo Html::img(src: "data:image/png;base64, " . \kernel\app_modules\card\services\CardFileService::createCardPNG($card, true));
|
||||
?>
|
||||
</div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col-12 m-1" style="font-size: 20px;">
|
||||
Баланс: <?= $card->balance ?>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="row" style="margin-top: 20px;">
|
||||
<div class="col-12 m-1">
|
||||
<a class="btn btn-primary w-100" href="/miniapp/card_action_step_2?type=add_purchase&card_id=<?=$card->id?>">Добавить покупку</a>
|
||||
</div>
|
||||
</div>
|
||||
<div class="row" style="margin-top: 20px;">
|
||||
<div class="col-12 m-1">
|
||||
<a class="btn btn-primary w-100" href="/miniapp/card_action_step_2?type=add_money&card_id=<?=$card->id?>">Начислить</a>
|
||||
</div>
|
||||
</div>
|
||||
<div class="row" style="margin-top: 20px;">
|
||||
<div class="col-12 m-1">
|
||||
<a class="btn btn-primary w-100" href="/miniapp/card_action_step_2?type=withdraw&card_id=<?=$card->id?>">Списать</a>
|
||||
</div>
|
||||
</div>
|
51
app/modules/tgbot/views/tgbot/main/card_action_step_2.php
Normal file
51
app/modules/tgbot/views/tgbot/main/card_action_step_2.php
Normal file
@ -0,0 +1,51 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @var \app\modules\tgbot\models\forms\CardActionStep2Form $params;
|
||||
*/
|
||||
|
||||
$form = new \itguild\forms\ActiveForm();
|
||||
$form->beginForm( "/miniapp/card_action_step_3");
|
||||
|
||||
$form->field(class: \itguild\forms\inputs\Hidden::class, name: "card_id", params: [
|
||||
'value' => $params->getItem("card_id")
|
||||
])
|
||||
->render();
|
||||
|
||||
$form->field(class: \itguild\forms\inputs\Hidden::class, name: "type", params: [
|
||||
'value' => $params->getItem("type")
|
||||
])
|
||||
->render();
|
||||
|
||||
$form->field(class: \itguild\forms\inputs\TextInput::class, name: "amount", params: [
|
||||
'class' => "form-control",
|
||||
'placeholder' => 'Количество',
|
||||
])
|
||||
->setLabel("Количество")
|
||||
->render();
|
||||
|
||||
?>
|
||||
<div class="row">
|
||||
<div class="col-sm-2">
|
||||
<?php
|
||||
$form->field(\itguild\forms\inputs\Button::class, name: "btn-submit", params: [
|
||||
'class' => "btn btn-primary ",
|
||||
'value' => 'Отправить',
|
||||
'typeInput' => 'submit'
|
||||
])
|
||||
->render();
|
||||
?>
|
||||
</div>
|
||||
<div class="col-sm-2">
|
||||
<?php
|
||||
$form->field(\itguild\forms\inputs\Button::class, name: "btn-reset", params: [
|
||||
'class' => "btn btn-warning",
|
||||
'value' => 'Сбросить',
|
||||
'typeInput' => 'reset'
|
||||
])
|
||||
->render();
|
||||
?>
|
||||
</div>
|
||||
</div>
|
||||
<?php
|
||||
$form->endForm();
|
30
app/modules/tgbot/views/tgbot/main/card_action_step_3.php
Normal file
30
app/modules/tgbot/views/tgbot/main/card_action_step_3.php
Normal file
@ -0,0 +1,30 @@
|
||||
<?php
|
||||
/**
|
||||
* @var Card $card
|
||||
* @var CardTransaction $transaction
|
||||
*/
|
||||
|
||||
use kernel\app_modules\card\models\Card;
|
||||
use kernel\app_modules\card\models\CardTransaction;
|
||||
use kernel\app_modules\card\services\CardFileService;
|
||||
use kernel\helpers\Html;
|
||||
|
||||
?>
|
||||
|
||||
<div class="row">
|
||||
<div class="col-12 m-1">
|
||||
<?php
|
||||
echo Html::img(src: "data:image/png;base64, " . CardFileService::createCardPNG($card, true));
|
||||
?>
|
||||
</div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col-12 m-1" style="font-size: 20px;">
|
||||
Баланс: <?= $card->balance ?>
|
||||
</div>
|
||||
</div>
|
||||
<div class="row" style="margin-top: 20px;">
|
||||
<div class="col-12 m-1">
|
||||
<a class="btn btn-primary w-100" href="/miniapp/scanner">Сканировать</a>
|
||||
</div>
|
||||
</div>
|
Reference in New Issue
Block a user