notification

This commit is contained in:
2025-01-27 20:03:58 +03:00
parent 4692c70378
commit 6534b3155d
19 changed files with 670 additions and 38 deletions

View File

@ -8,8 +8,13 @@ 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\models\CardTransaction;
use kernel\app_modules\card\services\CardService;
use kernel\app_modules\card\services\CardTransactionService;
use kernel\app_modules\tag\service\TagService;
use kernel\app_modules\tgbot\models\forms\CreateTgbotNotificationForm;
use kernel\app_modules\tgbot\models\TgbotNotification;
use kernel\app_modules\tgbot\services\TgbotNotificationService;
use kernel\Controller;
use kernel\Flash;
use kernel\helpers\Debug;
@ -76,15 +81,15 @@ class TgMainController extends Controller
$card = CardService::getCardById($params->getItem("card_id"));
if ($params->getItem('type') === 'add_money'){
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'){
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'){
if ($params->getItem('type') === 'add_purchase') {
// Flash::setMessage("success", "С карты списано " . $params->getItem('amount'));
// CardService::withdrawMoneyFromCard($card, (int)$params->getItem('amount'));
$cashback = new CashbackCondition();
@ -94,7 +99,30 @@ class TgMainController extends Controller
$card = $card->fresh();
$tgbot = Tgbot::where("user_id", $card->user_id)->first();
if ($tgbot) {
$notificationForm = new CreateTgbotNotificationForm();
$notificationForm->load([
'bot_id' => $tgbot->bot_id,
'dialog_id' => $tgbot->dialog_id,
'content' => "На вашу карту начисленно " . $transaction->amount . " бонуса.",
'status' => TgbotNotification::TO_SEND_STATUS,
]);
$notificationService = new TgbotNotificationService();
$notificationService->create($notificationForm);
}
$this->cgView->render("card_action_step_3.php", ['card' => $card, 'transaction' => $transaction ?? null]);
}
public function actionCardInfo(int $cardId): void
{
$card = Card::where("id", $cardId)->first();
$transactions = CardTransaction::where("from", $cardId)->orWhere("to", $cardId)->get();
$this->cgView->render("card_info.php", ['card' => $card, 'transactions' => $transactions]);
}
}

View File

@ -18,6 +18,7 @@ App::$collector->group(["prefix" => "miniapp"], function (CGRouteCollector $rout
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']);
App::$collector->get('/card_info/{cardId}', [\app\modules\tgbot\controllers\TgMainController::class, 'actionCardInfo']);
});
});
});

View File

@ -35,4 +35,9 @@ use kernel\helpers\Html;
<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>
<div class="row" style="margin-top: 20px;">
<div class="col-12 m-1">
<a class="btn btn-primary w-100" href="/miniapp/card_info/<?=$card->id?>">Информация о карте</a>
</div>
</div>

View File

@ -0,0 +1,80 @@
<?php
/**
* @var \kernel\app_modules\card\models\Card $card
* @var \Illuminate\Database\Eloquent\Collection $transactions
*/
use Itguild\EloquentTable\ViewEloquentTable;
use Itguild\EloquentTable\ViewJsonTableEloquentModel;
use kernel\app_modules\card\models\Card;
use kernel\modules\user\models\User;
use kernel\widgets\IconBtn\IconBtnDeleteWidget;
use kernel\widgets\IconBtn\IconBtnEditWidget;
use kernel\widgets\IconBtn\IconBtnListWidget;
$table = new ViewEloquentTable(new ViewJsonTableEloquentModel($card, [
'params' => ["class" => "table table-bordered", "border" => "2"],
'baseUrl' => "/admin/card",
]));
$table->beforePrint(function () use ($card) {
$btn = "<h2>Информация о карте</h2>";
$btn .= IconBtnListWidget::create(['url' => '/miniapp/card_action/' . $card->id])->run();
return $btn;
});
$table->rows([
'user_id' => (function ($data) {
return User::find($data)->username;
}),
'status' => function ($data) {
return \kernel\app_modules\card\models\Card::getStatus()[$data];
}
]);
$table->create();
$table->render();
echo "<h3>Тразакции</h3>";
foreach ($transactions as $transaction){
$table = new ViewEloquentTable(new ViewJsonTableEloquentModel($transaction, [
'params' => ["class" => "table table-bordered", "border" => "2"],
'baseUrl' => "/admin/card_program",
]));
$table->rows([
'status' => [
'value' => function ($data) {
return \kernel\app_modules\card\models\CardProgram::getStatus()[$data];
}
],
'from' => [
'value' => function ($data) {
if ((int)$data === 1001){
$username = "System";
}
else {
$username = Card::find($data)->username ?? '';
}
return $username;
}
],
'to' => [
'value' => function ($data) {
if ((int)$data === 1001){
$username = "System";
}
else {
$username = Card::find($data)->username ?? '';
}
return $username;
}
],
]);
$table->create();
$table->render();
}