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]);
}
}