Compare commits
42 Commits
74efe9e01e
...
master
Author | SHA1 | Date | |
---|---|---|---|
6534b3155d | |||
4692c70378 | |||
4b498c7fc6 | |||
c7f56937df | |||
06e5434266 | |||
de31005f1a | |||
dd28eadf79 | |||
b08aaec81d | |||
79ed17baa4 | |||
ffd30ca370 | |||
824130df26 | |||
08cdf44b67 | |||
485c11de5f | |||
1ffa0581bf | |||
193fc35caf | |||
d9178c17f7 | |||
6b61b51d53 | |||
d34fdd946c | |||
b18378bcb1 | |||
40369fb515 | |||
3ca3d48ffe | |||
6bc4bc72d2 | |||
db530979a2 | |||
5e945485f5 | |||
0b85738332 | |||
a9a32db54c | |||
dae649fe65 | |||
7b4bfbbc21 | |||
3a36554034 | |||
cba447015c | |||
f97439c348 | |||
9e7ded8b15 | |||
6180fb52ae | |||
3d5869d140 | |||
697a46afea | |||
069a5b223f | |||
d2ffae95dc | |||
ba10bea132 | |||
6462a98e6c | |||
7e9d2cf5a7 | |||
63f88f425e | |||
bbdcf08e13 |
4
.gitignore
vendored
4
.gitignore
vendored
@ -4,4 +4,6 @@ vendor
|
||||
views_cache
|
||||
resources/upload
|
||||
resources/tmp
|
||||
composer.lock
|
||||
resources/cards
|
||||
composer.lock
|
||||
resources/main/js/tg_app/config_local.js
|
@ -2,7 +2,31 @@
|
||||
|
||||
namespace app\modules\photo;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use kernel\app_modules\photo\models\Photo;
|
||||
|
||||
class PhotoModule extends \kernel\app_modules\photo\PhotoModule
|
||||
{
|
||||
|
||||
public function getItems(string $entity, Model $model): array|string
|
||||
{
|
||||
$photos = Photo::where("entity", $entity)->where("entity_id", $model->id)->get();
|
||||
$photoArr = [];
|
||||
foreach ($photos as $photo) {
|
||||
$photoArr[] =$photo->image;
|
||||
}
|
||||
|
||||
return $photoArr;
|
||||
}
|
||||
|
||||
public function getItem(string $entity, string $entity_id): string
|
||||
{
|
||||
$photos = Photo::where("entity", $entity)->where("entity_id", $entity_id)->first();
|
||||
if ($photos){
|
||||
return $photos->image;
|
||||
}
|
||||
|
||||
return "";
|
||||
}
|
||||
|
||||
}
|
@ -2,7 +2,32 @@
|
||||
|
||||
namespace app\modules\tgbot\controllers;
|
||||
|
||||
use app\modules\tgbot\models\Tgbot;
|
||||
use kernel\app_modules\tag\service\TagService;
|
||||
use kernel\modules\post\models\Post;
|
||||
|
||||
class TgBotRestController extends \kernel\app_modules\tgbot\controllers\TgBotRestController
|
||||
{
|
||||
|
||||
public function actionGetScanBtn(int $id): void
|
||||
{
|
||||
$dialog = Tgbot::where("dialog_id", $id)->first();
|
||||
$html = "";
|
||||
if ($dialog){
|
||||
if ($dialog->status === Tgbot::ADMIN_STATUS){
|
||||
$html = '<a class="btn btn-primary" href="/miniapp/scanner">Сканировать</a>';
|
||||
}
|
||||
}
|
||||
|
||||
$this->renderApi([
|
||||
'html' => $html,
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
public function actionGetNews(): void
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
}
|
128
app/modules/tgbot/controllers/TgMainController.php
Normal file
128
app/modules/tgbot/controllers/TgMainController.php
Normal file
@ -0,0 +1,128 @@
|
||||
<?php
|
||||
|
||||
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\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;
|
||||
use kernel\modules\post\models\Post;
|
||||
use kernel\Request;
|
||||
|
||||
class TgMainController extends Controller
|
||||
{
|
||||
|
||||
protected function init(): void
|
||||
{
|
||||
parent::init();
|
||||
$this->cgView->viewPath = APP_DIR . "/modules/tgbot/views/tgbot/main/";
|
||||
$this->cgView->layout = "main.php";
|
||||
$this->cgView->layoutPath = APP_DIR . "/modules/tgbot/views/tgbot/layout/";
|
||||
$this->cgView->addVarToLayout("resources", "/resources/main");
|
||||
}
|
||||
|
||||
public function actionMain(): void
|
||||
{
|
||||
$this->cgView->render("index.php");
|
||||
}
|
||||
|
||||
public function actionNews(): void
|
||||
{
|
||||
$news = TagService::getEntityByTagSlug("novosti", Post::class);
|
||||
|
||||
$this->cgView->render("news.php", ['news' => $news]);
|
||||
}
|
||||
|
||||
public function actionPromo(): void
|
||||
{
|
||||
$news = TagService::getEntityByTagSlug("akcii", Post::class);
|
||||
|
||||
$this->cgView->render("news.php", ['news' => $news]);
|
||||
}
|
||||
|
||||
public function actionScanner(): void
|
||||
{
|
||||
$this->cgView->render("scanner.php");
|
||||
}
|
||||
|
||||
public function actionCardActionStep1(int $cardId): void
|
||||
{
|
||||
$card = Card::where("id", $cardId)->first();
|
||||
|
||||
$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();
|
||||
|
||||
$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]);
|
||||
}
|
||||
|
||||
}
|
36
app/modules/tgbot/middlewares/TgBotAuthMiddleware.php
Normal file
36
app/modules/tgbot/middlewares/TgBotAuthMiddleware.php
Normal file
@ -0,0 +1,36 @@
|
||||
<?php
|
||||
|
||||
namespace app\modules\tgbot\middlewares;
|
||||
|
||||
use app\modules\tgbot\models\Tgbot;
|
||||
use app\modules\tgbot\services\TgBotService;
|
||||
use kernel\Middleware;
|
||||
|
||||
class TgBotAuthMiddleware extends Middleware
|
||||
{
|
||||
|
||||
public function handler(): void
|
||||
{
|
||||
if(isset($_COOKIE['dialog_id']))
|
||||
{
|
||||
$model = Tgbot::where("dialog_id", $_COOKIE['dialog_id'])->first();
|
||||
if ($model){
|
||||
TgBotService::$currentDialog = $model;
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
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',
|
||||
];
|
||||
}
|
||||
|
||||
}
|
@ -1,3 +1,24 @@
|
||||
<?php
|
||||
|
||||
include KERNEL_APP_MODULES_DIR . "/tgbot/routs/tgbot.php";
|
||||
use kernel\App;
|
||||
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->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']);
|
||||
App::$collector->get('/card_info/{cardId}', [\app\modules\tgbot\controllers\TgMainController::class, 'actionCardInfo']);
|
||||
});
|
||||
});
|
||||
});
|
84
app/modules/tgbot/views/tgbot/layout/main.php
Normal file
84
app/modules/tgbot/views/tgbot/layout/main.php
Normal file
@ -0,0 +1,84 @@
|
||||
<?php
|
||||
/**
|
||||
* @var $content
|
||||
* @var string $resources
|
||||
* @var string $title
|
||||
* @var \kernel\CgView $view
|
||||
*/
|
||||
\kernel\Flash::start();
|
||||
?>
|
||||
<!doctype html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<title><?= $title ?></title>
|
||||
<meta charset="utf-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
|
||||
<?= $view->getMeta() ?>
|
||||
|
||||
<link href="https://fonts.googleapis.com/css?family=Poppins:300,400,500,600,700,800,900" rel="stylesheet">
|
||||
|
||||
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.6.0/css/all.min.css">
|
||||
<link rel="stylesheet" href="<?= $resources ?>/css/bootstrap.min.css">
|
||||
<link rel="stylesheet" href="<?= $resources ?>/css/style.css">
|
||||
<link rel="stylesheet" href="<?= $resources ?>/css/tgApp.css">
|
||||
<script src="https://telegram.org/js/telegram-web-app.js"></script>
|
||||
<script src="https://unpkg.com/html5-qrcode" type="text/javascript"></script>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<div class="wrapper d-flex align-items-stretch">
|
||||
<!-- Page Content -->
|
||||
<div id="content" class="p-4 p-md-5">
|
||||
|
||||
<nav class="navbar navbar-expand-lg navbar-light bg-light">
|
||||
<div class="container-fluid">
|
||||
|
||||
<button class="btn btn-dark d-inline-block d-lg-none ml-auto" type="button" data-toggle="collapse"
|
||||
data-target="#navbarSupportedContent" aria-controls="navbarSupportedContent"
|
||||
aria-expanded="false" aria-label="Toggle navigation">
|
||||
<i class="fa fa-bars"></i>
|
||||
</button>
|
||||
|
||||
<div class="collapse navbar-collapse" id="navbarSupportedContent">
|
||||
<ul class="nav navbar-nav ml-auto">
|
||||
<li class="nav-item">
|
||||
<a class="nav-link" href="/miniapp">Главная</a>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<a class="nav-link" href="/miniapp/news">Новости</a>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<a class="nav-link" href="/miniapp/promo">Акции</a>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
</nav>
|
||||
<?php if (\kernel\Flash::hasMessage("error")): ?>
|
||||
<div class="alert alert-danger alert-dismissible mainAlert">
|
||||
<?= \kernel\Flash::getMessage("error"); ?>
|
||||
<button type="button" class="btn-close closeAlertBtn"></button>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
<?php if (\kernel\Flash::hasMessage("success")): ?>
|
||||
<div class="alert alert-success alert-dismissible">
|
||||
<?= \kernel\Flash::getMessage("success"); ?>
|
||||
<button type="button" class="btn-close closeAlertBtn"></button>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
<?= $content ?>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script src="<?= $resources ?>/js/jquery.min.js"></script>
|
||||
<script src="<?= $resources ?>/js/popper.js"></script>
|
||||
<script src="<?= $resources ?>/js/bootstrap.min.js"></script>
|
||||
<script src="<?= $resources ?>/js/main.js"></script>
|
||||
<script type="module" src="<?= $resources ?>/js/tg.js"></script>
|
||||
<!--<script src="https://cdn.jsdelivr.net/npm/eruda"></script>-->
|
||||
<!--<script>-->
|
||||
<!-- // Initialize Eruda-->
|
||||
<!-- eruda.init();-->
|
||||
<!--</script>-->
|
||||
</body>
|
||||
</html>
|
1
app/modules/tgbot/views/tgbot/main/btn.php
Normal file
1
app/modules/tgbot/views/tgbot/main/btn.php
Normal file
@ -0,0 +1 @@
|
||||
<a class="btn btn-primary" href="/miniapp/scan">Сканировать</a>
|
43
app/modules/tgbot/views/tgbot/main/card_action_step_1.php
Normal file
43
app/modules/tgbot/views/tgbot/main/card_action_step_1.php
Normal file
@ -0,0 +1,43 @@
|
||||
<?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>
|
||||
<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>
|
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>
|
80
app/modules/tgbot/views/tgbot/main/card_info.php
Normal file
80
app/modules/tgbot/views/tgbot/main/card_info.php
Normal 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();
|
||||
}
|
1
app/modules/tgbot/views/tgbot/main/index.php
Normal file
1
app/modules/tgbot/views/tgbot/main/index.php
Normal file
@ -0,0 +1 @@
|
||||
<div id="tg_app"></div>
|
20
app/modules/tgbot/views/tgbot/main/news.php
Normal file
20
app/modules/tgbot/views/tgbot/main/news.php
Normal file
@ -0,0 +1,20 @@
|
||||
<?php
|
||||
/**
|
||||
* @var \Illuminate\Database\Eloquent\Collection $news
|
||||
*/
|
||||
$entityRelation = new \kernel\EntityRelation();
|
||||
?>
|
||||
<?php foreach ($news as $new): ?>
|
||||
<?php
|
||||
$img = $entityRelation->getAdditionalPropertyByEntityId("post", $new['id'], 'photo');
|
||||
?>
|
||||
<div class="card">
|
||||
<?php if ($img): ?>
|
||||
<img src="<?= $img ?>" class="card-img-top"/>
|
||||
<?php endif; ?>
|
||||
<div class="card-body">
|
||||
<h5 class="card-title"><?= $new['title'] ?></h5>
|
||||
<p class="card-text"><?= $new['content'] ?></p>
|
||||
</div>
|
||||
</div>
|
||||
<?php endforeach; ?>
|
30
app/modules/tgbot/views/tgbot/main/scanner.php
Normal file
30
app/modules/tgbot/views/tgbot/main/scanner.php
Normal file
@ -0,0 +1,30 @@
|
||||
<div id="tg_app">
|
||||
|
||||
</div>
|
||||
<div id="scanner_box"></div>
|
||||
<script>
|
||||
function domReady(fn) {
|
||||
if (
|
||||
document.readyState === "complete" ||
|
||||
document.readyState === "interactive"
|
||||
) {
|
||||
setTimeout(fn, 1000);
|
||||
} else {
|
||||
document.addEventListener("DOMContentLoaded", fn);
|
||||
}
|
||||
}
|
||||
|
||||
domReady(function () {
|
||||
|
||||
// If found you qr code
|
||||
function onScanSuccess(decodeText, decodeResult) {
|
||||
window.location.href = "/miniapp/card_action/" + decodeText;
|
||||
}
|
||||
|
||||
let htmlscanner = new Html5QrcodeScanner(
|
||||
"scanner_box",
|
||||
{fps: 10, qrbox: {width: 250, height: 250}},
|
||||
);
|
||||
htmlscanner.render(onScanSuccess);
|
||||
});
|
||||
</script>
|
@ -9,12 +9,13 @@ class Flash
|
||||
|
||||
public static function setMessage(string $type, string $msg): void
|
||||
{
|
||||
Session::start();
|
||||
self::start();
|
||||
Session::set($type, $msg);
|
||||
}
|
||||
|
||||
public static function getMessage(string $type): string
|
||||
{
|
||||
self::start();
|
||||
$msg = Session::get($type, false);
|
||||
Session::remove($type);
|
||||
|
||||
@ -23,7 +24,16 @@ class Flash
|
||||
|
||||
public static function hasMessage(string $type): bool
|
||||
{
|
||||
self::start();
|
||||
|
||||
return Session::has($type);
|
||||
}
|
||||
|
||||
public static function start()
|
||||
{
|
||||
if (!Session::isStarted()){
|
||||
Session::start();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -50,6 +50,27 @@ class CardModule extends Module
|
||||
"slug" => "card_template",
|
||||
"parent_slug" => "card"
|
||||
]);
|
||||
|
||||
$this->menuService->createItem([
|
||||
"label" => "Программы",
|
||||
"url" => "/admin/card_program",
|
||||
"slug" => "card_program",
|
||||
"parent_slug" => "card"
|
||||
]);
|
||||
|
||||
$this->menuService->createItem([
|
||||
"label" => "Условия",
|
||||
"url" => "/admin/card_program_conditions",
|
||||
"slug" => "card_program_conditions",
|
||||
"parent_slug" => "card"
|
||||
]);
|
||||
|
||||
$this->menuService->createItem([
|
||||
"label" => "Транзакции",
|
||||
"url" => "/admin/card_transaction",
|
||||
"slug" => "card_transaction",
|
||||
"parent_slug" => "card"
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -60,6 +81,9 @@ class CardModule extends Module
|
||||
$this->menuService->removeItemBySlug("card");
|
||||
$this->menuService->removeItemBySlug("card_list");
|
||||
$this->menuService->removeItemBySlug("card_template");
|
||||
$this->menuService->removeItemBySlug("card_program");
|
||||
$this->menuService->removeItemBySlug("card_program_conditions");
|
||||
$this->menuService->removeItemBySlug("card_transaction");
|
||||
$this->migrationService->rollbackAtPath("{KERNEL_APP_MODULES}/card/migrations");
|
||||
$this->consoleService->runComposerRemove("dragon-code/card-number");
|
||||
$this->consoleService->runComposerRemove("endroid/qr-code");
|
||||
|
42
kernel/app_modules/card/conditions/CashbackCondition.php
Normal file
42
kernel/app_modules/card/conditions/CashbackCondition.php
Normal file
@ -0,0 +1,42 @@
|
||||
<?php
|
||||
|
||||
namespace kernel\app_modules\card\conditions;
|
||||
|
||||
use kernel\app_modules\card\models\Card;
|
||||
use kernel\app_modules\card\models\forms\CreateCardTransactionForm;
|
||||
use kernel\app_modules\card\services\CardTransactionService;
|
||||
use kernel\helpers\Debug;
|
||||
|
||||
class CashbackCondition
|
||||
{
|
||||
|
||||
public function handler(Card $card, int $amount): \kernel\app_modules\card\models\CardTransaction|false
|
||||
{
|
||||
$conditions = $card->cardProgram->cardProgramConditions;
|
||||
if ($conditions){
|
||||
foreach ($conditions as $condition){
|
||||
if ($condition->type === "cashback"){
|
||||
$transactionForm = new CreateCardTransactionForm();
|
||||
$transactionForm->load([
|
||||
'from' => 1001,
|
||||
'to' => $card->id,
|
||||
'amount' => $this->calcPercent($amount, $condition->value),
|
||||
'type' => 1,
|
||||
'status' => 1,
|
||||
]);
|
||||
$transactionService = new CardTransactionService();
|
||||
|
||||
return $transactionService->create($transactionForm);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private function calcPercent($price, $percent): int
|
||||
{
|
||||
return round($price * ($percent / 100));
|
||||
}
|
||||
|
||||
}
|
@ -89,6 +89,7 @@ class CardController extends AdminController
|
||||
$this->redirect("/admin/card/" . $card->id);
|
||||
}
|
||||
}
|
||||
Flash::setMessage("error", $cardForm->getErrorsStr());
|
||||
$this->redirect("/admin/card/update/" . $id);
|
||||
}
|
||||
|
||||
|
@ -0,0 +1,120 @@
|
||||
<?php
|
||||
|
||||
namespace kernel\app_modules\card\controllers;
|
||||
|
||||
use Exception;
|
||||
use JetBrains\PhpStorm\NoReturn;
|
||||
use kernel\AdminController;
|
||||
use kernel\app_modules\card\models\CardProgram;
|
||||
use kernel\app_modules\card\models\CardProgramConditions;
|
||||
use kernel\app_modules\card\models\forms\CreateCardProgramConditionsForm;
|
||||
use kernel\app_modules\card\models\forms\CreateCardProgramForm;
|
||||
use kernel\app_modules\card\services\CardProgramConditionsService;
|
||||
use kernel\app_modules\card\services\CardProgramService;
|
||||
use kernel\app_modules\card\services\CardService;
|
||||
use kernel\Flash;
|
||||
|
||||
class CardProgramConditionsController extends AdminController
|
||||
{
|
||||
|
||||
private CardProgramConditionsService $cardProgramConditionsService;
|
||||
|
||||
protected function init(): void
|
||||
{
|
||||
parent::init();
|
||||
$this->cgView->viewPath = KERNEL_APP_MODULES_DIR . "/card/views/card_program_conditions/";
|
||||
$this->cardProgramConditionsService = new CardProgramConditionsService();
|
||||
}
|
||||
|
||||
public function actionCreate(): void
|
||||
{
|
||||
$this->cgView->render("form.php");
|
||||
}
|
||||
|
||||
#[NoReturn] public function actionAdd(): void
|
||||
{
|
||||
$cardForm = new CreateCardProgramConditionsForm();
|
||||
$cardForm->load($_REQUEST);
|
||||
|
||||
if ($cardForm->validate()){
|
||||
$cardProgramConditions = $this->cardProgramConditionsService->create($cardForm);
|
||||
if ($cardProgramConditions){
|
||||
Flash::setMessage("success", "Card program conditions created " . $cardProgramConditions->title);
|
||||
$this->redirect("/admin/card_program_conditions/" . $cardProgramConditions->id);
|
||||
}
|
||||
}
|
||||
|
||||
Flash::setMessage("error", $cardForm->getErrorsStr());
|
||||
$this->redirect("/admin/card_program_conditions/create");
|
||||
}
|
||||
|
||||
public function actionIndex($page_number = 1): void
|
||||
{
|
||||
$this->cgView->render("index.php", ['page_number' => $page_number]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws Exception
|
||||
*/
|
||||
public function actionView($id): void
|
||||
{
|
||||
$card_program = CardProgramConditions::find($id);
|
||||
|
||||
if (!$card_program){
|
||||
throw new Exception(message: "The card program conditions not found");
|
||||
}
|
||||
$this->cgView->render("view.php", ['card_program_conditions' => $card_program]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws Exception
|
||||
*/
|
||||
public function actionUpdate($id): void
|
||||
{
|
||||
$model = CardProgramConditions::find($id);
|
||||
if (!$model){
|
||||
throw new Exception(message: "The card program conditions not found");
|
||||
}
|
||||
|
||||
$this->cgView->render("form.php", ['model' => $model]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws Exception
|
||||
*/
|
||||
public function actionEdit($id): void
|
||||
{
|
||||
$cardProgramConditions = CardProgramConditions::find($id);
|
||||
if (!$cardProgramConditions){
|
||||
throw new Exception(message: "The card program conditions not found");
|
||||
}
|
||||
$cardProgramConditionsForm = new CreateCardProgramConditionsForm();
|
||||
$cardProgramConditionsForm->load($_REQUEST);
|
||||
|
||||
if ($cardProgramConditionsForm->validate()) {
|
||||
$card = $this->cardProgramConditionsService->update($cardProgramConditionsForm, $cardProgramConditions);
|
||||
if ($card) {
|
||||
Flash::setMessage("success", "Card program updated " . $cardProgramConditions->title);
|
||||
$this->redirect("/admin/card_program_conditions/" . $card->id);
|
||||
}
|
||||
}
|
||||
Flash::setMessage("error", $cardProgramConditionsForm->getErrorsStr());
|
||||
|
||||
$this->redirect("/admin/card_program_conditions/update/" . $id);
|
||||
}
|
||||
|
||||
#[NoReturn] public function actionDelete($id): void
|
||||
{
|
||||
$card_program = CardProgramConditions::where("id", $id)->first();
|
||||
if (!$card_program){
|
||||
Flash::setMessage("error", "Card program conditions not found");
|
||||
}
|
||||
else {
|
||||
Flash::setMessage("success", "Card program conditions deleted");
|
||||
$card_program->delete();
|
||||
}
|
||||
|
||||
$this->redirect("/admin/card_program_conditions/");
|
||||
}
|
||||
|
||||
}
|
123
kernel/app_modules/card/controllers/CardProgramController.php
Normal file
123
kernel/app_modules/card/controllers/CardProgramController.php
Normal file
@ -0,0 +1,123 @@
|
||||
<?php
|
||||
|
||||
namespace kernel\app_modules\card\controllers;
|
||||
|
||||
use Exception;
|
||||
use JetBrains\PhpStorm\NoReturn;
|
||||
use kernel\AdminController;
|
||||
use kernel\app_modules\card\models\CardProgram;
|
||||
use kernel\app_modules\card\models\CardTemplate;
|
||||
use kernel\app_modules\card\models\forms\CreateCardProgramForm;
|
||||
use kernel\app_modules\card\models\forms\CreateCardTemplateForm;
|
||||
use kernel\app_modules\card\services\CardProgramService;
|
||||
use kernel\app_modules\card\services\CardService;
|
||||
use kernel\app_modules\card\services\CardTemplateService;
|
||||
use kernel\FileUpload;
|
||||
use kernel\Flash;
|
||||
use kernel\helpers\Debug;
|
||||
|
||||
class CardProgramController extends AdminController
|
||||
{
|
||||
private CardService $cardService;
|
||||
private CardProgramService $cardProgramService;
|
||||
|
||||
protected function init(): void
|
||||
{
|
||||
parent::init();
|
||||
$this->cgView->viewPath = KERNEL_APP_MODULES_DIR . "/card/views/card_program/";
|
||||
$this->cardService = new CardService();
|
||||
$this->cardProgramService = new CardProgramService();
|
||||
}
|
||||
|
||||
public function actionCreate(): void
|
||||
{
|
||||
$this->cgView->render("form.php");
|
||||
}
|
||||
|
||||
#[NoReturn] public function actionAdd(): void
|
||||
{
|
||||
$cardForm = new CreateCardProgramForm();
|
||||
$cardForm->load($_REQUEST);
|
||||
|
||||
if ($cardForm->validate()){
|
||||
$cardProgram = $this->cardProgramService->create($cardForm);
|
||||
if ($cardProgram){
|
||||
Flash::setMessage("success", "Card program creates " . $cardProgram->title);
|
||||
$this->redirect("/admin/card_program/" . $cardProgram->id);
|
||||
}
|
||||
}
|
||||
|
||||
Flash::setMessage("error", $cardForm->getErrorsStr());
|
||||
$this->redirect("/admin/card_program/create");
|
||||
}
|
||||
|
||||
public function actionIndex($page_number = 1): void
|
||||
{
|
||||
$this->cgView->render("index.php", ['page_number' => $page_number]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws Exception
|
||||
*/
|
||||
public function actionView($id): void
|
||||
{
|
||||
$card_program = CardProgram::find($id);
|
||||
|
||||
if (!$card_program){
|
||||
throw new Exception(message: "The card program not found");
|
||||
}
|
||||
$this->cgView->render("view.php", ['card_program' => $card_program]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws Exception
|
||||
*/
|
||||
public function actionUpdate($id): void
|
||||
{
|
||||
$model = CardProgram::find($id);
|
||||
if (!$model){
|
||||
throw new Exception(message: "The card program not found");
|
||||
}
|
||||
|
||||
$this->cgView->render("form.php", ['model' => $model]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws Exception
|
||||
*/
|
||||
public function actionEdit($id): void
|
||||
{
|
||||
$cardProgram = CardProgram::find($id);
|
||||
if (!$cardProgram){
|
||||
throw new Exception(message: "The card not found");
|
||||
}
|
||||
$cardProgramForm = new CreateCardProgramForm();
|
||||
$cardProgramForm->load($_REQUEST);
|
||||
|
||||
if ($cardProgramForm->validate()) {
|
||||
$card = $this->cardProgramService->update($cardProgramForm, $cardProgram);
|
||||
if ($card) {
|
||||
Flash::setMessage("success", "Card program updated " . $cardProgram->title);
|
||||
$this->redirect("/admin/card_program/" . $card->id);
|
||||
}
|
||||
}
|
||||
Flash::setMessage("error", $cardProgramForm->getErrorsStr());
|
||||
|
||||
$this->redirect("/admin/card_program/update/" . $id);
|
||||
}
|
||||
|
||||
#[NoReturn] public function actionDelete($id): void
|
||||
{
|
||||
$card_program = CardProgram::where("id", $id)->first();
|
||||
if (!$card_program){
|
||||
Flash::setMessage("error", "Card program not found");
|
||||
}
|
||||
else {
|
||||
Flash::setMessage("success", "Card program deleted");
|
||||
$card_program->delete();
|
||||
}
|
||||
|
||||
$this->redirect("/admin/card_program/");
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,120 @@
|
||||
<?php
|
||||
|
||||
namespace kernel\app_modules\card\controllers;
|
||||
|
||||
use Exception;
|
||||
use JetBrains\PhpStorm\NoReturn;
|
||||
use kernel\AdminController;
|
||||
use kernel\app_modules\card\models\CardTemplate;
|
||||
use kernel\app_modules\card\models\CardTransaction;
|
||||
use kernel\app_modules\card\models\forms\CreateCardTemplateForm;
|
||||
use kernel\app_modules\card\models\forms\CreateCardTransactionForm;
|
||||
use kernel\app_modules\card\services\CardService;
|
||||
use kernel\app_modules\card\services\CardTemplateService;
|
||||
use kernel\app_modules\card\services\CardTransactionService;
|
||||
use kernel\FileUpload;
|
||||
use kernel\Flash;
|
||||
|
||||
class CardTransactionController extends AdminController
|
||||
{
|
||||
private CardTransactionService $cardTransactionService;
|
||||
|
||||
protected function init(): void
|
||||
{
|
||||
parent::init();
|
||||
$this->cgView->viewPath = KERNEL_APP_MODULES_DIR . "/card/views/card_transaction/";
|
||||
$this->cardTransactionService = new CardTransactionService();
|
||||
}
|
||||
|
||||
public function actionCreate(): void
|
||||
{
|
||||
$this->cgView->render("form.php");
|
||||
}
|
||||
|
||||
#[NoReturn] public function actionAdd(): void
|
||||
{
|
||||
$cardForm = new CreateCardTransactionForm();
|
||||
$cardForm->load($_REQUEST);
|
||||
|
||||
if ($cardForm->validate()){
|
||||
$cardTransaction = $this->cardTransactionService->create($cardForm);
|
||||
if ($cardTransaction){
|
||||
Flash::setMessage("success", "Card transaction created");
|
||||
$this->redirect("/admin/card_transaction/" . $cardTransaction->id);
|
||||
}
|
||||
Flash::setMessage("error", $this->cardTransactionService->getErrorsString());
|
||||
$this->redirect("/admin/card_transaction/create");
|
||||
}
|
||||
|
||||
Flash::setMessage("error", $cardForm->getErrorsStr());
|
||||
$this->redirect("/admin/card_transaction/create");
|
||||
}
|
||||
|
||||
public function actionIndex($page_number = 1): void
|
||||
{
|
||||
$this->cgView->render("index.php", ['page_number' => $page_number]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws Exception
|
||||
*/
|
||||
public function actionView($id): void
|
||||
{
|
||||
$card = CardTransaction::find($id);
|
||||
|
||||
if (!$card){
|
||||
throw new Exception(message: "The card transaction not found");
|
||||
}
|
||||
$this->cgView->render("view.php", ['card_transaction' => $card]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws Exception
|
||||
*/
|
||||
public function actionUpdate($id): void
|
||||
{
|
||||
$model = CardTransaction::find($id);
|
||||
if (!$model){
|
||||
throw new Exception(message: "The card transaction not found");
|
||||
}
|
||||
|
||||
$this->cgView->render("form.php", ['model' => $model]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws Exception
|
||||
*/
|
||||
public function actionEdit($id): void
|
||||
{
|
||||
$cardTransaction = CardTransaction::find($id);
|
||||
if (!$cardTransaction){
|
||||
throw new Exception(message: "The card transaction not found");
|
||||
}
|
||||
$cardTransactionForm = new CreateCardTransactionForm();
|
||||
$cardTransactionForm->load($_REQUEST);
|
||||
|
||||
if ($cardTransactionForm->validateForUpdate()) {
|
||||
$card = $this->cardTransactionService->update($cardTransactionForm, $cardTransaction);
|
||||
if ($card) {
|
||||
$this->redirect("/admin/card_transaction/" . $card->id);
|
||||
}
|
||||
}
|
||||
Flash::setMessage("error", $cardTransaction->getErrorsStr());
|
||||
|
||||
$this->redirect("/admin/card_transaction/update/" . $id);
|
||||
}
|
||||
|
||||
#[NoReturn] public function actionDelete($id): void
|
||||
{
|
||||
$card = CardTemplate::where("id", $id)->first();
|
||||
if (!$card){
|
||||
Flash::setMessage("error", "Card transaction not found");
|
||||
}
|
||||
else {
|
||||
$card->delete();
|
||||
}
|
||||
|
||||
$this->redirect("/admin/card_template/");
|
||||
}
|
||||
|
||||
}
|
@ -16,6 +16,7 @@ return new class extends Migration
|
||||
$table->increments('id')->from(105545);
|
||||
$table->string('path')->nullable(false);
|
||||
$table->string('title')->nullable(false);
|
||||
$table->text('settings')->nullable();
|
||||
|
||||
$table->integer('status')->default(1);
|
||||
$table->timestamps();
|
||||
@ -30,6 +31,46 @@ return new class extends Migration
|
||||
$table->timestamps();
|
||||
});
|
||||
|
||||
\kernel\App::$db->schema->create('card_program', function (Blueprint $table) {
|
||||
$table->increments('id')->from(71);
|
||||
$table->string('slug')->nullable(false)->unique();
|
||||
$table->string('title')->nullable(false);
|
||||
|
||||
$table->integer('status')->default(1);
|
||||
$table->timestamps();
|
||||
});
|
||||
|
||||
\kernel\App::$db->schema->create('card_program_conditions', function (Blueprint $table) {
|
||||
$table->increments('id');
|
||||
$table->integer("card_program_id")->nullable(false);
|
||||
$table->string('slug')->nullable(false)->unique();
|
||||
$table->string('title')->nullable(false);
|
||||
$table->string('type')->nullable(false);
|
||||
$table->string('value');
|
||||
|
||||
$table->integer('status')->default(1);
|
||||
$table->timestamps();
|
||||
});
|
||||
|
||||
\kernel\App::$db->schema->create('card_card_program', function (Blueprint $table) {
|
||||
$table->increments('id');
|
||||
$table->string('card_program_id')->nullable(false);
|
||||
$table->string('card_id')->nullable(false);
|
||||
|
||||
$table->timestamps();
|
||||
});
|
||||
|
||||
\kernel\App::$db->schema->create('card_transaction', function (Blueprint $table) {
|
||||
$table->increments('id');
|
||||
$table->integer('from')->nullable(false);
|
||||
$table->integer('to')->nullable(false);
|
||||
$table->integer('amount')->nullable(false);
|
||||
$table->integer('type')->nullable(false)->default(1);
|
||||
|
||||
$table->integer('status')->default(1);
|
||||
$table->timestamps();
|
||||
});
|
||||
|
||||
\kernel\App::$db->schema->create('card', function (Blueprint $table) {
|
||||
$table->increments('id')->from(105545);
|
||||
$table->integer('user_id')->nullable(false);
|
||||
@ -56,6 +97,9 @@ return new class extends Migration
|
||||
{
|
||||
\kernel\App::$db->schema->dropIfExists('card');
|
||||
\kernel\App::$db->schema->dropIfExists('card_template');
|
||||
\kernel\App::$db->schema->dropIfExists('card_card_program');
|
||||
\kernel\App::$db->schema->dropIfExists('card_program_conditions');
|
||||
\kernel\App::$db->schema->dropIfExists('card_program');
|
||||
\kernel\App::$db->schema->dropIfExists('card_file');
|
||||
}
|
||||
};
|
||||
|
@ -0,0 +1,29 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
public string $migration;
|
||||
/**
|
||||
* Run the migrations.
|
||||
*/
|
||||
public function up(): void
|
||||
{
|
||||
\kernel\App::$db->schema->table('card', function(Blueprint $table) {
|
||||
$table->renameColumn('program', 'card_program_id');
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
\kernel\App::$db->schema->table('card', function(Blueprint $table) {
|
||||
$table->renameColumn('card_program_id', 'program');
|
||||
});
|
||||
}
|
||||
};
|
@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
public string $migration;
|
||||
/**
|
||||
* Run the migrations.
|
||||
*/
|
||||
public function up(): void
|
||||
{
|
||||
\kernel\App::$db->schema->table('card_transaction', function(Blueprint $table) {
|
||||
$table->integer("from_balance")->after("from")->default(0);
|
||||
$table->integer("to_balance")->after("to")->default(0);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
\kernel\App::$db->schema->table('card_transaction', function(Blueprint $table) {
|
||||
$table->dropColumn("from_balance");
|
||||
$table->dropColumn("to_balance");
|
||||
});
|
||||
}
|
||||
};
|
@ -14,7 +14,7 @@ use kernel\modules\user\models\User;
|
||||
* @property int $payment_type
|
||||
* @property int $bank_id
|
||||
* @property int $info
|
||||
* @property int $program
|
||||
* @property int $card_program_id
|
||||
* @property int $cvc
|
||||
* @property int $pin
|
||||
* @property int $card_template_id
|
||||
@ -28,7 +28,7 @@ class Card extends Model
|
||||
|
||||
protected $table = 'card';
|
||||
|
||||
protected $fillable = ['user_id', 'payment_type', 'balance', 'bank_id', 'info', 'program', 'cvc', 'pin', 'username', 'card_template_id', 'card_file_id', 'status'];
|
||||
protected $fillable = ['user_id', 'payment_type', 'balance', 'bank_id', 'info', 'card_program_id', 'cvc', 'pin', 'username', 'card_template_id', 'card_file_id', 'status'];
|
||||
|
||||
public static function labels(): array
|
||||
{
|
||||
@ -46,7 +46,7 @@ class Card extends Model
|
||||
'balance' => 'Баланс',
|
||||
'bank_id' => 'ID банка',
|
||||
'info' => 'Информация о банке',
|
||||
'program' => 'Программа',
|
||||
'card_program_id' => 'Программа',
|
||||
'cvc' => 'CVC',
|
||||
'pin' => 'PIN',
|
||||
'username' => 'Username',
|
||||
@ -72,6 +72,11 @@ class Card extends Model
|
||||
return $this->belongsTo(CardTemplate::class);
|
||||
}
|
||||
|
||||
public function cardProgram(): \Illuminate\Database\Eloquent\Relations\BelongsTo
|
||||
{
|
||||
return $this->belongsTo(related: CardProgram::class);
|
||||
}
|
||||
|
||||
public function cardFile(): \Illuminate\Database\Eloquent\Relations\BelongsTo
|
||||
{
|
||||
return $this->belongsTo(CardFile::class);
|
||||
|
56
kernel/app_modules/card/models/CardProgram.php
Normal file
56
kernel/app_modules/card/models/CardProgram.php
Normal file
@ -0,0 +1,56 @@
|
||||
<?php
|
||||
|
||||
namespace kernel\app_modules\card\models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
/**
|
||||
* @property int $id;
|
||||
* @property string $slug;
|
||||
* @property string $title;
|
||||
* @property int $status;
|
||||
*/
|
||||
class CardProgram extends Model
|
||||
{
|
||||
|
||||
const DISABLE_STATUS = 0;
|
||||
const ACTIVE_STATUS = 1;
|
||||
|
||||
protected $table = 'card_program';
|
||||
|
||||
protected $fillable = ['slug', 'title', 'status'];
|
||||
|
||||
public static function labels(): array
|
||||
{
|
||||
// Заполнить массив
|
||||
// Пример: [
|
||||
// 'label' => 'Заголовок',
|
||||
// 'entity' => 'Сущность',
|
||||
// 'slug' => 'Slug',
|
||||
// 'status' => 'Статус',
|
||||
// ]
|
||||
|
||||
return [
|
||||
'slug' => 'Slug',
|
||||
'title' => 'Название',
|
||||
'status' => 'Статус',
|
||||
];
|
||||
}
|
||||
|
||||
public function cardProgramConditions(): \Illuminate\Database\Eloquent\Relations\HasMany
|
||||
{
|
||||
return $this->hasMany(CardProgramConditions::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string[]
|
||||
*/
|
||||
public static function getStatus(): array
|
||||
{
|
||||
return [
|
||||
self::DISABLE_STATUS => "Не активный",
|
||||
self::ACTIVE_STATUS => "Активный",
|
||||
];
|
||||
}
|
||||
|
||||
}
|
57
kernel/app_modules/card/models/CardProgramConditions.php
Normal file
57
kernel/app_modules/card/models/CardProgramConditions.php
Normal file
@ -0,0 +1,57 @@
|
||||
<?php
|
||||
|
||||
namespace kernel\app_modules\card\models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
/**
|
||||
* @property int $id;
|
||||
* @property int $card_program_id;
|
||||
* @property string $slug;
|
||||
* @property string $title;
|
||||
* @property string $value;
|
||||
* @property string $type;
|
||||
* @property int $status;
|
||||
*/
|
||||
class CardProgramConditions extends Model
|
||||
{
|
||||
|
||||
const DISABLE_STATUS = 0;
|
||||
const ACTIVE_STATUS = 1;
|
||||
|
||||
protected $table = 'card_program_conditions';
|
||||
|
||||
protected $fillable = ['card_program_id', 'slug', 'title', 'value', 'type', 'status'];
|
||||
|
||||
public static function labels(): array
|
||||
{
|
||||
// Заполнить массив
|
||||
// Пример: [
|
||||
// 'label' => 'Заголовок',
|
||||
// 'entity' => 'Сущность',
|
||||
// 'slug' => 'Slug',
|
||||
// 'status' => 'Статус',
|
||||
// ]
|
||||
|
||||
return [
|
||||
'card_program_id' => 'Программа',
|
||||
'slug' => 'Slug',
|
||||
'title' => 'Название',
|
||||
'value' => 'Условия',
|
||||
'type' => 'Тип',
|
||||
'status' => 'Статус',
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string[]
|
||||
*/
|
||||
public static function getStatus(): array
|
||||
{
|
||||
return [
|
||||
self::DISABLE_STATUS => "Не активный",
|
||||
self::ACTIVE_STATUS => "Активный",
|
||||
];
|
||||
}
|
||||
|
||||
}
|
@ -7,6 +7,7 @@ use Illuminate\Database\Eloquent\Model;
|
||||
/**
|
||||
* @property string $path
|
||||
* @property string $title
|
||||
* @property string $settings
|
||||
* @property int $status
|
||||
*/
|
||||
class CardTemplate extends Model
|
||||
@ -17,7 +18,7 @@ class CardTemplate extends Model
|
||||
|
||||
protected $table = 'card_template';
|
||||
|
||||
protected $fillable = ['path', 'title', 'status'];
|
||||
protected $fillable = ['path', 'title', 'status', 'settings'];
|
||||
|
||||
public static function labels(): array
|
||||
{
|
||||
@ -32,6 +33,7 @@ class CardTemplate extends Model
|
||||
return [
|
||||
'path' => 'Шаблон',
|
||||
'title' => 'Название',
|
||||
'settings' => 'Настройки',
|
||||
'status' => 'Статус',
|
||||
];
|
||||
}
|
||||
|
63
kernel/app_modules/card/models/CardTransaction.php
Normal file
63
kernel/app_modules/card/models/CardTransaction.php
Normal file
@ -0,0 +1,63 @@
|
||||
<?php
|
||||
|
||||
namespace kernel\app_modules\card\models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
/**
|
||||
* @property integer $from
|
||||
* @property integer $to
|
||||
* @property integer $from_balance
|
||||
* @property integer $to_balance
|
||||
* @property integer $amount
|
||||
* @property integer $type
|
||||
* @property integer $status
|
||||
*/
|
||||
class CardTransaction extends Model
|
||||
{
|
||||
|
||||
const DISABLE_STATUS = 0;
|
||||
const SUCCESS_STATUS = 1;
|
||||
const IN_PROGRESS_STATUS = 2;
|
||||
|
||||
protected $table = 'card_transaction';
|
||||
|
||||
protected $fillable = ['from', 'from_balance', 'to', 'to_balance', 'amount', 'type', 'status'];
|
||||
|
||||
public static function labels(): array
|
||||
{
|
||||
// Заполнить массив
|
||||
// Пример: [
|
||||
// 'label' => 'Заголовок',
|
||||
// 'entity' => 'Сущность',
|
||||
// 'slug' => 'Slug',
|
||||
// 'status' => 'Статус',
|
||||
// ]
|
||||
|
||||
return [
|
||||
'from' => 'От',
|
||||
'to' => 'Кому',
|
||||
'amount' => 'Количество',
|
||||
'type' => 'Тип операции',
|
||||
'status' => 'Статус',
|
||||
];
|
||||
}
|
||||
|
||||
public function fromCard(): \Illuminate\Database\Eloquent\Relations\BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Card::class, ownerKey: "from");
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string[]
|
||||
*/
|
||||
public static function getStatus(): array
|
||||
{
|
||||
return [
|
||||
self::DISABLE_STATUS => "Не активный",
|
||||
self::SUCCESS_STATUS => "Завершен",
|
||||
self::IN_PROGRESS_STATUS => "В процессе",
|
||||
];
|
||||
}
|
||||
|
||||
}
|
@ -23,10 +23,10 @@ class CreateCardForm extends FormModel
|
||||
'balance' => 'alpha-numeric',
|
||||
'bank_id' => 'required|alpha-numeric',
|
||||
'info' => 'required|alpha-numeric',
|
||||
'program' => 'required|alpha-numeric',
|
||||
'card_program_id' => 'required|alpha-numeric',
|
||||
'cvc' => 'required|alpha-numeric',
|
||||
'pin' => 'required|alpha-numeric',
|
||||
'username' => 'required|min-str-len:5|max-str-len:20',
|
||||
'username' => 'required|min-str-len:5|max-str-len:30',
|
||||
'card_template_id' => 'required|alpha-numeric',
|
||||
'card_file_id' => 'alpha-numeric',
|
||||
'status' => '',
|
||||
|
@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
namespace kernel\app_modules\card\models\forms;
|
||||
|
||||
use kernel\FormModel;
|
||||
|
||||
class CreateCardProgramConditionsForm extends FormModel
|
||||
{
|
||||
|
||||
public function rules(): array
|
||||
{
|
||||
// Заполнить массив правил
|
||||
// Пример:
|
||||
// return [
|
||||
// 'label' => 'required|min-str-len:5|max-str-len:30',
|
||||
// 'entity' => 'required',
|
||||
// 'slug' => '',
|
||||
// 'status' => ''
|
||||
// ];
|
||||
return [
|
||||
'card_program_id' => 'required|alpha-numeric',
|
||||
'slug' => 'required|min-str-len:4',
|
||||
'title' => 'required',
|
||||
'type' => 'required',
|
||||
'value' => '',
|
||||
'status' => ''
|
||||
];
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,27 @@
|
||||
<?php
|
||||
|
||||
namespace kernel\app_modules\card\models\forms;
|
||||
|
||||
use kernel\FormModel;
|
||||
|
||||
class CreateCardProgramForm extends FormModel
|
||||
{
|
||||
|
||||
public function rules(): array
|
||||
{
|
||||
// Заполнить массив правил
|
||||
// Пример:
|
||||
// return [
|
||||
// 'label' => 'required|min-str-len:5|max-str-len:30',
|
||||
// 'entity' => 'required',
|
||||
// 'slug' => '',
|
||||
// 'status' => ''
|
||||
// ];
|
||||
return [
|
||||
'slug' => 'required|min-str-len:4',
|
||||
'title' => 'required',
|
||||
'status' => ''
|
||||
];
|
||||
}
|
||||
|
||||
}
|
@ -20,6 +20,7 @@ class CreateCardTemplateForm extends FormModel
|
||||
return [
|
||||
'path' => 'required|min-str-len:4',
|
||||
'title' => 'required',
|
||||
'settings' => 'min-str-len:4',
|
||||
'status' => ''
|
||||
];
|
||||
}
|
||||
@ -29,6 +30,7 @@ class CreateCardTemplateForm extends FormModel
|
||||
return [
|
||||
'path' => '',
|
||||
'title' => 'required',
|
||||
'settings' => 'min-str-len:4',
|
||||
'status' => ''
|
||||
];
|
||||
}
|
||||
|
@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
namespace kernel\app_modules\card\models\forms;
|
||||
|
||||
use kernel\FormModel;
|
||||
|
||||
class CreateCardTransactionForm extends FormModel
|
||||
{
|
||||
|
||||
public function rules(): array
|
||||
{
|
||||
// Заполнить массив правил
|
||||
// Пример:
|
||||
// return [
|
||||
// 'label' => 'required|min-str-len:5|max-str-len:30',
|
||||
// 'entity' => 'required',
|
||||
// 'slug' => '',
|
||||
// 'status' => ''
|
||||
// ];
|
||||
return [
|
||||
'from' => 'required|alpha-numeric',
|
||||
'from_balance' => 'alpha-numeric',
|
||||
'to' => 'required|alpha-numeric',
|
||||
'to_balance' => 'alpha-numeric',
|
||||
'amount' => 'required|alpha-numeric',
|
||||
'type' => 'required|alpha-numeric',
|
||||
'status' => ''
|
||||
];
|
||||
}
|
||||
|
||||
}
|
@ -34,6 +34,51 @@ App::$collector->group(["prefix" => "admin"], function (CgRouteCollector $router
|
||||
});
|
||||
});
|
||||
|
||||
App::$collector->group(["prefix" => "admin"], function (CgRouteCollector $router) {
|
||||
App::$collector->group(["before" => "auth"], function (RouteCollector $router) {
|
||||
App::$collector->group(["prefix" => "card_program"], function (CGRouteCollector $router) {
|
||||
App::$collector->get('/', [\kernel\app_modules\card\controllers\CardProgramController::class, 'actionIndex']);
|
||||
App::$collector->get('/page/{page_number}', [\kernel\app_modules\card\controllers\CardProgramController::class, 'actionIndex']);
|
||||
App::$collector->get('/create', [\kernel\app_modules\card\controllers\CardProgramController::class, 'actionCreate']);
|
||||
App::$collector->post("/", [\kernel\app_modules\card\controllers\CardProgramController::class, 'actionAdd']);
|
||||
App::$collector->get('/{id}', [\kernel\app_modules\card\controllers\CardProgramController::class, 'actionView']);
|
||||
App::$collector->any('/update/{id}', [\kernel\app_modules\card\controllers\CardProgramController::class, 'actionUpdate']);
|
||||
App::$collector->any("/edit/{id}", [\kernel\app_modules\card\controllers\CardProgramController::class, 'actionEdit']);
|
||||
App::$collector->get('/delete/{id}', [\kernel\app_modules\card\controllers\CardProgramController::class, 'actionDelete']);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
App::$collector->group(["prefix" => "admin"], function (CgRouteCollector $router) {
|
||||
App::$collector->group(["before" => "auth"], function (RouteCollector $router) {
|
||||
App::$collector->group(["prefix" => "card_program_conditions"], function (CGRouteCollector $router) {
|
||||
App::$collector->get('/', [\kernel\app_modules\card\controllers\CardProgramConditionsController::class, 'actionIndex']);
|
||||
App::$collector->get('/page/{page_number}', [\kernel\app_modules\card\controllers\CardProgramConditionsController::class, 'actionIndex']);
|
||||
App::$collector->get('/create', [\kernel\app_modules\card\controllers\CardProgramConditionsController::class, 'actionCreate']);
|
||||
App::$collector->post("/", [\kernel\app_modules\card\controllers\CardProgramConditionsController::class, 'actionAdd']);
|
||||
App::$collector->get('/{id}', [\kernel\app_modules\card\controllers\CardProgramConditionsController::class, 'actionView']);
|
||||
App::$collector->any('/update/{id}', [\kernel\app_modules\card\controllers\CardProgramConditionsController::class, 'actionUpdate']);
|
||||
App::$collector->any("/edit/{id}", [\kernel\app_modules\card\controllers\CardProgramConditionsController::class, 'actionEdit']);
|
||||
App::$collector->get('/delete/{id}', [\kernel\app_modules\card\controllers\CardProgramConditionsController::class, 'actionDelete']);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
App::$collector->group(["prefix" => "admin"], function (CgRouteCollector $router) {
|
||||
App::$collector->group(["before" => "auth"], function (RouteCollector $router) {
|
||||
App::$collector->group(["prefix" => "card_transaction"], function (CGRouteCollector $router) {
|
||||
App::$collector->get('/', [\kernel\app_modules\card\controllers\CardTransactionController::class, 'actionIndex']);
|
||||
App::$collector->get('/page/{page_number}', [\kernel\app_modules\card\controllers\CardTransactionController::class, 'actionIndex']);
|
||||
App::$collector->get('/create', [\kernel\app_modules\card\controllers\CardTransactionController::class, 'actionCreate']);
|
||||
App::$collector->post("/", [\kernel\app_modules\card\controllers\CardTransactionController::class, 'actionAdd']);
|
||||
App::$collector->get('/{id}', [\kernel\app_modules\card\controllers\CardTransactionController::class, 'actionView']);
|
||||
App::$collector->any('/update/{id}', [\kernel\app_modules\card\controllers\CardTransactionController::class, 'actionUpdate']);
|
||||
App::$collector->any("/edit/{id}", [\kernel\app_modules\card\controllers\CardTransactionController::class, 'actionEdit']);
|
||||
App::$collector->get('/delete/{id}', [\kernel\app_modules\card\controllers\CardTransactionController::class, 'actionDelete']);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
App::$collector->group(["prefix" => "api"], function (CgRouteCollector $router){
|
||||
App::$collector->group(['before' => 'bearer'], function (CgRouteCollector $router){
|
||||
$router->rest("card", [\kernel\app_modules\card\controllers\CardRestController::class]);
|
||||
|
@ -8,6 +8,7 @@ use DragonCode\CardNumber\Formatters\BankFormatter;
|
||||
use kernel\app_modules\card\models\Card;
|
||||
use kernel\app_modules\card\models\CardFile;
|
||||
use kernel\FormModel;
|
||||
use kernel\helpers\Debug;
|
||||
use kernel\helpers\ImageGD;
|
||||
use Endroid\QrCode\Color\Color;
|
||||
use Endroid\QrCode\Encoding\Encoding;
|
||||
@ -51,12 +52,12 @@ class CardFileService
|
||||
return false;
|
||||
}
|
||||
|
||||
public static function createCardPNG(Card $card): false|string
|
||||
public static function createCardPNG(Card $card, bool $returnBase64 = false): false|string
|
||||
{
|
||||
if ($card->cardTemplate) {
|
||||
$formatter = BankFormatter::create();
|
||||
|
||||
$customer = BankFactory::create()->paymentType($card->payment_type)->bank($card->bank_id, $card->info, $card->program)->client($card->id);
|
||||
$customer = BankFactory::create()->paymentType($card->payment_type)->bank($card->bank_id, $card->info, $card->card_program_id)->client($card->id);
|
||||
|
||||
$cardNumber = CardNumber::generate($customer, $formatter);
|
||||
//Card
|
||||
@ -64,35 +65,65 @@ class CardFileService
|
||||
$uploadDir = "/resources/cards/";
|
||||
$uploadDirUri = $uploadDir . mb_substr($newFileName, 0, 2) . '/' . mb_substr($newFileName, 2, 2) . '/';
|
||||
$oldMask = umask(0);
|
||||
mkdir(ROOT_DIR . $uploadDirUri, 0775, true);
|
||||
if (!file_exists(ROOT_DIR . $uploadDirUri)){
|
||||
mkdir(ROOT_DIR . $uploadDirUri, 0775, true);
|
||||
}
|
||||
umask($oldMask);
|
||||
$uploadFileDir = ROOT_DIR . $uploadDirUri;
|
||||
|
||||
$img = ROOT_DIR . "/" . $card->cardTemplate->path; // Ссылка на файл
|
||||
$font = RESOURCES_DIR . "/tmp/arialmt.ttf"; // Ссылка на шрифт
|
||||
$cardSettings = json_decode($card->cardTemplate->settings ?? "", true);
|
||||
|
||||
$qr = self::createQr($card->id);
|
||||
$img = ROOT_DIR . "/" . $card->cardTemplate->path; // Ссылка на файл
|
||||
$font = RESOURCES_DIR . "/Montserrat-SemiBold.ttf"; // Ссылка на шрифт
|
||||
|
||||
$qr = self::createQr($card->id, $cardSettings['qr_size'] ?? 131);
|
||||
$qrImg = new ImageGD($qr->getDataUri());
|
||||
$img = new ImageGD($img);
|
||||
|
||||
$pngFilePath = RESOURCES_DIR . "/tmp/" . $card->id . ".png";
|
||||
$pngFileUrl = "/resources/tmp/" . $card->id . ".png";
|
||||
|
||||
$img->addText(font_size: 14, degree: 0, x: 15, y: 25, color: "#000000", font: $font, text: "KO coin");
|
||||
$img->addText(font_size: 14, degree: 0, x: 15, y: 45, color: "#000000", font: $font, text: "BGroup\ITGuild");
|
||||
$img->addText(font_size: 14, degree: 0, x: 15, y: 65, color: "#000000", font: $font, text: $card->cardTemplate->title . " card");
|
||||
$img->addText(font_size: 18, degree: 0, x: 15, y: 180, color: "#000000", font: $font, text: $cardNumber);
|
||||
$img->addText(font_size: 12, degree: 0, x: 15, y: 200, color: "#000000", font: $font, text: $card->username);
|
||||
$img->addImg($qrImg->getImg(), 200, 15, 0, 0, 124, 124, 100);
|
||||
$img->save($uploadFileDir . $newFileName);
|
||||
$img->addText(
|
||||
font_size: 20,
|
||||
degree: 0,
|
||||
x: 15,
|
||||
y: 190,
|
||||
color: $cardSettings['card_number_color'] ?? "#ffffff",
|
||||
font: $font,
|
||||
text: $cardNumber
|
||||
);
|
||||
$img->addText(
|
||||
font_size: 12,
|
||||
degree: 0,
|
||||
x: 15,
|
||||
y: 210,
|
||||
color: $cardSettings['card_name_color'] ?? "#FEE62F",
|
||||
font: $font,
|
||||
text: $card->username
|
||||
);
|
||||
$img->addImg($qrImg->getImg(),
|
||||
$cardSettings['qr_location_x'] ?? 190,
|
||||
$cardSettings['qr_location_y'] ?? 20,
|
||||
0,
|
||||
0,
|
||||
$cardSettings['qr_box_width'] ?? 135,
|
||||
$cardSettings['qr_box_height'] ?? 135,
|
||||
100
|
||||
);
|
||||
if ($returnBase64){
|
||||
return $img->getBase64();
|
||||
}
|
||||
else {
|
||||
$img->save($uploadFileDir . $newFileName);
|
||||
|
||||
return $uploadDirUri . $newFileName;
|
||||
return $uploadDirUri . $newFileName;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public static function createQr(string|int $text): \Endroid\QrCode\Writer\Result\ResultInterface
|
||||
public static function createQr(string|int $text, int $size = 131): \Endroid\QrCode\Writer\Result\ResultInterface
|
||||
{
|
||||
$writer = new PngWriter();
|
||||
|
||||
@ -100,7 +131,7 @@ class CardFileService
|
||||
data: $text,
|
||||
encoding: new Encoding('UTF-8'),
|
||||
errorCorrectionLevel: ErrorCorrectionLevel::Low,
|
||||
size: 120,
|
||||
size: $size,
|
||||
margin: 2,
|
||||
roundBlockSizeMode: RoundBlockSizeMode::Margin,
|
||||
foregroundColor: new Color(0, 0, 0),
|
||||
|
@ -0,0 +1,48 @@
|
||||
<?php
|
||||
|
||||
namespace kernel\app_modules\card\services;
|
||||
|
||||
use kernel\app_modules\card\models\CardProgram;
|
||||
use kernel\app_modules\card\models\CardProgramConditions;
|
||||
use kernel\FormModel;
|
||||
|
||||
class CardProgramConditionsService
|
||||
{
|
||||
|
||||
public function create(FormModel $form_model): false|CardProgramConditions
|
||||
{
|
||||
$model = new CardProgramConditions();
|
||||
// Пример заполнения:
|
||||
$model->card_program_id = $form_model->getItem('card_program_id');
|
||||
$model->slug = $form_model->getItem('slug');
|
||||
$model->status = $form_model->getItem('status');
|
||||
$model->type = $form_model->getItem('type');
|
||||
$model->title = $form_model->getItem('title');
|
||||
$model->value = $form_model->getItem('value');
|
||||
// $model->slug = Slug::createSlug($form_model->getItem('title'), Card::class); // Генерация уникального slug
|
||||
|
||||
if ($model->save()) {
|
||||
return $model;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public function update(FormModel $form_model, CardProgramConditions $cardProgramConditions): false|CardProgramConditions
|
||||
{
|
||||
// Пример обновления:
|
||||
$cardProgramConditions->title = $form_model->getItem('title');
|
||||
$cardProgramConditions->slug = $form_model->getItem('slug');
|
||||
$cardProgramConditions->status = $form_model->getItem('status');
|
||||
$cardProgramConditions->type = $form_model->getItem('type');
|
||||
$cardProgramConditions->card_program_id = $form_model->getItem('card_program_id');
|
||||
$cardProgramConditions->value = $form_model->getItem('value');
|
||||
|
||||
if ($cardProgramConditions->save()) {
|
||||
return $cardProgramConditions;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
55
kernel/app_modules/card/services/CardProgramService.php
Normal file
55
kernel/app_modules/card/services/CardProgramService.php
Normal file
@ -0,0 +1,55 @@
|
||||
<?php
|
||||
|
||||
namespace kernel\app_modules\card\services;
|
||||
|
||||
use kernel\app_modules\card\models\CardProgram;
|
||||
use kernel\app_modules\card\models\CardTemplate;
|
||||
use kernel\FormModel;
|
||||
|
||||
class CardProgramService
|
||||
{
|
||||
|
||||
public function create(FormModel $form_model): false|CardProgram
|
||||
{
|
||||
$model = new CardProgram();
|
||||
// Пример заполнения:
|
||||
$model->slug = $form_model->getItem('slug');
|
||||
$model->status = $form_model->getItem('status');
|
||||
$model->title = $form_model->getItem('title');
|
||||
// $model->slug = Slug::createSlug($form_model->getItem('title'), Card::class); // Генерация уникального slug
|
||||
|
||||
if ($model->save()) {
|
||||
return $model;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public function update(FormModel $form_model, CardProgram $cardProgram): false|CardProgram
|
||||
{
|
||||
// Пример обновления:
|
||||
$cardProgram->title = $form_model->getItem('title');
|
||||
$cardProgram->slug = $form_model->getItem('slug');
|
||||
$cardProgram->status = $form_model->getItem('status');
|
||||
|
||||
if ($cardProgram->save()) {
|
||||
return $cardProgram;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public static function getProgramList(): array
|
||||
{
|
||||
$arr = [];
|
||||
foreach (CardProgram::all()->toArray() as $cardTemplate){
|
||||
$arr[$cardTemplate['id']] = $cardTemplate['title'];
|
||||
}
|
||||
if (!empty($arr)) {
|
||||
return $arr;
|
||||
}
|
||||
|
||||
return [];
|
||||
}
|
||||
|
||||
}
|
@ -5,18 +5,23 @@ namespace kernel\app_modules\card\services;
|
||||
use DragonCode\CardNumber\CardNumber;
|
||||
use DragonCode\CardNumber\Factories\BankFactory;
|
||||
use DragonCode\CardNumber\Formatters\BankFormatter;
|
||||
use kernel\app_modules\card\models\CardTransaction;
|
||||
use kernel\app_modules\card\models\forms\CreateCardTransactionForm;
|
||||
use kernel\helpers\Debug;
|
||||
use kernel\app_modules\card\models\Card;
|
||||
use kernel\FormModel;
|
||||
use kernel\helpers\ImageGD;
|
||||
use kernel\modules\user\models\User;
|
||||
|
||||
class CardService
|
||||
{
|
||||
protected CardFileService $cardFileService;
|
||||
protected CardTransactionService $cardTransactionService;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->cardFileService = new CardFileService();
|
||||
$this->cardTransactionService = new CardTransactionService();
|
||||
}
|
||||
|
||||
public function create(FormModel $form_model): false|Card
|
||||
@ -27,10 +32,10 @@ class CardService
|
||||
$model->payment_type = $form_model->getItem('payment_type') ?? 2;
|
||||
$model->bank_id = $form_model->getItem('bank_id') ?? 232;
|
||||
$model->info = $form_model->getItem('info') ?? 42;
|
||||
$model->program = $form_model->getItem('program') ?? 74;
|
||||
$model->card_program_id = $form_model->getItem('card_program_id') ?? 71;
|
||||
$model->balance = $form_model->getItem('balance') ?? 0;
|
||||
$model->cvc = $form_model->getItem('cvc');
|
||||
$model->pin = $form_model->getItem('pin');
|
||||
$model->cvc = $form_model->getItem('cvc') ?? 101;
|
||||
$model->pin = $form_model->getItem('pin') ?? 1111;
|
||||
$model->username = $form_model->getItem('username');
|
||||
$model->card_template_id = $form_model->getItem('card_template_id');
|
||||
$model->status = $form_model->getItem('status');
|
||||
@ -55,14 +60,17 @@ class CardService
|
||||
$card->payment_type = $form_model->getItem('payment_type');
|
||||
$card->bank_id = $form_model->getItem('bank_id');
|
||||
$card->info = $form_model->getItem('info');
|
||||
$card->program = $form_model->getItem('program');
|
||||
$card->card_program_id = $form_model->getItem('card_program_id');
|
||||
$card->balance = $form_model->getItem('balance');
|
||||
$card->cvc = $form_model->getItem('cvc');
|
||||
$card->pin = $form_model->getItem('pin');
|
||||
$card->username = $form_model->getItem('username');
|
||||
$card->status = $form_model->getItem('status');
|
||||
|
||||
if ($card->card_template_id !== (int)$form_model->getItem('card_template_id')) {
|
||||
if (
|
||||
$card->card_template_id !== (int)$form_model->getItem('card_template_id')
|
||||
or $card->program !== (int)$form_model->getItem('program')
|
||||
) {
|
||||
$card->card_template_id = $form_model->getItem('card_template_id');
|
||||
$cardFile = $this->cardFileService->create($card);
|
||||
if ($cardFile) {
|
||||
@ -77,12 +85,44 @@ class CardService
|
||||
return false;
|
||||
}
|
||||
|
||||
public static function addMoneyToCard(Card $card, int $amount): CardTransaction
|
||||
{
|
||||
$transactionForm = new CreateCardTransactionForm();
|
||||
$transactionForm->load([
|
||||
'from' => 1001,
|
||||
'to' => $card->id,
|
||||
'amount' => $amount,
|
||||
'type' => 1,
|
||||
'status' => 1,
|
||||
]);
|
||||
|
||||
$transactionService = new CardTransactionService();
|
||||
|
||||
return $transactionService->create($transactionForm);
|
||||
}
|
||||
|
||||
public static function withdrawMoneyFromCard(Card $card, int $amount): CardTransaction
|
||||
{
|
||||
$transactionForm = new CreateCardTransactionForm();
|
||||
$transactionForm->load([
|
||||
'from' => $card->id,
|
||||
'to' => 1001,
|
||||
'amount' => $amount,
|
||||
'type' => 1,
|
||||
'status' => 1,
|
||||
]);
|
||||
|
||||
$transactionService = new CardTransactionService();
|
||||
|
||||
return $transactionService->create($transactionForm);
|
||||
}
|
||||
|
||||
public static function createCardPNG(Card $card): false|string
|
||||
{
|
||||
if ($card->cardTemplate) {
|
||||
$formatter = BankFormatter::create();
|
||||
|
||||
$customer = BankFactory::create()->paymentType($card->payment_type)->bank($card->bank_id, $card->info, $card->program)->client($card->id);
|
||||
$customer = BankFactory::create()->paymentType($card->payment_type)->bank($card->bank_id, $card->info, $card->card_program_id)->client($card->id);
|
||||
|
||||
$cardNumber = CardNumber::generate($customer, $formatter);
|
||||
//Card
|
||||
@ -96,8 +136,8 @@ class CardService
|
||||
|
||||
$img->addText(font_size: 14, degree: 0, x: 15, y: 25, color: "#000000", font: $font, text: "KO coin");
|
||||
$img->addText(font_size: 14, degree: 0, x: 15, y: 45, color: "#000000", font: $font, text: "BGroup\ITGuild");
|
||||
$img->addText(font_size: 18, degree: 0, x: 15, y: 180, color: "#000000", font: $font, text: $cardNumber);
|
||||
$img->addText(font_size: 12, degree: 0, x: 15, y: 200, color: "#000000", font: $font, text: $card->username);
|
||||
$img->addText(font_size: 18, degree: 0, x: 15, y: 180, color: "#ffffff", font: $font, text: $cardNumber);
|
||||
$img->addText(font_size: 12, degree: 0, x: 15, y: 200, color: "#ffffff", font: $font, text: $card->username);
|
||||
$img->save($pngFilePath);
|
||||
|
||||
return $pngFileUrl;
|
||||
@ -105,4 +145,24 @@ class CardService
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public static function getCardById(int $id)
|
||||
{
|
||||
$card = Card::find($id);
|
||||
if ($card) {
|
||||
return $card;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public static function userHasCard(int $userId): bool
|
||||
{
|
||||
$card = Card::where("user_id", $userId)->first();
|
||||
if ($card) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
@ -14,6 +14,7 @@ class CardTemplateService
|
||||
$model = new CardTemplate();
|
||||
// Пример заполнения:
|
||||
$model->path = $form_model->getItem('path');
|
||||
$model->settings = $form_model->getItem('settings');
|
||||
$model->status = $form_model->getItem('status');
|
||||
$model->title = $form_model->getItem('title');
|
||||
// $model->slug = Slug::createSlug($form_model->getItem('title'), Card::class); // Генерация уникального slug
|
||||
@ -29,6 +30,7 @@ class CardTemplateService
|
||||
{
|
||||
// Пример обновления:
|
||||
$cardTemplate->title = $form_model->getItem('title');
|
||||
$cardTemplate->settings = $form_model->getItem('settings');
|
||||
$cardTemplate->path = $form_model->getItem('path') ?? $cardTemplate->path;
|
||||
$cardTemplate->status = $form_model->getItem('status');
|
||||
|
||||
|
110
kernel/app_modules/card/services/CardTransactionService.php
Normal file
110
kernel/app_modules/card/services/CardTransactionService.php
Normal file
@ -0,0 +1,110 @@
|
||||
<?php
|
||||
|
||||
namespace kernel\app_modules\card\services;
|
||||
|
||||
use kernel\app_modules\card\models\Card;
|
||||
use kernel\app_modules\card\models\CardTemplate;
|
||||
use kernel\app_modules\card\models\CardTransaction;
|
||||
use kernel\FormModel;
|
||||
|
||||
class CardTransactionService
|
||||
{
|
||||
protected array $errors = [];
|
||||
|
||||
public function create(FormModel $form_model): false|CardTransaction
|
||||
{
|
||||
$model = new CardTransaction();
|
||||
|
||||
$fromId = (int)$form_model->getItem('from');
|
||||
$toId = (int)$form_model->getItem('to');
|
||||
|
||||
if ($fromId !== 1001){
|
||||
$fromCard = Card::where("id", $form_model->getItem('from'))->first();
|
||||
if (!$fromCard){
|
||||
$this->errors[] = ["error_id" => 3, "error_msg" => "Sender not found"];
|
||||
return false;
|
||||
}
|
||||
$model->from_balance = $fromCard->balance;
|
||||
}
|
||||
|
||||
if ($toId !== 1001){
|
||||
$toCard = Card::where("id", $form_model->getItem('to'))->first();
|
||||
if (!$toCard){
|
||||
$this->errors[] = ["error_id" => 3, "error_msg" => "Recipient not found"];
|
||||
return false;
|
||||
}
|
||||
$model->to_balance = $toCard->balance;
|
||||
}
|
||||
|
||||
if ($fromId !== 1001){
|
||||
if ($fromCard->balance < $form_model->getItem('amount')){
|
||||
$this->errors[] = ["error_id" => 3, "error_msg" => "Insufficient funds of the sender"];
|
||||
}
|
||||
}
|
||||
|
||||
// Пример заполнения:
|
||||
$model->from = $form_model->getItem('from');
|
||||
$model->to = $form_model->getItem('to');
|
||||
$model->status = $form_model->getItem('status');
|
||||
$model->type = $form_model->getItem('type');
|
||||
$model->amount = $form_model->getItem('amount');
|
||||
// $model->slug = Slug::createSlug($form_model->getItem('title'), Card::class); // Генерация уникального slug
|
||||
|
||||
if ($model->save()) {
|
||||
if (isset($fromCard)){
|
||||
$fromCard->balance = $fromCard->balance - (int)$form_model->getItem('amount');
|
||||
$fromCard->save();
|
||||
}
|
||||
if (isset($toCard)){
|
||||
$toCard->balance = $toCard->balance + (int)$form_model->getItem('amount');
|
||||
$toCard->save();
|
||||
}
|
||||
|
||||
return $model;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public function update(FormModel $form_model, CardTransaction $cardTransaction): false|CardTransaction
|
||||
{
|
||||
$fromCard = Card::where("id", $form_model->getItem('from'))->first();
|
||||
if (!$fromCard){
|
||||
$this->errors[] = ["error_id" => 3, "error_msg" => "Sender not found"];
|
||||
return false;
|
||||
}
|
||||
|
||||
$toCard = Card::where("id", $form_model->getItem('to'))->first();
|
||||
if (!$toCard){
|
||||
$this->errors[] = ["error_id" => 3, "error_msg" => "Recipient not found"];
|
||||
return false;
|
||||
}
|
||||
|
||||
if ($fromCard->balance < $form_model->getItem('amount')){
|
||||
$this->errors[] = ["error_id" => 3, "error_msg" => "Insufficient funds of the sender"];
|
||||
}
|
||||
// Пример обновления:
|
||||
$cardTransaction->from = $form_model->getItem('from');
|
||||
$cardTransaction->to = $form_model->getItem('to');
|
||||
$cardTransaction->amount = $form_model->getItem('amount');
|
||||
$cardTransaction->type = $form_model->getItem('type');
|
||||
$cardTransaction->status = $form_model->getItem('status');
|
||||
|
||||
if ($cardTransaction->save()) {
|
||||
return $cardTransaction;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public function getErrorsString(): string
|
||||
{
|
||||
$errStr = "";
|
||||
foreach ($this->errors as $error){
|
||||
$errStr .= $error['error_msg'] . ". ";
|
||||
}
|
||||
|
||||
return $errStr;
|
||||
}
|
||||
|
||||
}
|
64
kernel/app_modules/card/views/card_program/form.php
Normal file
64
kernel/app_modules/card/views/card_program/form.php
Normal file
@ -0,0 +1,64 @@
|
||||
<?php
|
||||
/**
|
||||
* @var \kernel\app_modules\card\models\CardProgram $model
|
||||
*/
|
||||
|
||||
use kernel\app_modules\card\models\Card;
|
||||
|
||||
$form = new \itguild\forms\ActiveForm();
|
||||
$form->beginForm(isset($model) ? "/admin/card_program/edit/" . $model->id : "/admin/card_program", 'multipart/form-data');
|
||||
|
||||
// Пример формы:
|
||||
|
||||
|
||||
$form->field(\itguild\forms\inputs\TextInput::class, 'title', [
|
||||
'class' => "form-control",
|
||||
'placeholder' => 'Название',
|
||||
'value' => $model->title ?? ''
|
||||
])
|
||||
->setLabel("Заголовок")
|
||||
->render();
|
||||
|
||||
$form->field(\itguild\forms\inputs\TextInput::class, 'slug', [
|
||||
'class' => "form-control",
|
||||
'placeholder' => 'Slug',
|
||||
'value' => $model->slug ?? ''
|
||||
])
|
||||
->setLabel("Slug")
|
||||
->render();
|
||||
|
||||
|
||||
$form->field(class: \itguild\forms\inputs\Select::class, name: "status", params: [
|
||||
'class' => "form-control",
|
||||
'value' => $model->status ?? ''
|
||||
])
|
||||
->setLabel("Статус")
|
||||
->setOptions(\kernel\app_modules\card\models\CardTemplate::getStatus())
|
||||
->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();
|
77
kernel/app_modules/card/views/card_program/index.php
Normal file
77
kernel/app_modules/card/views/card_program/index.php
Normal file
@ -0,0 +1,77 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @var \Illuminate\Database\Eloquent\Collection $card
|
||||
* @var int $page_number
|
||||
* @var \kernel\CgView $view
|
||||
*/
|
||||
|
||||
use kernel\app_modules\card\models\Card;
|
||||
use Itguild\EloquentTable\EloquentDataProvider;
|
||||
use Itguild\EloquentTable\ListEloquentTable;
|
||||
use kernel\widgets\IconBtn\IconBtnCreateWidget;
|
||||
use kernel\widgets\IconBtn\IconBtnDeleteWidget;
|
||||
use kernel\widgets\IconBtn\IconBtnEditWidget;
|
||||
use kernel\widgets\IconBtn\IconBtnViewWidget;
|
||||
|
||||
$view->setTitle("Список шаблонов card");
|
||||
$view->setMeta([
|
||||
'description' => 'Список шаблонов card системы'
|
||||
]);
|
||||
|
||||
//Для использования таблицы с моделью, необходимо создать таблицу в базе данных
|
||||
$table = new ListEloquentTable(new EloquentDataProvider(\kernel\app_modules\card\models\CardProgram::class, [
|
||||
'currentPage' => $page_number,
|
||||
'perPage' => 8,
|
||||
'params' => ["class" => "table table-bordered", "border" => "2"],
|
||||
'baseUrl' => "/admin/card_program"
|
||||
]));
|
||||
|
||||
|
||||
//$table = new \Itguild\Tables\ListJsonTable(json_encode(
|
||||
// [
|
||||
// 'meta' => [
|
||||
// 'total' => 0,
|
||||
// 'totalWithFilters' => 0,
|
||||
// 'columns' => [
|
||||
// 'title',
|
||||
// 'slug',
|
||||
// 'status',
|
||||
// ],
|
||||
// 'perPage' => 5,
|
||||
// 'currentPage' => 1,
|
||||
// 'baseUrl' => '/admin/some',
|
||||
// 'params' => [
|
||||
// 'class' => 'table table-bordered',
|
||||
// 'border' => 2
|
||||
// ]
|
||||
// ],
|
||||
// 'filters' => [],
|
||||
// 'data' => [],
|
||||
// ]
|
||||
//));
|
||||
|
||||
$table->beforePrint(function () {
|
||||
return IconBtnCreateWidget::create(['url' => '/admin/card_program/create'])->run();
|
||||
});
|
||||
|
||||
$table->columns([
|
||||
'status' => [
|
||||
'value' => function ($data) {
|
||||
return \kernel\app_modules\card\models\CardProgram::getStatus()[$data];
|
||||
}
|
||||
],
|
||||
|
||||
]);
|
||||
|
||||
$table->addAction(function($row) {
|
||||
return IconBtnViewWidget::create(['url' => '/admin/card_program/' . $row['id']])->run();
|
||||
});
|
||||
$table->addAction(function($row) {
|
||||
return IconBtnEditWidget::create(['url' => '/admin/card_program/update/' . $row['id']])->run();
|
||||
});
|
||||
$table->addAction(function($row) {
|
||||
return IconBtnDeleteWidget::create(['url' => '/admin/card_program/delete/' . $row['id']])->run();
|
||||
});
|
||||
$table->create();
|
||||
$table->render();
|
34
kernel/app_modules/card/views/card_program/view.php
Normal file
34
kernel/app_modules/card/views/card_program/view.php
Normal file
@ -0,0 +1,34 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @var \Illuminate\Database\Eloquent\Collection $card_program
|
||||
*/
|
||||
|
||||
use Itguild\EloquentTable\ViewEloquentTable;
|
||||
use Itguild\EloquentTable\ViewJsonTableEloquentModel;
|
||||
use kernel\widgets\IconBtn\IconBtnDeleteWidget;
|
||||
use kernel\widgets\IconBtn\IconBtnEditWidget;
|
||||
use kernel\widgets\IconBtn\IconBtnListWidget;
|
||||
|
||||
$table = new ViewEloquentTable(new ViewJsonTableEloquentModel($card_program, [
|
||||
'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];
|
||||
}
|
||||
]
|
||||
]);
|
||||
|
||||
$table->beforePrint(function () use ($card_program) {
|
||||
$btn = IconBtnListWidget::create(['url' => '/admin/card_program'])->run();
|
||||
$btn .= IconBtnEditWidget::create(['url' => '/admin/card_program/update/' . $card_program->id])->run();
|
||||
$btn .= IconBtnDeleteWidget::create(['url' => '/admin/card_program/delete/' . $card_program->id])->run();
|
||||
return $btn;
|
||||
});
|
||||
|
||||
$table->create();
|
||||
$table->render();
|
@ -0,0 +1,87 @@
|
||||
<?php
|
||||
/**
|
||||
* @var \kernel\app_modules\card\models\CardProgramConditions $model
|
||||
*/
|
||||
|
||||
use kernel\app_modules\card\models\Card;
|
||||
|
||||
$form = new \itguild\forms\ActiveForm();
|
||||
$form->beginForm(isset($model) ? "/admin/card_program_conditions/edit/" . $model->id : "/admin/card_program_conditions", 'multipart/form-data');
|
||||
|
||||
// Пример формы:
|
||||
|
||||
|
||||
$form->field(\itguild\forms\inputs\TextInput::class, 'title', [
|
||||
'class' => "form-control",
|
||||
'placeholder' => 'Название',
|
||||
'value' => $model->title ?? ''
|
||||
])
|
||||
->setLabel("Заголовок")
|
||||
->render();
|
||||
|
||||
$form->field(\itguild\forms\inputs\TextInput::class, 'slug', [
|
||||
'class' => "form-control",
|
||||
'placeholder' => 'Slug',
|
||||
'value' => $model->slug ?? ''
|
||||
])
|
||||
->setLabel("Slug")
|
||||
->render();
|
||||
|
||||
$form->field(\itguild\forms\inputs\TextInput::class, 'type', [
|
||||
'class' => "form-control",
|
||||
'placeholder' => 'Тип',
|
||||
'value' => $model->type ?? ''
|
||||
])
|
||||
->setLabel("Тип")
|
||||
->render();
|
||||
|
||||
$form->field(\itguild\forms\inputs\TextInput::class, 'value', [
|
||||
'class' => "form-control",
|
||||
'placeholder' => 'Значение',
|
||||
'value' => $model->value ?? ''
|
||||
])
|
||||
->setLabel("Значение")
|
||||
->render();
|
||||
|
||||
$form->field(class: \itguild\forms\inputs\Select::class, name: "card_program_id", params: [
|
||||
'class' => "form-control",
|
||||
'value' => $model->card_program_id ?? ''
|
||||
])
|
||||
->setLabel("Программа")
|
||||
->setOptions(\kernel\app_modules\card\services\CardProgramService::getProgramList())
|
||||
->render();
|
||||
|
||||
$form->field(class: \itguild\forms\inputs\Select::class, name: "status", params: [
|
||||
'class' => "form-control",
|
||||
'value' => $model->status ?? ''
|
||||
])
|
||||
->setLabel("Статус")
|
||||
->setOptions(\kernel\app_modules\card\models\CardTemplate::getStatus())
|
||||
->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();
|
@ -0,0 +1,77 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @var \Illuminate\Database\Eloquent\Collection $card
|
||||
* @var int $page_number
|
||||
* @var \kernel\CgView $view
|
||||
*/
|
||||
|
||||
use kernel\app_modules\card\models\Card;
|
||||
use Itguild\EloquentTable\EloquentDataProvider;
|
||||
use Itguild\EloquentTable\ListEloquentTable;
|
||||
use kernel\widgets\IconBtn\IconBtnCreateWidget;
|
||||
use kernel\widgets\IconBtn\IconBtnDeleteWidget;
|
||||
use kernel\widgets\IconBtn\IconBtnEditWidget;
|
||||
use kernel\widgets\IconBtn\IconBtnViewWidget;
|
||||
|
||||
$view->setTitle("Список условий");
|
||||
$view->setMeta([
|
||||
'description' => 'Список условий системы'
|
||||
]);
|
||||
|
||||
//Для использования таблицы с моделью, необходимо создать таблицу в базе данных
|
||||
$table = new ListEloquentTable(new EloquentDataProvider(\kernel\app_modules\card\models\CardProgramConditions::class, [
|
||||
'currentPage' => $page_number,
|
||||
'perPage' => 8,
|
||||
'params' => ["class" => "table table-bordered", "border" => "2"],
|
||||
'baseUrl' => "/admin/card_program_conditions"
|
||||
]));
|
||||
|
||||
|
||||
//$table = new \Itguild\Tables\ListJsonTable(json_encode(
|
||||
// [
|
||||
// 'meta' => [
|
||||
// 'total' => 0,
|
||||
// 'totalWithFilters' => 0,
|
||||
// 'columns' => [
|
||||
// 'title',
|
||||
// 'slug',
|
||||
// 'status',
|
||||
// ],
|
||||
// 'perPage' => 5,
|
||||
// 'currentPage' => 1,
|
||||
// 'baseUrl' => '/admin/some',
|
||||
// 'params' => [
|
||||
// 'class' => 'table table-bordered',
|
||||
// 'border' => 2
|
||||
// ]
|
||||
// ],
|
||||
// 'filters' => [],
|
||||
// 'data' => [],
|
||||
// ]
|
||||
//));
|
||||
|
||||
$table->beforePrint(function () {
|
||||
return IconBtnCreateWidget::create(['url' => '/admin/card_program_conditions/create'])->run();
|
||||
});
|
||||
|
||||
$table->columns([
|
||||
'status' => [
|
||||
'value' => function ($data) {
|
||||
return \kernel\app_modules\card\models\CardProgramConditions::getStatus()[$data];
|
||||
}
|
||||
],
|
||||
|
||||
]);
|
||||
|
||||
$table->addAction(function($row) {
|
||||
return IconBtnViewWidget::create(['url' => '/admin/card_program_conditions/' . $row['id']])->run();
|
||||
});
|
||||
$table->addAction(function($row) {
|
||||
return IconBtnEditWidget::create(['url' => '/admin/card_program_conditions/update/' . $row['id']])->run();
|
||||
});
|
||||
$table->addAction(function($row) {
|
||||
return IconBtnDeleteWidget::create(['url' => '/admin/card_program_conditions/delete/' . $row['id']])->run();
|
||||
});
|
||||
$table->create();
|
||||
$table->render();
|
@ -0,0 +1,34 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @var \Illuminate\Database\Eloquent\Collection $card_program_conditions
|
||||
*/
|
||||
|
||||
use Itguild\EloquentTable\ViewEloquentTable;
|
||||
use Itguild\EloquentTable\ViewJsonTableEloquentModel;
|
||||
use kernel\widgets\IconBtn\IconBtnDeleteWidget;
|
||||
use kernel\widgets\IconBtn\IconBtnEditWidget;
|
||||
use kernel\widgets\IconBtn\IconBtnListWidget;
|
||||
|
||||
$table = new ViewEloquentTable(new ViewJsonTableEloquentModel($card_program_conditions, [
|
||||
'params' => ["class" => "table table-bordered", "border" => "2"],
|
||||
'baseUrl' => "/admin/card_program_conditions",
|
||||
]));
|
||||
|
||||
$table->rows([
|
||||
'status' => [
|
||||
'value' => function ($data) {
|
||||
return \kernel\app_modules\card\models\CardProgramConditions::getStatus()[$data];
|
||||
}
|
||||
]
|
||||
]);
|
||||
|
||||
$table->beforePrint(function () use ($card_program_conditions) {
|
||||
$btn = IconBtnListWidget::create(['url' => '/admin/card_program_conditions'])->run();
|
||||
$btn .= IconBtnEditWidget::create(['url' => '/admin/card_program_conditions/update/' . $card_program_conditions->id])->run();
|
||||
$btn .= IconBtnDeleteWidget::create(['url' => '/admin/card_program_conditions/delete/' . $card_program_conditions->id])->run();
|
||||
return $btn;
|
||||
});
|
||||
|
||||
$table->create();
|
||||
$table->render();
|
@ -19,6 +19,14 @@ $form->field(\itguild\forms\inputs\TextInput::class, 'title', [
|
||||
->setLabel("Заголовок")
|
||||
->render();
|
||||
|
||||
$form->field(\itguild\forms\inputs\TextInput::class, 'settings', [
|
||||
'class' => "form-control",
|
||||
'placeholder' => 'Настройки',
|
||||
'value' => $model->settings ?? ''
|
||||
])
|
||||
->setLabel("Настройки")
|
||||
->render();
|
||||
|
||||
$form->field(\itguild\forms\inputs\File::class, 'path', [
|
||||
'class' => "form-control",
|
||||
'placeholder' => 'Путь к файлу',
|
||||
|
80
kernel/app_modules/card/views/card_transaction/form.php
Normal file
80
kernel/app_modules/card/views/card_transaction/form.php
Normal file
@ -0,0 +1,80 @@
|
||||
<?php
|
||||
/**
|
||||
* @var \kernel\app_modules\card\models\CardTransaction $model
|
||||
*/
|
||||
|
||||
use kernel\app_modules\card\models\Card;
|
||||
|
||||
$form = new \itguild\forms\ActiveForm();
|
||||
$form->beginForm(isset($model) ? "/admin/card_transaction/edit/" . $model->id : "/admin/card_transaction", 'multipart/form-data');
|
||||
|
||||
// Пример формы:
|
||||
|
||||
|
||||
$form->field(\itguild\forms\inputs\TextInput::class, 'from', [
|
||||
'class' => "form-control",
|
||||
'placeholder' => 'От кого',
|
||||
'value' => $model->from ?? ''
|
||||
])
|
||||
->setLabel("От кого")
|
||||
->render();
|
||||
|
||||
$form->field(\itguild\forms\inputs\TextInput::class, 'to', [
|
||||
'class' => "form-control",
|
||||
'placeholder' => 'Кому',
|
||||
'value' => $model->to ?? ''
|
||||
])
|
||||
->setLabel("Кому")
|
||||
->render();
|
||||
|
||||
$form->field(\itguild\forms\inputs\TextInput::class, 'amount', [
|
||||
'class' => "form-control",
|
||||
'placeholder' => 'Количество',
|
||||
'value' => $model->amount ?? ''
|
||||
])
|
||||
->setLabel("Количество")
|
||||
->render();
|
||||
|
||||
$form->field(class: \itguild\forms\inputs\Select::class, name: "type", params: [
|
||||
'class' => "form-control",
|
||||
'value' => $model->type ?? ''
|
||||
])
|
||||
->setLabel("Тип операции")
|
||||
->setOptions([1 => "Зачисление", 2 => "Списание"])
|
||||
->render();
|
||||
|
||||
|
||||
$form->field(class: \itguild\forms\inputs\Select::class, name: "status", params: [
|
||||
'class' => "form-control",
|
||||
'value' => $model->status ?? ''
|
||||
])
|
||||
->setLabel("Статус")
|
||||
->setOptions(\kernel\app_modules\card\models\CardTransaction::getStatus())
|
||||
->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();
|
78
kernel/app_modules/card/views/card_transaction/index.php
Normal file
78
kernel/app_modules/card/views/card_transaction/index.php
Normal file
@ -0,0 +1,78 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @var \Illuminate\Database\Eloquent\Collection $card
|
||||
* @var int $page_number
|
||||
* @var \kernel\CgView $view
|
||||
*/
|
||||
|
||||
use kernel\app_modules\card\models\Card;
|
||||
use Itguild\EloquentTable\EloquentDataProvider;
|
||||
use Itguild\EloquentTable\ListEloquentTable;
|
||||
use kernel\widgets\IconBtn\IconBtnCreateWidget;
|
||||
use kernel\widgets\IconBtn\IconBtnDeleteWidget;
|
||||
use kernel\widgets\IconBtn\IconBtnEditWidget;
|
||||
use kernel\widgets\IconBtn\IconBtnViewWidget;
|
||||
|
||||
$view->setTitle("Список транзакций");
|
||||
$view->setMeta([
|
||||
'description' => 'Список транзакций системы'
|
||||
]);
|
||||
|
||||
//Для использования таблицы с моделью, необходимо создать таблицу в базе данных
|
||||
$table = new ListEloquentTable(new EloquentDataProvider(\kernel\app_modules\card\models\CardTransaction::class, [
|
||||
'currentPage' => $page_number,
|
||||
'perPage' => 8,
|
||||
'params' => ["class" => "table table-bordered", "border" => "2"],
|
||||
'baseUrl' => "/admin/card_transaction"
|
||||
]));
|
||||
|
||||
$table->beforePrint(function () {
|
||||
$count = \kernel\app_modules\card\models\CardTransaction::all()->count();
|
||||
$html = IconBtnCreateWidget::create(['url' => '/admin/card_transaction/create'])->run();
|
||||
$html .= "<div>Всего записей: $count</div>";
|
||||
|
||||
return $html;
|
||||
});
|
||||
|
||||
$table->columns([
|
||||
'status' => [
|
||||
'value' => function ($data) {
|
||||
return \kernel\app_modules\card\models\CardTransaction::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->addAction(function($row) {
|
||||
return IconBtnViewWidget::create(['url' => '/admin/card_transaction/' . $row['id']])->run();
|
||||
});
|
||||
//$table->addAction(function($row) {
|
||||
// return IconBtnEditWidget::create(['url' => '/admin/card_transaction/update/' . $row['id']])->run();
|
||||
//});
|
||||
//$table->addAction(function($row) {
|
||||
// return IconBtnDeleteWidget::create(['url' => '/admin/card_transaction/delete/' . $row['id']])->run();
|
||||
//});
|
||||
$table->create();
|
||||
$table->render();
|
34
kernel/app_modules/card/views/card_transaction/view.php
Normal file
34
kernel/app_modules/card/views/card_transaction/view.php
Normal file
@ -0,0 +1,34 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @var \Illuminate\Database\Eloquent\Collection $card_transaction
|
||||
*/
|
||||
|
||||
use Itguild\EloquentTable\ViewEloquentTable;
|
||||
use Itguild\EloquentTable\ViewJsonTableEloquentModel;
|
||||
use kernel\widgets\IconBtn\IconBtnDeleteWidget;
|
||||
use kernel\widgets\IconBtn\IconBtnEditWidget;
|
||||
use kernel\widgets\IconBtn\IconBtnListWidget;
|
||||
|
||||
$table = new ViewEloquentTable(new ViewJsonTableEloquentModel($card_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];
|
||||
}
|
||||
]
|
||||
]);
|
||||
|
||||
$table->beforePrint(function () use ($card_transaction) {
|
||||
$btn = IconBtnListWidget::create(['url' => '/admin/card_transaction'])->run();
|
||||
// $btn .= IconBtnEditWidget::create(['url' => '/admin/card_transaction/update/' . $card_transaction->id])->run();
|
||||
// $btn .= IconBtnDeleteWidget::create(['url' => '/admin/card_transaction/delete/' . $card_transaction->id])->run();
|
||||
return $btn;
|
||||
});
|
||||
|
||||
$table->create();
|
||||
$table->render();
|
@ -58,12 +58,12 @@ $form->field(\itguild\forms\inputs\TextInput::class, 'info', [
|
||||
->setLabel("Информация")
|
||||
->render();
|
||||
|
||||
$form->field(\itguild\forms\inputs\TextInput::class, 'program', [
|
||||
$form->field(class: \itguild\forms\inputs\Select::class, name: "card_program_id", params: [
|
||||
'class' => "form-control",
|
||||
'placeholder' => 'Программа',
|
||||
'value' => $model->program ?? ''
|
||||
'value' => $model->card_program_id ?? ''
|
||||
])
|
||||
->setLabel("Программа")
|
||||
->setOptions(\kernel\app_modules\card\services\CardProgramService::getProgramList())
|
||||
->render();
|
||||
|
||||
$form->field(\itguild\forms\inputs\TextInput::class, 'cvc', [
|
||||
|
@ -15,17 +15,29 @@ use kernel\widgets\IconBtn\IconBtnDeleteWidget;
|
||||
use kernel\widgets\IconBtn\IconBtnEditWidget;
|
||||
use kernel\widgets\IconBtn\IconBtnViewWidget;
|
||||
|
||||
$view->setTitle("Список card");
|
||||
$view->setTitle("Список карт");
|
||||
$view->setMeta([
|
||||
'description' => 'Список card системы'
|
||||
'description' => 'Список карт системы'
|
||||
]);
|
||||
|
||||
$get = (new \kernel\Request())->get();
|
||||
|
||||
//Для использования таблицы с моделью, необходимо создать таблицу в базе данных
|
||||
$table = new ListEloquentTable(new EloquentDataProvider(Card::class, [
|
||||
$table = new ListEloquentTable(new EloquentDataProvider(Card::query()->orderBy("id", "DESC"), [
|
||||
'currentPage' => $page_number,
|
||||
'perPage' => 8,
|
||||
'params' => ["class" => "table table-bordered", "border" => "2"],
|
||||
'baseUrl' => "/admin/card"
|
||||
'baseUrl' => "/admin/card",
|
||||
'searchPrefix' => "",
|
||||
'searchParams' => $get,
|
||||
'fillable' => [
|
||||
'user_id',
|
||||
'balance',
|
||||
'username',
|
||||
'card_template_id',
|
||||
'card_file_id',
|
||||
'status',
|
||||
],
|
||||
]));
|
||||
|
||||
$table->columns([
|
||||
@ -39,6 +51,12 @@ $table->columns([
|
||||
return \kernel\app_modules\card\models\CardTemplate::find($data)->title;
|
||||
}
|
||||
],
|
||||
"username" => [
|
||||
"filter" => [
|
||||
"class" => \Itguild\Tables\Filter\InputTextFilter::class,
|
||||
'value' => $get['username'] ?? ''
|
||||
]
|
||||
],
|
||||
'card_file_id' => [
|
||||
'value' => function ($data) {
|
||||
$file = \kernel\app_modules\card\models\CardFile::find($data)->file;
|
||||
@ -48,35 +66,23 @@ $table->columns([
|
||||
'status' => [
|
||||
'value' => function ($data) {
|
||||
return Card::getStatus()[$data];
|
||||
}
|
||||
},
|
||||
'filter' => [
|
||||
'class' => \kernel\filters\BootstrapSelectFilter::class,
|
||||
'params' => [
|
||||
'options' => Card::getStatus(),
|
||||
'prompt' => 'Не выбрано'
|
||||
],
|
||||
'value' => $get['status'] ?? '',
|
||||
],
|
||||
]
|
||||
]);
|
||||
|
||||
//$table = new \Itguild\Tables\ListJsonTable(json_encode(
|
||||
// [
|
||||
// 'meta' => [
|
||||
// 'total' => 0,
|
||||
// 'totalWithFilters' => 0,
|
||||
// 'columns' => [
|
||||
// 'title',
|
||||
// 'slug',
|
||||
// 'status',
|
||||
// ],
|
||||
// 'perPage' => 5,
|
||||
// 'currentPage' => 1,
|
||||
// 'baseUrl' => '/admin/some',
|
||||
// 'params' => [
|
||||
// 'class' => 'table table-bordered',
|
||||
// 'border' => 2
|
||||
// ]
|
||||
// ],
|
||||
// 'filters' => [],
|
||||
// 'data' => [],
|
||||
// ]
|
||||
//));
|
||||
|
||||
$table->beforePrint(function () {
|
||||
return IconBtnCreateWidget::create(['url' => '/admin/card/create'])->run();
|
||||
$table->beforePrint(function () use ($table) {
|
||||
$count = Card::all()->count();
|
||||
$html = IconBtnCreateWidget::create(['url' => '/admin/card/create'])->run();
|
||||
$html .= "<div>Всего записей: $count</div>";
|
||||
return $html;
|
||||
});
|
||||
|
||||
$table->addAction(function($row) {
|
||||
|
@ -39,6 +39,8 @@ $table->rows([
|
||||
$table->create();
|
||||
$table->render();
|
||||
|
||||
echo \kernel\helpers\Html::img("data:image/png;base64, " . \kernel\app_modules\card\services\CardFileService::createCardPNG($card, true));
|
||||
|
||||
//$writer = new PngWriter();
|
||||
//
|
||||
//// Create QR code
|
||||
|
@ -2,7 +2,9 @@
|
||||
|
||||
namespace kernel\app_modules\tag\service;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use kernel\app_modules\tag\models\Tag;
|
||||
use kernel\app_modules\tag\models\TagEntity;
|
||||
use kernel\FormModel;
|
||||
use kernel\helpers\Debug;
|
||||
use kernel\helpers\Slug;
|
||||
@ -40,4 +42,38 @@ class TagService
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
public static function getEntityByTagId(int $tagId, $model)
|
||||
{
|
||||
$tagEntity = TagEntity::where("tag_id", $tagId)->get();
|
||||
if ($tagEntity){
|
||||
$entityIdArr = [];
|
||||
foreach ($tagEntity as $item){
|
||||
$entityIdArr[] = $item['entity_id'];
|
||||
}
|
||||
}
|
||||
$queryBuilder = $model::query();
|
||||
|
||||
return $queryBuilder->whereIn("id", $entityIdArr)->get();
|
||||
}
|
||||
|
||||
public static function getEntityByTagSlug(string $tagSlug, $model)
|
||||
{
|
||||
$tag = Tag::where("slug", $tagSlug)->first();
|
||||
if ($tag){
|
||||
$tagEntity = TagEntity::where("tag_id", $tag->id)->get();
|
||||
if ($tagEntity){
|
||||
$entityIdArr = [];
|
||||
foreach ($tagEntity as $item){
|
||||
$entityIdArr[] = $item['entity_id'];
|
||||
}
|
||||
}
|
||||
$queryBuilder = $model::query();
|
||||
|
||||
return $queryBuilder->whereIn("id", $entityIdArr)->get();
|
||||
}
|
||||
|
||||
return [];
|
||||
}
|
||||
|
||||
}
|
@ -29,11 +29,27 @@ class TgbotModule extends Module
|
||||
"url" => "/admin/tg-bot",
|
||||
"slug" => "tg-bot",
|
||||
]);
|
||||
|
||||
$this->menuService->createItem([
|
||||
"label" => "Диалоги",
|
||||
"url" => "/admin/tg-bot",
|
||||
"slug" => "tg-bot-dialogs",
|
||||
"parent_slug" => "tg-bot",
|
||||
]);
|
||||
|
||||
$this->menuService->createItem([
|
||||
"label" => "Уведомления",
|
||||
"url" => "/admin/tg-bot-notification",
|
||||
"slug" => "tg-bot-notification",
|
||||
"parent_slug" => "tg-bot",
|
||||
]);
|
||||
}
|
||||
|
||||
public function deactivate()
|
||||
{
|
||||
$this->menuService->removeItemBySlug("tg-bot");
|
||||
$this->menuService->removeItemBySlug("tg-bot-dialogs");
|
||||
$this->menuService->removeItemBySlug("tg-bot-notification");
|
||||
$this->migrationService->rollbackAtPath("{KERNEL_APP_MODULES}/tgbot/migrations");
|
||||
}
|
||||
}
|
@ -4,6 +4,7 @@ namespace kernel\app_modules\tgbot\controllers;
|
||||
|
||||
use app\modules\tgbot\models\Tgbot;
|
||||
use JetBrains\PhpStorm\NoReturn;
|
||||
use kernel\app_modules\card\models\Card;
|
||||
use kernel\app_modules\card\models\forms\CreateCardForm;
|
||||
use kernel\app_modules\card\services\CardService;
|
||||
use kernel\helpers\Debug;
|
||||
@ -28,8 +29,8 @@ class TgBotRestController extends RestController
|
||||
|
||||
$tgBot = $this->model->where("bot_id", $data['bot_id'])->where("dialog_id", $data['dialog_id'])->first();
|
||||
|
||||
if (!$tgBot){
|
||||
foreach ($this->model->getFillable() as $item){
|
||||
if (!$tgBot) {
|
||||
foreach ($this->model->getFillable() as $item) {
|
||||
$this->model->{$item} = $data[$item] ?? null;
|
||||
}
|
||||
|
||||
@ -49,10 +50,23 @@ class TgBotRestController extends RestController
|
||||
|
||||
$this->model->save();
|
||||
|
||||
$this->renderApi($this->model->toArray());
|
||||
}
|
||||
$resArr = $this->model->toArray();
|
||||
|
||||
$this->renderApi($tgBot->toArray());
|
||||
$cardService = new CardService();
|
||||
$cardForm = new CreateCardForm();
|
||||
$cardForm->load([
|
||||
'user_id' => $user->id,
|
||||
'username' => $username,
|
||||
'card_template_id' => 105545,
|
||||
'status' => 1,
|
||||
]);
|
||||
$cardService->create($cardForm);
|
||||
|
||||
$this->renderApi($resArr);
|
||||
}
|
||||
$resArr = $tgBot->toArray();
|
||||
|
||||
$this->renderApi($resArr);
|
||||
}
|
||||
|
||||
#[NoReturn] public function actionCreateCard(): void
|
||||
@ -65,12 +79,12 @@ class TgBotRestController extends RestController
|
||||
$form->setItem('payment_type', 2);
|
||||
$form->setItem('bank_id', 323);
|
||||
$form->setItem('info', 42);
|
||||
$form->setItem('program', 74);
|
||||
$form->setItem('program', 71);
|
||||
$form->setItem('cvc', 101);
|
||||
$form->setItem('pin', 1111);
|
||||
$form->setItem('status', 1);
|
||||
|
||||
if ($form->validate()){
|
||||
if ($form->validate()) {
|
||||
$model = $cardService->create($form);
|
||||
|
||||
$this->renderApi($model->load(['cardFile'])->toArray());
|
||||
@ -88,4 +102,16 @@ class TgBotRestController extends RestController
|
||||
$this->renderApi([]);
|
||||
}
|
||||
|
||||
#[NoReturn] public function actionGetCardByDialog(int $dialog_id, int $bot_id): void
|
||||
{
|
||||
$model = \kernel\app_modules\tgbot\models\Tgbot::where(['dialog_id' => $dialog_id, 'bot_id' => $bot_id])->first();
|
||||
if ($model) {
|
||||
$card = Card::where("user_id", $model->user_id)->first();
|
||||
if ($card) {
|
||||
$this->renderApi($card->load('cardFile')->toArray());
|
||||
}
|
||||
}
|
||||
$this->renderApi([]);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,114 @@
|
||||
<?php
|
||||
|
||||
namespace kernel\app_modules\tgbot\controllers;
|
||||
|
||||
use Exception;
|
||||
use JetBrains\PhpStorm\NoReturn;
|
||||
use kernel\AdminController;
|
||||
use kernel\app_modules\tgbot\models\forms\CreateTgbotNotificationForm;
|
||||
use kernel\app_modules\tgbot\models\TgbotNotification;
|
||||
use kernel\app_modules\tgbot\services\TgbotNotificationService;
|
||||
use kernel\Flash;
|
||||
|
||||
class TgbotNotificationController extends AdminController
|
||||
{
|
||||
protected TgbotNotificationService $notificationService;
|
||||
|
||||
protected function init(): void
|
||||
{
|
||||
parent::init();
|
||||
$this->cgView->viewPath = KERNEL_APP_MODULES_DIR . "/tgbot/views/notification/";
|
||||
$this->notificationService = new TgbotNotificationService();
|
||||
}
|
||||
|
||||
public function actionCreate(): void
|
||||
{
|
||||
$this->cgView->render("form.php");
|
||||
}
|
||||
|
||||
public function actionIndex($page_number = 1): void
|
||||
{
|
||||
$this->cgView->render("index.php", ['page_number' => $page_number]);
|
||||
}
|
||||
|
||||
#[NoReturn] public function actionAdd(): void
|
||||
{
|
||||
$tgForm = new CreateTgbotNotificationForm();
|
||||
$tgForm->load($_REQUEST);
|
||||
if ($tgForm->validate()) {
|
||||
$tg = $this->notificationService->create($tgForm);
|
||||
if ($tg) {
|
||||
$this->redirect("/admin/tg-bot-notification/view/" . $tg->id);
|
||||
}
|
||||
}
|
||||
|
||||
Flash::setMessage("error", $tgForm->getErrorsStr());
|
||||
$this->redirect("/admin/tg-bot-notification/create");
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws Exception
|
||||
*/
|
||||
public function actionUpdate($id): void
|
||||
{
|
||||
$model = TgbotNotification::find($id);
|
||||
if (!$model) {
|
||||
throw new Exception(message: "The notification not found");
|
||||
}
|
||||
|
||||
$this->cgView->render("form.php", ['model' => $model]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws Exception
|
||||
*/
|
||||
public function actionEdit($id): void
|
||||
{
|
||||
$tg = TgbotNotification::find($id);
|
||||
if (!$tg) {
|
||||
throw new Exception(message: "The tag not found");
|
||||
}
|
||||
$tgForm = new CreateTgbotNotificationForm();
|
||||
$tgService = new TgbotNotificationService();
|
||||
$tgForm->load($_REQUEST);
|
||||
if ($tgForm->validate()) {
|
||||
$tg = $tgService->update($tgForm, $tg);
|
||||
if ($tg) {
|
||||
$this->redirect("/admin/tg-bot-notification/view/" . $tg->id);
|
||||
}
|
||||
}
|
||||
|
||||
Flash::setMessage("error", $tgForm->getErrorsStr());
|
||||
$this->redirect("/admin/tg-bot-notification/update/" . $id);
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws Exception
|
||||
*/
|
||||
public function actionView($id): void
|
||||
{
|
||||
$tg = TgbotNotification::find($id);
|
||||
|
||||
if (!$tg) {
|
||||
throw new Exception(message: "The notification not found");
|
||||
}
|
||||
$this->cgView->render("view.php", ['tg' => $tg]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws Exception
|
||||
*/
|
||||
#[NoReturn] public function actionDelete(int $id): void
|
||||
{
|
||||
$post = TgbotNotification::find($id)->first();
|
||||
if (!$post){
|
||||
throw new Exception(message: "The tg notification not found");
|
||||
}
|
||||
|
||||
Flash::setMessage("success", "Notification deleted");
|
||||
$post->delete();
|
||||
$this->redirect("/admin/tg-bot-notification/");
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
namespace kernel\app_modules\tgbot\controllers;
|
||||
|
||||
use JetBrains\PhpStorm\NoReturn;
|
||||
use kernel\app_modules\tgbot\models\TgbotNotification;
|
||||
use kernel\RestController;
|
||||
|
||||
class TgbotNotificationRestController extends RestController
|
||||
{
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->model = new TgbotNotification();
|
||||
}
|
||||
|
||||
#[NoReturn] public function actionGetToSend(): void
|
||||
{
|
||||
$notification = TgbotNotification::where("status", TgbotNotification::TO_SEND_STATUS)->first();
|
||||
if ($notification){
|
||||
$notification->status = TgbotNotification::SENT_STATUS;
|
||||
$notification->save();
|
||||
|
||||
$this->renderApi($notification->toArray());
|
||||
}
|
||||
|
||||
$this->renderApi([]);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,34 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
public string $migration;
|
||||
/**
|
||||
* Run the migrations.
|
||||
*/
|
||||
public function up(): void
|
||||
{
|
||||
\kernel\App::$db->schema->create('tgbot_notification', function (Blueprint $table) {
|
||||
$table->increments('id');
|
||||
$table->bigInteger('bot_id')->nullable(false);
|
||||
$table->bigInteger('dialog_id')->nullable();
|
||||
$table->string('to_group')->nullable();
|
||||
$table->text('content')->nullable();
|
||||
$table->string('photo')->nullable();
|
||||
$table->integer('status')->nullable()->default(1);
|
||||
$table->timestamps();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
\kernel\App::$db->schema->dropIfExists('tgbot_notification');
|
||||
}
|
||||
};
|
@ -18,6 +18,7 @@ class Tgbot extends Model
|
||||
{
|
||||
const DISABLE_STATUS = 0;
|
||||
const ACTIVE_STATUS = 1;
|
||||
const ADMIN_STATUS = 9;
|
||||
|
||||
protected $table = 'tgbot';
|
||||
|
||||
@ -44,6 +45,7 @@ class Tgbot extends Model
|
||||
return [
|
||||
self::DISABLE_STATUS => "Не активный",
|
||||
self::ACTIVE_STATUS => "Активный",
|
||||
self::ADMIN_STATUS => "Админ",
|
||||
];
|
||||
}
|
||||
|
||||
|
53
kernel/app_modules/tgbot/models/TgbotNotification.php
Normal file
53
kernel/app_modules/tgbot/models/TgbotNotification.php
Normal file
@ -0,0 +1,53 @@
|
||||
<?php
|
||||
|
||||
namespace kernel\app_modules\tgbot\models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
/**
|
||||
* @property integer $id
|
||||
* @property integer $bot_id
|
||||
* @property integer $dialog_id
|
||||
* @property string $to_group
|
||||
* @property string $content
|
||||
* @property string $photo
|
||||
* @property integer $status
|
||||
*/
|
||||
class TgbotNotification extends Model
|
||||
{
|
||||
|
||||
const DISABLE_STATUS = 0;
|
||||
const NEW_STATUS = 1;
|
||||
const TO_SEND_STATUS = 2;
|
||||
const SENT_STATUS = 3;
|
||||
|
||||
protected $table = 'tgbot_notification';
|
||||
|
||||
protected $fillable = ['bot_id', 'dialog_id', 'to_group', 'content', 'photo', 'status'];
|
||||
|
||||
public static function labels(): array
|
||||
{
|
||||
return [
|
||||
'bot_id' => 'Bot ID',
|
||||
'dialog_id' => 'Dialog ID',
|
||||
'to_group' => 'Group',
|
||||
'content' => 'Контент',
|
||||
'photo' => 'Фото',
|
||||
'status' => 'Статус',
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string[]
|
||||
*/
|
||||
public static function getStatus(): array
|
||||
{
|
||||
return [
|
||||
self::DISABLE_STATUS => "Не активный",
|
||||
self::NEW_STATUS => "Новое",
|
||||
self::TO_SEND_STATUS => "На отправку",
|
||||
self::SENT_STATUS => "Отправлено",
|
||||
];
|
||||
}
|
||||
|
||||
}
|
@ -18,6 +18,7 @@ class CreateTgBotForm extends FormModel
|
||||
public function rules(): array
|
||||
{
|
||||
return [
|
||||
'user_id' => 'required',
|
||||
'bot_id' => 'required',
|
||||
'dialog_id' => 'required',
|
||||
'username' => 'required',
|
||||
|
@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
namespace kernel\app_modules\tgbot\models\forms;
|
||||
|
||||
use kernel\FormModel;
|
||||
|
||||
/**
|
||||
* @property int $bot_id
|
||||
* @property int $dialog_id
|
||||
* @property string $to_group
|
||||
* @property string $content
|
||||
* @property string $photo
|
||||
* @property int $status
|
||||
*/
|
||||
class CreateTgbotNotificationForm extends FormModel
|
||||
{
|
||||
|
||||
public function rules(): array
|
||||
{
|
||||
return [
|
||||
'bot_id' => 'required|alpha-numeric',
|
||||
'dialog_id' => 'alpha-numeric',
|
||||
'to_group' => 'alpha-numeric',
|
||||
'content' => 'min-str-len:5',
|
||||
'photo' => 'min-str-len:5',
|
||||
'status' => 'alpha-numeric'
|
||||
];
|
||||
}
|
||||
|
||||
}
|
@ -4,22 +4,30 @@
|
||||
use kernel\App;
|
||||
use kernel\CgRouteCollector;
|
||||
use Phroute\Phroute\RouteCollector;
|
||||
use kernel\app_modules\tgbot\controllers\TgbotNotificationController;
|
||||
use kernel\app_modules\tgbot\controllers\TgbotController;
|
||||
|
||||
App::$collector->group(["prefix" => "admin"], function (CgRouteCollector $router) {
|
||||
App::$collector->group(["before" => "auth"], function (RouteCollector $router) {
|
||||
App::$collector->group(["prefix" => "tg-bot"], function (CGRouteCollector $router) {
|
||||
App::$collector->get('/', [\app\modules\tgbot\controllers\TgbotController::class, 'actionIndex']);
|
||||
App::$collector->get('/page/{page_number}', [\app\modules\tag\controllers\TagController::class, 'actionIndex']);
|
||||
App::$collector->get('/create', [\app\modules\tgbot\controllers\TgbotController::class, 'actionCreate']);
|
||||
App::$collector->post("/", [\app\modules\tgbot\controllers\TgbotController::class, 'actionAdd']);
|
||||
App::$collector->get('/view/{id}', [\app\modules\tgbot\controllers\TgbotController::class, 'actionView']);
|
||||
App::$collector->any('/update/{id}', [\app\modules\tgbot\controllers\TgbotController::class, 'actionUpdate']);
|
||||
App::$collector->any("/edit/{id}", [\app\modules\tgbot\controllers\TgbotController::class, 'actionEdit']);
|
||||
App::$collector->get('/delete/{id}', [\app\modules\tgbot\controllers\TgbotController::class, 'actionDelete']);
|
||||
App::$collector->get('/', [TgbotController::class, 'actionIndex']);
|
||||
App::$collector->get('/page/{page_number}', [TgbotController::class, 'actionIndex']);
|
||||
App::$collector->get('/create', [TgbotController::class, 'actionCreate']);
|
||||
App::$collector->post("/", [TgbotController::class, 'actionAdd']);
|
||||
App::$collector->get('/view/{id}', [TgbotController::class, 'actionView']);
|
||||
App::$collector->any('/update/{id}', [TgbotController::class, 'actionUpdate']);
|
||||
App::$collector->any("/edit/{id}", [TgbotController::class, 'actionEdit']);
|
||||
App::$collector->get('/delete/{id}', [TgbotController::class, 'actionDelete']);
|
||||
});
|
||||
App::$collector->group(["prefix" => "settings"], function (CGRouteCollector $router) {
|
||||
App::$collector->get('/tag', [\app\modules\tag\controllers\TagController::class, 'actionSettings']);
|
||||
App::$collector->post('/tag/update', [\app\modules\tag\controllers\TagController::class, 'actionSaveSettings']);
|
||||
App::$collector->group(["prefix" => "tg-bot-notification"], function (CGRouteCollector $router) {
|
||||
App::$collector->get('/', [TgbotNotificationController::class, 'actionIndex']);
|
||||
App::$collector->get('/page/{page_number}', [TgbotNotificationController::class, 'actionIndex']);
|
||||
App::$collector->get('/create', [TgbotNotificationController::class, 'actionCreate']);
|
||||
App::$collector->post("/", [TgbotNotificationController::class, 'actionAdd']);
|
||||
App::$collector->get('/view/{id}', [TgbotNotificationController::class, 'actionView']);
|
||||
App::$collector->any('/update/{id}', [TgbotNotificationController::class, 'actionUpdate']);
|
||||
App::$collector->any("/edit/{id}", [TgbotNotificationController::class, 'actionEdit']);
|
||||
App::$collector->get('/delete/{id}', [TgbotNotificationController::class, 'actionDelete']);
|
||||
});
|
||||
});
|
||||
});
|
||||
@ -30,4 +38,7 @@ App::$collector->group(["prefix" => "api"], function (CgRouteCollector $router){
|
||||
$router->post('/tg-bot/create-card', [\app\modules\tgbot\controllers\TgBotRestController::class, 'actionCreateCard']);
|
||||
$router->get('/tg-bot/get-by-dialog/{dialog_id}/{bot_id}', [\app\modules\tgbot\controllers\TgBotRestController::class, 'actionGetByDialog']);
|
||||
});
|
||||
$router->get('/tg-bot/get-scan-btn/{id}', [\app\modules\tgbot\controllers\TgBotRestController::class, 'actionGetScanBtn']);
|
||||
$router->get('/tg-bot/get-card-by-dialog/{dialog_id}/{bot_id}', [\app\modules\tgbot\controllers\TgBotRestController::class, 'actionGetCardByDialog']);
|
||||
$router->get('/tg-bot-notification/get-to-send', [\kernel\app_modules\tgbot\controllers\TgbotNotificationRestController::class, 'actionGetToSend']);
|
||||
});
|
@ -11,9 +11,12 @@ use kernel\services\ModuleService;
|
||||
|
||||
class TgBotService
|
||||
{
|
||||
public static null|Tgbot $currentDialog = null;
|
||||
|
||||
public function create(FormModel $form_model): false|Tgbot
|
||||
{
|
||||
$model = new Tgbot();
|
||||
$model->user_id = $form_model->getItem('user_id');
|
||||
$model->bot_id = $form_model->getItem('bot_id');
|
||||
$model->dialog_id = $form_model->getItem('dialog_id');
|
||||
$model->user_id = $form_model->getItem('user_id');
|
||||
@ -30,6 +33,7 @@ class TgBotService
|
||||
|
||||
public function update(FormModel $form_model, Tgbot $model): false|Tgbot
|
||||
{
|
||||
$model->user_id = $form_model->getItem('user_id');
|
||||
$model->bot_id = $form_model->getItem('bot_id');
|
||||
$model->dialog_id = $form_model->getItem('dialog_id');
|
||||
$model->user_id = $form_model->getItem('user_id');
|
||||
@ -45,4 +49,13 @@ class TgBotService
|
||||
return false;
|
||||
}
|
||||
|
||||
public static function isAdmin(): bool
|
||||
{
|
||||
if (self::$currentDialog->status === Tgbot::ADMIN_STATUS){
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,43 @@
|
||||
<?php
|
||||
|
||||
namespace kernel\app_modules\tgbot\services;
|
||||
|
||||
use kernel\app_modules\tgbot\models\TgbotNotification;
|
||||
use kernel\FormModel;
|
||||
|
||||
class TgbotNotificationService
|
||||
{
|
||||
|
||||
public function create(FormModel $form_model): false|TgbotNotification
|
||||
{
|
||||
$model = new TgbotNotification();
|
||||
$model->to_group = $form_model->getItem('to_group');
|
||||
$model->bot_id = $form_model->getItem('bot_id');
|
||||
$model->dialog_id = $form_model->getItem('dialog_id');
|
||||
$model->content = $form_model->getItem('content');
|
||||
$model->photo = $form_model->getItem('username');
|
||||
$model->status = $form_model->getItem('status');
|
||||
if ($model->save()){
|
||||
return $model;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public function update(FormModel $form_model, TgbotNotification $model): false|TgbotNotification
|
||||
{
|
||||
$model->bot_id = $form_model->getItem('bot_id');
|
||||
$model->dialog_id = $form_model->getItem('dialog_id');
|
||||
$model->to_group = $form_model->getItem('to_group');
|
||||
$model->content = $form_model->getItem('content');
|
||||
$model->photo = $form_model->getItem('photo');
|
||||
$model->status = $form_model->getItem('status');
|
||||
|
||||
if ($model->save()){
|
||||
return $model;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
84
kernel/app_modules/tgbot/views/notification/form.php
Normal file
84
kernel/app_modules/tgbot/views/notification/form.php
Normal file
@ -0,0 +1,84 @@
|
||||
<?php
|
||||
/**
|
||||
* @var \kernel\app_modules\tgbot\models\TgbotNotification $model
|
||||
*/
|
||||
|
||||
use app\modules\tgbot\models\Tgbot;
|
||||
|
||||
$form = new \itguild\forms\ActiveForm();
|
||||
$form->beginForm(isset($model) ? "/admin/tg-bot-notification/edit/" . $model->id : "/admin/tg-bot-notification");
|
||||
|
||||
|
||||
$form->field(class: \itguild\forms\inputs\TextInput::class, name: "bot_id", params: [
|
||||
'class' => "form-control",
|
||||
'placeholder' => 'Bot ID',
|
||||
'value' => $model->bot_id ?? ''
|
||||
])
|
||||
->setLabel("Bot ID")
|
||||
->render();
|
||||
|
||||
$form->field(class: \itguild\forms\inputs\TextInput::class, name: "dialog_id", params: [
|
||||
'class' => "form-control",
|
||||
'placeholder' => 'Dialog ID',
|
||||
'value' => $model->dialog_id ?? ''
|
||||
])
|
||||
->setLabel("Dialog ID")
|
||||
->render();
|
||||
|
||||
$form->field(class: \itguild\forms\inputs\TextInput::class, name: "to_group", params: [
|
||||
'class' => "form-control",
|
||||
'placeholder' => '',
|
||||
'value' => $model->to_group ?? ''
|
||||
])
|
||||
->setLabel("To user group")
|
||||
->render();
|
||||
|
||||
$form->field(class: \itguild\forms\inputs\TextInput::class, name: "content", params: [
|
||||
'class' => "form-control",
|
||||
'placeholder' => 'Content',
|
||||
'value' => $model->content ?? ''
|
||||
])
|
||||
->setLabel("Content")
|
||||
->render();
|
||||
|
||||
$form->field(class: \itguild\forms\inputs\TextInput::class, name: "photo", params: [
|
||||
'class' => "form-control",
|
||||
'placeholder' => 'Photo',
|
||||
'value' => $model->photo ?? ''
|
||||
])
|
||||
->setLabel("Photo")
|
||||
->render();
|
||||
|
||||
|
||||
$form->field(\itguild\forms\inputs\Select::class, 'status', [
|
||||
'class' => "form-control",
|
||||
'value' => $model->status ?? ''
|
||||
])
|
||||
->setLabel("Статус")
|
||||
->setOptions(\kernel\app_modules\tgbot\models\TgbotNotification::getStatus())
|
||||
->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();
|
63
kernel/app_modules/tgbot/views/notification/index.php
Normal file
63
kernel/app_modules/tgbot/views/notification/index.php
Normal file
@ -0,0 +1,63 @@
|
||||
<?php
|
||||
/**
|
||||
* @var int $page_number
|
||||
* @var \kernel\CgView $view
|
||||
*/
|
||||
|
||||
use Itguild\EloquentTable\EloquentDataProvider;
|
||||
use Itguild\EloquentTable\ListEloquentTable;
|
||||
use kernel\app_modules\tag\models\Tag;
|
||||
use kernel\IGTabel\btn\PrimaryBtn;
|
||||
use kernel\models\Menu;
|
||||
use kernel\modules\menu\table\columns\MenuDeleteActionColumn;
|
||||
use kernel\modules\menu\table\columns\MenuEditActionColumn;
|
||||
use kernel\modules\menu\table\columns\MenuViewActionColumn;
|
||||
use kernel\widgets\IconBtn\IconBtnDeleteWidget;
|
||||
use kernel\widgets\IconBtn\IconBtnEditWidget;
|
||||
use kernel\widgets\IconBtn\IconBtnViewWidget;
|
||||
|
||||
$view->setTitle("Список существующих диалогов");
|
||||
|
||||
$table = new ListEloquentTable(new EloquentDataProvider(\kernel\app_modules\tgbot\models\TgbotNotification::query()->orderBy("id", "DESC"), [
|
||||
'currentPage' => $page_number,
|
||||
'perPage' => 8,
|
||||
'params' => ["class" => "table table-bordered", "border" => "2"],
|
||||
'baseUrl' => "/admin/tg-bot-notification",
|
||||
'searchPrefix' => "",
|
||||
'searchParams' => (new \kernel\Request())->get(),
|
||||
]));
|
||||
|
||||
$table->beforePrint(function () {
|
||||
return PrimaryBtn::create("Создать", "/admin/tg-bot-notification/create")->fetch();
|
||||
});
|
||||
|
||||
$table->columns([
|
||||
"status" => [
|
||||
"value" => function ($cell) {
|
||||
return \kernel\app_modules\tgbot\models\TgbotNotification::getStatus()[$cell] ?? 0;
|
||||
}
|
||||
],
|
||||
"bot_id" => [
|
||||
"filter" => [
|
||||
"class" => \Itguild\Tables\Filter\InputTextFilter::class
|
||||
]
|
||||
],
|
||||
"dialog_id" => [
|
||||
"filter" => [
|
||||
"class" => \Itguild\Tables\Filter\InputTextFilter::class
|
||||
]
|
||||
]
|
||||
]);
|
||||
|
||||
|
||||
$table->addAction(function($row) {
|
||||
return IconBtnViewWidget::create(['url' => '/admin/tg-bot-notification/' . $row['id']])->run();
|
||||
});
|
||||
$table->addAction(function($row) {
|
||||
return IconBtnEditWidget::create(['url' => '/admin/tg-bot-notification/update/' . $row['id']])->run();
|
||||
});
|
||||
$table->addAction(function($row) {
|
||||
return IconBtnDeleteWidget::create(['url' => '/admin/tg-bot-notification/delete/' . $row['id']])->run();
|
||||
});
|
||||
$table->create();
|
||||
$table->render();
|
30
kernel/app_modules/tgbot/views/notification/view.php
Normal file
30
kernel/app_modules/tgbot/views/notification/view.php
Normal file
@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @var \Illuminate\Database\Eloquent\Collection $tg
|
||||
*/
|
||||
|
||||
use kernel\modules\user\models\User;
|
||||
use Itguild\EloquentTable\ViewEloquentTable;
|
||||
use Itguild\EloquentTable\ViewJsonTableEloquentModel;
|
||||
use kernel\IGTabel\btn\DangerBtn;
|
||||
use kernel\IGTabel\btn\PrimaryBtn;
|
||||
use kernel\IGTabel\btn\SuccessBtn;
|
||||
|
||||
$table = new ViewEloquentTable(new ViewJsonTableEloquentModel($tg, [
|
||||
'params' => ["class" => "table table-bordered", "border" => "2"],
|
||||
'baseUrl' => "/admin/tg-bot-notification",
|
||||
]));
|
||||
$table->beforePrint(function () use ($tg) {
|
||||
$btn = PrimaryBtn::create("Список", "/admin/tg-bot-notification")->fetch();
|
||||
$btn .= SuccessBtn::create("Редактировать", "/admin/tg-bot-notification/update/" . $tg->id)->fetch();
|
||||
$btn .= DangerBtn::create("Удалить", "/admin/tg-bot-notification/delete/" . $tg->id)->fetch();
|
||||
return $btn;
|
||||
});
|
||||
$table->rows([
|
||||
'status' => (function ($data) {
|
||||
return \kernel\app_modules\tgbot\models\TgbotNotification::getStatus()[$data];
|
||||
})
|
||||
]);
|
||||
$table->create();
|
||||
$table->render();
|
@ -8,6 +8,14 @@ use app\modules\tgbot\models\Tgbot;
|
||||
$form = new \itguild\forms\ActiveForm();
|
||||
$form->beginForm(isset($model) ? "/admin/tg-bot/edit/" . $model->id : "/admin/tg-bot");
|
||||
|
||||
$form->field(class: \itguild\forms\inputs\TextInput::class, name: "user_id", params: [
|
||||
'class' => "form-control",
|
||||
'placeholder' => 'User ID',
|
||||
'value' => $model->user_id ?? ''
|
||||
])
|
||||
->setLabel("User ID")
|
||||
->render();
|
||||
|
||||
$form->field(class: \itguild\forms\inputs\TextInput::class, name: "bot_id", params: [
|
||||
'class' => "form-control",
|
||||
'placeholder' => 'Bot ID',
|
||||
|
@ -15,7 +15,7 @@ use kernel\modules\menu\table\columns\MenuViewActionColumn;
|
||||
|
||||
$view->setTitle("Список существующих диалогов");
|
||||
|
||||
$table = new ListEloquentTable(new EloquentDataProvider(\app\modules\tgbot\models\Tgbot::class, [
|
||||
$table = new ListEloquentTable(new EloquentDataProvider(\kernel\app_modules\tgbot\models\Tgbot::query()->orderBy("id", "DESC"), [
|
||||
'currentPage' => $page_number,
|
||||
'perPage' => 8,
|
||||
'params' => ["class" => "table table-bordered", "border" => "2"],
|
||||
@ -31,7 +31,7 @@ $table->beforePrint(function () {
|
||||
$table->columns([
|
||||
"status" => [
|
||||
"value" => function ($cell) {
|
||||
return \app\modules\tgbot\models\Tgbot::getStatus()[$cell];
|
||||
return \app\modules\tgbot\models\Tgbot::getStatus()[$cell] ?? 0;
|
||||
}
|
||||
],
|
||||
"username" => [
|
||||
|
@ -71,10 +71,15 @@ class MigrationController extends ConsoleController
|
||||
$dmr = new DatabaseMigrationRepository(App::$db->capsule->getDatabaseManager(), 'migration');
|
||||
|
||||
$m = new Migrator($dmr, App::$db->capsule->getDatabaseManager(), new Filesystem());
|
||||
if (\kernel\App::$db->schema->hasTable('option')) {
|
||||
$migrationPaths = array_merge($this->moduleService->getModulesMigrationsPaths(), [ROOT_DIR . '/migrations']);
|
||||
} else {
|
||||
$migrationPaths = [ROOT_DIR . '/migrations'];
|
||||
if (isset($this->argv['path'])){
|
||||
$migrationPaths = [ROOT_DIR . $this->argv['path']];
|
||||
}
|
||||
else {
|
||||
if (\kernel\App::$db->schema->hasTable('option')) {
|
||||
$migrationPaths = array_merge($this->moduleService->getModulesMigrationsPaths(), [ROOT_DIR . '/migrations']);
|
||||
} else {
|
||||
$migrationPaths = [ROOT_DIR . '/migrations'];
|
||||
}
|
||||
}
|
||||
|
||||
$res = $m->run($migrationPaths);
|
||||
@ -94,7 +99,13 @@ class MigrationController extends ConsoleController
|
||||
|
||||
$m = new Migrator($dmr, App::$db->capsule->getDatabaseManager(), new Filesystem());
|
||||
//$migrationPaths = array_merge(App::$migrationsPaths, [WORKSPACE_DIR . '/console/migrations']);
|
||||
$migrationPaths = [ROOT_DIR . '/migrations'];
|
||||
if (isset($this->argv['path'])){
|
||||
$migrationPaths = [ROOT_DIR . $this->argv['path']];
|
||||
}
|
||||
else {
|
||||
$migrationPaths = [ROOT_DIR . '/migrations'];
|
||||
}
|
||||
|
||||
$res = $m->rollback($migrationPaths, ['step' => $step]);
|
||||
print_r($step);
|
||||
foreach ($res as $re) {
|
||||
|
@ -40,9 +40,54 @@ class ImageGD
|
||||
imagedestroy($this->img);
|
||||
}
|
||||
|
||||
public function getBase64(): string
|
||||
{
|
||||
ob_start ();
|
||||
imagepng($this->img);
|
||||
$image_data = ob_get_contents ();
|
||||
ob_end_clean ();
|
||||
|
||||
imagedestroy($this->img);
|
||||
return base64_encode ($image_data);
|
||||
}
|
||||
|
||||
public function makeCornersForImage($radius, $background): void
|
||||
{
|
||||
// включаем режим сопряжения цветов
|
||||
imagealphablending($this->img, true);
|
||||
// размер исходной картинки
|
||||
$width = imagesx($this->img);
|
||||
$height = imagesy($this->img);
|
||||
// создаем изображение для углов
|
||||
$corner = imagecreatetruecolor($radius, $radius);
|
||||
imagealphablending($corner, false);
|
||||
// прозрачный цвет
|
||||
$trans = imagecolorallocatealpha($corner, 255, 255, 255, 127);
|
||||
// заливаем картинку для углов
|
||||
imagefill($corner, 0, 0, $background);
|
||||
// рисуем прозрачный эллипс
|
||||
imagefilledellipse($corner, $radius, $radius, $radius * 2, $radius * 2, $trans);
|
||||
// массив положений. Для расположения по углам
|
||||
$positions = array(
|
||||
array(0, 0),
|
||||
array($width - $radius, 0),
|
||||
array($width - $radius, $height - $radius),
|
||||
array(0, $height - $radius),
|
||||
);
|
||||
// накладываем на углы картинки изображение с прозрачными эллипсами
|
||||
foreach ($positions as $pos) {
|
||||
imagecopyresampled($this->img, $corner, $pos[0], $pos[1], 0, 0, $radius, $radius, $radius, $radius);
|
||||
// поворачиваем картинку с эллипсов каждый раз на 90 градусов
|
||||
$corner = imagerotate($corner, -90, $background);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
protected function hexToRgb(string $hex)
|
||||
{
|
||||
return sscanf($hex, "#%02x%02x%02x");
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "Kernel",
|
||||
"version": "0.1.2",
|
||||
"version": "0.1.3",
|
||||
"author": "ITGuild",
|
||||
"slug": "kernel",
|
||||
"type": "kernel",
|
||||
|
@ -6,6 +6,7 @@ use Exception;
|
||||
use JetBrains\PhpStorm\NoReturn;
|
||||
use kernel\AdminController;
|
||||
use kernel\FileUpload;
|
||||
use kernel\Flash;
|
||||
use kernel\models\Menu;
|
||||
use kernel\modules\menu\models\forms\CreateMenuForm;
|
||||
use kernel\modules\menu\service\MenuService;
|
||||
@ -46,6 +47,7 @@ class MenuController extends AdminController
|
||||
$this->redirect("/admin/settings/menu/view/" . $menuItem->id, code: 302);
|
||||
}
|
||||
}
|
||||
Flash::setMessage("error", $menuForm->getErrorsStr());
|
||||
$this->redirect("/admin/settings/menu/create", code: 302);
|
||||
}
|
||||
|
||||
|
@ -13,21 +13,28 @@ use kernel\services\TokenService;
|
||||
class SecureService
|
||||
{
|
||||
|
||||
public static function createSecretCode(User $user): void
|
||||
public static function createSecretCode(User $user): SecretCode
|
||||
{
|
||||
$secretCode = new SecretCode();
|
||||
$secretCode->user_id = $user->id;
|
||||
$secretCode->code = mt_rand(100000, 999999);
|
||||
$secretCode->code_expires_at = date("Y-m-d H:i:s", strtotime("+5 minutes"));;
|
||||
$secretCode->save();
|
||||
|
||||
return $secretCode;
|
||||
}
|
||||
|
||||
public static function updateSecretCode(User $user): void
|
||||
public static function updateSecretCode(User $user): SecretCode
|
||||
{
|
||||
$secretCode = SecretCode::where('user_id', $user->id)->first();
|
||||
if(!$secretCode){
|
||||
return self::createSecretCode($user);
|
||||
}
|
||||
$secretCode->code = mt_rand(100000, 999999);
|
||||
$secretCode->code_expires_at = date("Y-m-d H:i:s", strtotime("+5 minutes"));;
|
||||
$secretCode->save();
|
||||
|
||||
return $secretCode;
|
||||
}
|
||||
|
||||
public static function getCodeByUserId(int $user_id)
|
||||
|
@ -11,7 +11,11 @@ class UserService
|
||||
|
||||
public function create(FormModel $form_model): false|User
|
||||
{
|
||||
$model = new User();
|
||||
$model = User::where("username", $form_model->getItem('username'))->first();
|
||||
if ($model){
|
||||
return $model;
|
||||
}
|
||||
$model = new User();
|
||||
$model->username = $form_model->getItem('username');
|
||||
$model->email = $form_model->getItem('email');
|
||||
$model->password_hash = password_hash($form_model->getItem('password'), PASSWORD_DEFAULT);
|
||||
|
BIN
resources/Montserrat-Medium.ttf
Normal file
BIN
resources/Montserrat-Medium.ttf
Normal file
Binary file not shown.
BIN
resources/Montserrat-SemiBold.ttf
Normal file
BIN
resources/Montserrat-SemiBold.ttf
Normal file
Binary file not shown.
BIN
resources/arialmt.ttf
Normal file
BIN
resources/arialmt.ttf
Normal file
Binary file not shown.
7
resources/main/css/bootstrap.min.css
vendored
Normal file
7
resources/main/css/bootstrap.min.css
vendored
Normal file
File diff suppressed because one or more lines are too long
12
resources/main/css/bootstrap/_media.css
Normal file
12
resources/main/css/bootstrap/_media.css
Normal file
@ -0,0 +1,12 @@
|
||||
.media {
|
||||
display: -webkit-box;
|
||||
display: -ms-flexbox;
|
||||
display: flex;
|
||||
-webkit-box-align: start;
|
||||
-ms-flex-align: start;
|
||||
align-items: flex-start; }
|
||||
|
||||
.media-body {
|
||||
-webkit-box-flex: 1;
|
||||
-ms-flex: 1;
|
||||
flex: 1; }
|
0
resources/main/css/bootstrap/mixins/_visibility.css
Normal file
0
resources/main/css/bootstrap/mixins/_visibility.css
Normal file
10
resources/main/css/bootstrap/utilities/_stretched-link.css
Normal file
10
resources/main/css/bootstrap/utilities/_stretched-link.css
Normal file
@ -0,0 +1,10 @@
|
||||
.stretched-link::after {
|
||||
position: absolute;
|
||||
top: 0;
|
||||
right: 0;
|
||||
bottom: 0;
|
||||
left: 0;
|
||||
z-index: 1;
|
||||
pointer-events: auto;
|
||||
content: "";
|
||||
background-color: rgba(0, 0, 0, 0); }
|
8288
resources/main/css/style.css
Normal file
8288
resources/main/css/style.css
Normal file
File diff suppressed because it is too large
Load Diff
60
resources/main/css/tg.css
Normal file
60
resources/main/css/tg.css
Normal file
@ -0,0 +1,60 @@
|
||||
* {
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
box-sizing: border-box;
|
||||
}
|
||||
|
||||
body {
|
||||
color: var(--tg-theme-text-color);
|
||||
background: var(--tg-theme-bg-color);
|
||||
}
|
||||
|
||||
.Main {
|
||||
width: 100%;
|
||||
padding: 25px;
|
||||
text-align: center;
|
||||
|
||||
}
|
||||
|
||||
h1 {
|
||||
margin-top: 40px;
|
||||
margin-bottom: 10px;
|
||||
}
|
||||
|
||||
img {
|
||||
width: 70px;
|
||||
margin: 30px auto;
|
||||
}
|
||||
|
||||
.btn {
|
||||
border: 0;
|
||||
border-radius: 5px;
|
||||
margin-top: 50px;
|
||||
height: 60px;
|
||||
width: 200px;
|
||||
font-style: 20px;
|
||||
font-weight: 500;
|
||||
cursor: pointer;
|
||||
color: var(--tg-theme-button-text-color);
|
||||
background: var(--tg-theme-button-color);
|
||||
}
|
||||
|
||||
form {
|
||||
display: none;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
input {
|
||||
outline: none;
|
||||
border-radius: 5px;
|
||||
border: 2px solid #535353;
|
||||
padding: 15px 10px;
|
||||
margin: 10px 0 0;
|
||||
background: var(--tg-theme-section-separator-color);
|
||||
color: var(--tg-theme-text-color);
|
||||
transition: all .2s;
|
||||
}
|
||||
|
||||
input:focus {
|
||||
border-color: var(--tg-theme-secondary-bg-color)
|
||||
}
|
15
resources/main/css/tgApp.css
Normal file
15
resources/main/css/tgApp.css
Normal file
@ -0,0 +1,15 @@
|
||||
#cardBox {
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
#btnBox {
|
||||
margin-bottom: 10px;
|
||||
}
|
||||
|
||||
#btnBox a{
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.card {
|
||||
margin-bottom: 10px;
|
||||
}
|
BIN
resources/main/images/33.png
Normal file
BIN
resources/main/images/33.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 205 KiB |
BIN
resources/main/images/bg_1.jpg
Normal file
BIN
resources/main/images/bg_1.jpg
Normal file
Binary file not shown.
After Width: | Height: | Size: 120 KiB |
BIN
resources/main/images/l.gif
Normal file
BIN
resources/main/images/l.gif
Normal file
Binary file not shown.
After Width: | Height: | Size: 38 KiB |
BIN
resources/main/images/logo.jpg
Normal file
BIN
resources/main/images/logo.jpg
Normal file
Binary file not shown.
After Width: | Height: | Size: 36 KiB |
7
resources/main/js/bootstrap.min.js
vendored
Normal file
7
resources/main/js/bootstrap.min.js
vendored
Normal file
File diff suppressed because one or more lines are too long
2
resources/main/js/jquery.min.js
vendored
Normal file
2
resources/main/js/jquery.min.js
vendored
Normal file
File diff suppressed because one or more lines are too long
19
resources/main/js/main.js
Normal file
19
resources/main/js/main.js
Normal file
@ -0,0 +1,19 @@
|
||||
(function($) {
|
||||
|
||||
"use strict";
|
||||
|
||||
var fullHeight = function() {
|
||||
|
||||
$('.js-fullheight').css('height', $(window).height());
|
||||
$(window).resize(function(){
|
||||
$('.js-fullheight').css('height', $(window).height());
|
||||
});
|
||||
|
||||
};
|
||||
fullHeight();
|
||||
|
||||
$('#sidebarCollapse').on('click', function () {
|
||||
$('#sidebar').toggleClass('active');
|
||||
});
|
||||
|
||||
})(jQuery);
|
5
resources/main/js/popper.js
Normal file
5
resources/main/js/popper.js
Normal file
File diff suppressed because one or more lines are too long
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user