Compare commits
55 Commits
798c687547
...
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 | |||
74efe9e01e | |||
093b04c2c9 | |||
b24fac512a | |||
a71102eb05 | |||
7a7241746a | |||
95c3c0755b | |||
1cf2dc3d86 | |||
57d2f20255 | |||
5d671d03d2 | |||
d74a30f33e | |||
ea83698070 | |||
c4b3f46111 | |||
625089acd1 |
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
|
8
app/modules/card/CardModule.php
Normal file
8
app/modules/card/CardModule.php
Normal file
@ -0,0 +1,8 @@
|
||||
<?php
|
||||
|
||||
namespace app\modules\card;
|
||||
|
||||
class CardModule extends \kernel\app_modules\card\CardModule
|
||||
{
|
||||
|
||||
}
|
21
app/modules/card/controllers/CardController.php
Normal file
21
app/modules/card/controllers/CardController.php
Normal file
@ -0,0 +1,21 @@
|
||||
<?php
|
||||
|
||||
namespace app\modules\card\controllers;
|
||||
|
||||
use DragonCode\CardNumber\CardNumber;
|
||||
use DragonCode\CardNumber\Factories\BankFactory;
|
||||
use DragonCode\CardNumber\Formatters\BankFormatter;
|
||||
|
||||
class CardController extends \kernel\app_modules\card\controllers\CardController
|
||||
{
|
||||
|
||||
public function actionTestCard(): string
|
||||
{
|
||||
$formatter = BankFormatter::create();
|
||||
|
||||
$customer = BankFactory::create()->paymentType(2)->bank(323, 42, 75)->client(15);
|
||||
|
||||
return CardNumber::generate($customer, $formatter);
|
||||
}
|
||||
|
||||
}
|
11
app/modules/card/manifest.json
Normal file
11
app/modules/card/manifest.json
Normal file
@ -0,0 +1,11 @@
|
||||
{
|
||||
"name": "Card",
|
||||
"version": "0.1",
|
||||
"author": "ITGuild",
|
||||
"slug": "card",
|
||||
"description": "Card module",
|
||||
"module_class": "app\\modules\\card\\CardModule",
|
||||
"module_class_file": "{APP}/modules/card/CardModule.php",
|
||||
"routs": "routs/card.php",
|
||||
"migration_path": "migrations"
|
||||
}
|
15
app/modules/card/routs/card.php
Normal file
15
app/modules/card/routs/card.php
Normal file
@ -0,0 +1,15 @@
|
||||
<?php
|
||||
|
||||
use kernel\App;
|
||||
use kernel\CgRouteCollector;
|
||||
use Phroute\Phroute\RouteCollector;
|
||||
|
||||
include KERNEL_APP_MODULES_DIR . "/card/routs/card.php";
|
||||
|
||||
App::$collector->group(["prefix" => "admin"], function (CgRouteCollector $router) {
|
||||
App::$collector->group(["before" => "auth"], function (RouteCollector $router) {
|
||||
App::$collector->group(["prefix" => "card"], function (CGRouteCollector $router) {
|
||||
// App::$collector->get('/test', [\app\modules\card\controllers\CardController::class, 'actionTestCard']);
|
||||
});
|
||||
});
|
||||
});
|
@ -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 "";
|
||||
}
|
||||
|
||||
}
|
12
app/modules/tgbot/TgbotModule.php
Normal file
12
app/modules/tgbot/TgbotModule.php
Normal file
@ -0,0 +1,12 @@
|
||||
<?php
|
||||
|
||||
namespace app\modules\tgbot;
|
||||
|
||||
use kernel\Module;
|
||||
use kernel\modules\menu\service\MenuService;
|
||||
use kernel\services\MigrationService;
|
||||
|
||||
class TgbotModule extends \kernel\app_modules\tgbot\TgbotModule
|
||||
{
|
||||
|
||||
}
|
33
app/modules/tgbot/controllers/TgBotRestController.php
Normal file
33
app/modules/tgbot/controllers/TgBotRestController.php
Normal file
@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
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]);
|
||||
}
|
||||
|
||||
}
|
8
app/modules/tgbot/controllers/TgbotController.php
Normal file
8
app/modules/tgbot/controllers/TgbotController.php
Normal file
@ -0,0 +1,8 @@
|
||||
<?php
|
||||
|
||||
namespace app\modules\tgbot\controllers;
|
||||
|
||||
class TgbotController extends \kernel\app_modules\tgbot\controllers\TgbotController
|
||||
{
|
||||
|
||||
}
|
13
app/modules/tgbot/manifest.json
Normal file
13
app/modules/tgbot/manifest.json
Normal file
@ -0,0 +1,13 @@
|
||||
{
|
||||
"name": "Telegram Bot",
|
||||
"version": "0.3",
|
||||
"author": "ITGuild",
|
||||
"slug": "tgbot",
|
||||
"type": "entity",
|
||||
"description": "Telegram Bot Tools",
|
||||
"app_module_path": "{APP}/modules/{slug}",
|
||||
"module_class": "app\\modules\\tgbot\\TgbotModule",
|
||||
"module_class_file": "{APP}/modules/tgbot/TgbotModule.php",
|
||||
"routs": "routs/tgbot.php",
|
||||
"dependence": "menu"
|
||||
}
|
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();
|
||||
}
|
||||
}
|
19
app/modules/tgbot/models/Tgbot.php
Normal file
19
app/modules/tgbot/models/Tgbot.php
Normal file
@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
namespace app\modules\tgbot\models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
/**
|
||||
* @property integer $id
|
||||
* @property integer $bot_id
|
||||
* @property integer $dialog_id
|
||||
* @property string $username
|
||||
* @property string $first_name
|
||||
* @property string $last_name
|
||||
* @property integer $status
|
||||
*/
|
||||
class Tgbot extends \kernel\app_modules\tgbot\models\Tgbot
|
||||
{
|
||||
|
||||
}
|
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',
|
||||
];
|
||||
}
|
||||
|
||||
}
|
18
app/modules/tgbot/models/forms/CreateTgBotForm.php
Normal file
18
app/modules/tgbot/models/forms/CreateTgBotForm.php
Normal file
@ -0,0 +1,18 @@
|
||||
<?php
|
||||
|
||||
namespace app\modules\tgbot\models\forms;
|
||||
|
||||
use kernel\FormModel;
|
||||
|
||||
/**
|
||||
* @property integer $bot_id
|
||||
* @property integer $dialog_id
|
||||
* @property string $username
|
||||
* @property string $first_name
|
||||
* @property string $last_name
|
||||
* @property integer $status
|
||||
*/
|
||||
class CreateTgBotForm extends \kernel\app_modules\tgbot\models\forms\CreateTgBotForm
|
||||
{
|
||||
|
||||
}
|
24
app/modules/tgbot/routs/tgbot.php
Normal file
24
app/modules/tgbot/routs/tgbot.php
Normal file
@ -0,0 +1,24 @@
|
||||
<?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']);
|
||||
});
|
||||
});
|
||||
});
|
15
app/modules/tgbot/services/TgBotService.php
Normal file
15
app/modules/tgbot/services/TgBotService.php
Normal file
@ -0,0 +1,15 @@
|
||||
<?php
|
||||
|
||||
namespace app\modules\tgbot\services;
|
||||
|
||||
use app\modules\tgbot\models\Tgbot;
|
||||
use kernel\app_modules\tag\models\Tag;
|
||||
use kernel\FormModel;
|
||||
use kernel\helpers\Debug;
|
||||
use kernel\helpers\Slug;
|
||||
use kernel\services\ModuleService;
|
||||
|
||||
class TgBotService extends \kernel\app_modules\tgbot\services\TgBotService
|
||||
{
|
||||
|
||||
}
|
83
app/modules/tgbot/views/tgbot/form.php
Normal file
83
app/modules/tgbot/views/tgbot/form.php
Normal file
@ -0,0 +1,83 @@
|
||||
<?php
|
||||
/**
|
||||
* @var Tgbot $model
|
||||
*/
|
||||
|
||||
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: "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: "username", params: [
|
||||
'class' => "form-control",
|
||||
'placeholder' => 'Username',
|
||||
'value' => $model->username ?? ''
|
||||
])
|
||||
->setLabel("Username")
|
||||
->render();
|
||||
|
||||
$form->field(class: \itguild\forms\inputs\TextInput::class, name: "first_name", params: [
|
||||
'class' => "form-control",
|
||||
'placeholder' => 'First name',
|
||||
'value' => $model->first_name ?? ''
|
||||
])
|
||||
->setLabel("First name")
|
||||
->render();
|
||||
|
||||
$form->field(class: \itguild\forms\inputs\TextInput::class, name: "last_name", params: [
|
||||
'class' => "form-control",
|
||||
'placeholder' => 'Last name',
|
||||
'value' => $model->last_name ?? ''
|
||||
])
|
||||
->setLabel("Last name")
|
||||
->render();
|
||||
|
||||
|
||||
$form->field(\itguild\forms\inputs\Select::class, 'status', [
|
||||
'class' => "form-control",
|
||||
'value' => $model->status ?? ''
|
||||
])
|
||||
->setLabel("Статус")
|
||||
->setOptions(Tgbot::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();
|
41
app/modules/tgbot/views/tgbot/index.php
Normal file
41
app/modules/tgbot/views/tgbot/index.php
Normal file
@ -0,0 +1,41 @@
|
||||
<?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;
|
||||
|
||||
$view->setTitle("Список существующих диалогов");
|
||||
|
||||
$table = new ListEloquentTable(new EloquentDataProvider(\app\modules\tgbot\models\Tgbot::class, [
|
||||
'currentPage' => $page_number,
|
||||
'perPage' => 8,
|
||||
'params' => ["class" => "table table-bordered", "border" => "2"],
|
||||
'baseUrl' => "/admin/tg-bot",
|
||||
]));
|
||||
|
||||
$table->beforePrint(function () {
|
||||
return PrimaryBtn::create("Создать", "/admin/tg-bot/create")->fetch();
|
||||
});
|
||||
|
||||
$table->columns([
|
||||
"status" => [
|
||||
"value" => function ($cell) {
|
||||
return \app\modules\tgbot\models\Tgbot::getStatus()[$cell];
|
||||
}]
|
||||
]);
|
||||
|
||||
|
||||
$table->addAction(\kernel\IGTabel\action_column\ViewActionColumn::class);
|
||||
$table->addAction(\kernel\IGTabel\action_column\DeleteActionColumn::class);
|
||||
$table->addAction(\kernel\IGTabel\action_column\EditActionColumn::class);
|
||||
$table->create();
|
||||
$table->render();
|
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>
|
30
app/modules/tgbot/views/tgbot/view.php
Normal file
30
app/modules/tgbot/views/tgbot/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",
|
||||
]));
|
||||
$table->beforePrint(function () use ($tg) {
|
||||
$btn = PrimaryBtn::create("Список", "/admin/tg-bot")->fetch();
|
||||
$btn .= SuccessBtn::create("Редактировать", "/admin/tg-bot/update/" . $tg->id)->fetch();
|
||||
$btn .= DangerBtn::create("Удалить", "/admin/tg-bot/delete/" . $tg->id)->fetch();
|
||||
return $btn;
|
||||
});
|
||||
$table->rows([
|
||||
'status' => (function ($data) {
|
||||
return \app\modules\tgbot\models\Tgbot::getStatus()[$data];
|
||||
})
|
||||
]);
|
||||
$table->create();
|
||||
$table->render();
|
@ -21,7 +21,10 @@
|
||||
"guzzlehttp/guzzle": "^7.9",
|
||||
"phpmailer/phpmailer": "^6.9",
|
||||
"zircote/swagger-php": "^4.11",
|
||||
"doctrine/annotations": "^2.0"
|
||||
"doctrine/annotations": "^2.0",
|
||||
"ext-gd": "*",
|
||||
"dragon-code/card-number": "^1.6",
|
||||
"endroid/qr-code": "^6.0"
|
||||
},
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
|
@ -36,7 +36,9 @@ class FileUpload
|
||||
$newFileName = md5(time() . $this->fileName) . '.' . $this->fileExtension;
|
||||
if (in_array($this->fileExtension, $this->allowedFileExtensions)) {
|
||||
$this->uploadDir = $uploadDir . mb_substr($newFileName, 0, 2) . '/' . mb_substr($newFileName, 2, 2) . '/';
|
||||
mkdir(ROOT_DIR . $this->uploadDir, 0777, true);
|
||||
$oldMask = umask(0);
|
||||
mkdir(ROOT_DIR . $this->uploadDir, 0775, true);
|
||||
umask($oldMask);
|
||||
$uploadFileDir = ROOT_DIR . $this->uploadDir;
|
||||
$this->destPath = $uploadFileDir . $newFileName;
|
||||
$this->uploadFile = $this->uploadDir . $newFileName;
|
||||
@ -49,7 +51,9 @@ class FileUpload
|
||||
} else {
|
||||
if (in_array($this->fileExtension, $this->allowedFileExtensions)) {
|
||||
$this->uploadDir = $uploadDir;
|
||||
mkdir(ROOT_DIR . $this->uploadDir, 0777, true);
|
||||
$oldMask = umask(0);
|
||||
mkdir(ROOT_DIR . $this->uploadDir, 0775, true);
|
||||
umask($oldMask);
|
||||
$uploadFileDir = ROOT_DIR . $this->uploadDir;
|
||||
$this->destPath = $uploadFileDir . $this->fileName;
|
||||
$this->uploadFile = $this->uploadDir . $this->fileName;
|
||||
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -6,9 +6,9 @@ class PrimaryBtn
|
||||
{
|
||||
protected string $btn = '';
|
||||
|
||||
public function __construct(string $title, string $url)
|
||||
public function __construct(string $title, string $url, $width)
|
||||
{
|
||||
$this->btn = "<a class='btn btn-primary' href='$url' style='margin: 3px; width: 150px;' >$title</a>";
|
||||
$this->btn = "<a class='btn btn-primary' href='$url' style='margin: 3px; width: '$width >$title</a>";
|
||||
}
|
||||
|
||||
public function fetch(): string
|
||||
@ -16,9 +16,9 @@ class PrimaryBtn
|
||||
return $this->btn;
|
||||
}
|
||||
|
||||
public static function create(string $title, string $url): PrimaryBtn
|
||||
public static function create(string $title, string $url, $width = '150px'): PrimaryBtn
|
||||
{
|
||||
return new self($title, $url);
|
||||
return new self($title, $url, $width);
|
||||
}
|
||||
|
||||
}
|
@ -17,13 +17,32 @@ class RestController
|
||||
return [];
|
||||
}
|
||||
|
||||
protected function filters(): array
|
||||
{
|
||||
return [];
|
||||
}
|
||||
|
||||
#[NoReturn] public function actionIndex(): void
|
||||
{
|
||||
$request = new Request();
|
||||
$get = $request->get();
|
||||
$page = $request->get('page') ?? 1;
|
||||
$perPage = $request->get('per_page') ?? 10;
|
||||
$query = $this->model->query();
|
||||
|
||||
if ($this->filters()) {
|
||||
foreach ($this->filters() as $filter){
|
||||
if (key_exists($filter, $get)){
|
||||
if (is_numeric($get[$filter])){
|
||||
$query->where($filter, $get[$filter]);
|
||||
}
|
||||
elseif (is_string($get[$filter])){
|
||||
$query->where($filter,'like', '%' . $get[$filter] . '%');
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ($page > 1) {
|
||||
$query->skip(($page - 1) * $perPage)->take($perPage);
|
||||
} else {
|
||||
@ -31,7 +50,7 @@ class RestController
|
||||
}
|
||||
|
||||
$expand = $this->expand();
|
||||
$expandParams = explode( ",", $request->get('expand') ?? "");
|
||||
$expandParams = explode(",", $request->get('expand') ?? "");
|
||||
$finalExpand = array_intersect($expandParams, $expand);
|
||||
if ($finalExpand) {
|
||||
$res = $query->get()->load($finalExpand)->toArray();
|
||||
@ -46,14 +65,14 @@ class RestController
|
||||
{
|
||||
$expand = $this->expand();
|
||||
$request = new Request();
|
||||
$expandParams = explode( ",", $request->get('expand') ?? "");
|
||||
$expandParams = explode(",", $request->get('expand') ?? "");
|
||||
$model = $this->model->where("id", $id)->first();
|
||||
$finalExpand = array_intersect($expandParams, $expand);
|
||||
if ($finalExpand){
|
||||
if ($finalExpand) {
|
||||
$model->load($finalExpand);
|
||||
}
|
||||
$res = [];
|
||||
if ($model){
|
||||
if ($model) {
|
||||
$res = $model->toArray();
|
||||
}
|
||||
|
||||
@ -64,7 +83,7 @@ class RestController
|
||||
{
|
||||
$model = $this->model->where("id", $id)->first();
|
||||
$res = [];
|
||||
if ($model){
|
||||
if ($model) {
|
||||
$res = $model->toArray();
|
||||
}
|
||||
|
||||
@ -78,7 +97,7 @@ class RestController
|
||||
{
|
||||
$request = new Request();
|
||||
$data = $request->post();
|
||||
foreach ($this->model->getFillable() as $item){
|
||||
foreach ($this->model->getFillable() as $item) {
|
||||
$this->model->{$item} = $data[$item] ?? null;
|
||||
}
|
||||
$this->model->save();
|
||||
@ -93,8 +112,10 @@ class RestController
|
||||
|
||||
$model = $this->model->where('id', $id)->first();
|
||||
|
||||
foreach ($model->getFillable() as $item){
|
||||
$model->{$item} = $data[$item] ?? null;
|
||||
foreach ($model->getFillable() as $item) {
|
||||
if (!empty($data[$item])) {
|
||||
$model->{$item} = $data[$item] ?? null;
|
||||
}
|
||||
}
|
||||
|
||||
$model->save();
|
||||
@ -115,5 +136,4 @@ class RestController
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
@ -26,10 +26,13 @@
|
||||
<div class="wrapper d-flex align-items-stretch">
|
||||
<nav id="sidebar">
|
||||
<div class="p-4 pt-5">
|
||||
<a href="#" class="img logo rounded-circle mb-5"
|
||||
style="background-image: url(/resources/admin_theme/images/logo.jpg);"></a>
|
||||
<a href="<?= '/admin/user/profile' ?>" class="img logo rounded-circle mb-5"
|
||||
style="background-image: url(<?= \kernel\modules\user\service\UserService::getAuthUserPhoto() ?? '/resources/default_user_photo/noPhoto.png' ?>);">
|
||||
</a>
|
||||
<p>
|
||||
<?= \kernel\modules\user\service\UserService::getAuthUsername() ?>
|
||||
<a href="<?= '/admin/user/profile' ?>">
|
||||
<?= \kernel\modules\user\service\UserService::getAuthUsername() ?>
|
||||
</a>
|
||||
</p>
|
||||
<?php \kernel\widgets\MenuWidget::create()->run(); ?>
|
||||
<div class="footer">
|
||||
@ -74,15 +77,15 @@
|
||||
</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>
|
||||
<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>
|
||||
<button type="button" class="btn-close closeAlertBtn"></button>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
<?= $content ?>
|
||||
|
91
kernel/app_modules/card/CardModule.php
Normal file
91
kernel/app_modules/card/CardModule.php
Normal file
@ -0,0 +1,91 @@
|
||||
<?php
|
||||
|
||||
namespace kernel\app_modules\card;
|
||||
|
||||
use kernel\helpers\Debug;
|
||||
use kernel\Module;
|
||||
use kernel\modules\menu\service\MenuService;
|
||||
use kernel\services\ConsoleService;
|
||||
use kernel\services\MigrationService;
|
||||
|
||||
class CardModule extends Module
|
||||
{
|
||||
|
||||
public MenuService $menuService;
|
||||
public ConsoleService $consoleService;
|
||||
public MigrationService $migrationService;
|
||||
public function __construct()
|
||||
{
|
||||
$this->menuService = new MenuService();
|
||||
$this->consoleService = new ConsoleService();
|
||||
$this->migrationService = new MigrationService();
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function init(): void
|
||||
{
|
||||
$this->migrationService->runAtPath("{KERNEL_APP_MODULES}/card/migrations");
|
||||
|
||||
$this->consoleService->runComposerRequire("dragon-code/card-number");
|
||||
$this->consoleService->runComposerRequire("endroid/qr-code");
|
||||
|
||||
$this->menuService->createItem([
|
||||
"label" => "Card",
|
||||
"url" => "/admin/card",
|
||||
"slug" => "card",
|
||||
]);
|
||||
|
||||
$this->menuService->createItem([
|
||||
"label" => "Список карт",
|
||||
"url" => "/admin/card",
|
||||
"slug" => "card_list",
|
||||
"parent_slug" => "card"
|
||||
]);
|
||||
|
||||
$this->menuService->createItem([
|
||||
"label" => "Шаблоны карт",
|
||||
"url" => "/admin/card_template",
|
||||
"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"
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function deactivate(): void
|
||||
{
|
||||
$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));
|
||||
}
|
||||
|
||||
}
|
102
kernel/app_modules/card/controllers/CardController.php
Normal file
102
kernel/app_modules/card/controllers/CardController.php
Normal file
@ -0,0 +1,102 @@
|
||||
<?php
|
||||
|
||||
namespace kernel\app_modules\card\controllers;
|
||||
|
||||
use Exception;
|
||||
use JetBrains\PhpStorm\NoReturn;
|
||||
use kernel\AdminController;
|
||||
use kernel\app_modules\card\models\forms\CreateCardForm;
|
||||
use kernel\app_modules\card\models\Card;
|
||||
use kernel\app_modules\card\services\CardService;
|
||||
use kernel\Flash;
|
||||
use kernel\helpers\Debug;
|
||||
|
||||
class CardController extends AdminController
|
||||
{
|
||||
private CardService $cardService;
|
||||
protected function init(): void
|
||||
{
|
||||
parent::init();
|
||||
$this->cgView->viewPath = KERNEL_APP_MODULES_DIR . "/card/views/";
|
||||
$this->cardService = new CardService();
|
||||
}
|
||||
|
||||
public function actionCreate(): void
|
||||
{
|
||||
$this->cgView->render("form.php");
|
||||
}
|
||||
|
||||
#[NoReturn] public function actionAdd(): void
|
||||
{
|
||||
$cardForm = new CreateCardForm();
|
||||
$cardForm->load($_REQUEST);
|
||||
if ($cardForm->validate()){
|
||||
$card = $this->cardService->create($cardForm);
|
||||
if ($card){
|
||||
$this->redirect("/admin/card/" . $card->id);
|
||||
}
|
||||
}
|
||||
Flash::setMessage("error", $cardForm->getErrorsStr());
|
||||
$this->redirect("/admin/card/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 = Card::find($id);
|
||||
|
||||
if (!$card){
|
||||
throw new Exception(message: "The card not found");
|
||||
}
|
||||
$this->cgView->render("view.php", ['card' => $card]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws Exception
|
||||
*/
|
||||
public function actionUpdate($id): void
|
||||
{
|
||||
$model = Card::find($id);
|
||||
if (!$model){
|
||||
throw new Exception(message: "The card not found");
|
||||
}
|
||||
|
||||
$this->cgView->render("form.php", ['model' => $model]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws Exception
|
||||
*/
|
||||
public function actionEdit($id): void
|
||||
{
|
||||
$card = Card::find($id);
|
||||
if (!$card){
|
||||
throw new Exception(message: "The card not found");
|
||||
}
|
||||
$cardForm = new CreateCardForm();
|
||||
$cardService = new CardService();
|
||||
$cardForm->load($_REQUEST);
|
||||
if ($cardForm->validate()) {
|
||||
$card = $cardService->update($cardForm, $card);
|
||||
if ($card) {
|
||||
$this->redirect("/admin/card/" . $card->id);
|
||||
}
|
||||
}
|
||||
Flash::setMessage("error", $cardForm->getErrorsStr());
|
||||
$this->redirect("/admin/card/update/" . $id);
|
||||
}
|
||||
|
||||
#[NoReturn] public function actionDelete($id): void
|
||||
{
|
||||
$card = Card::find($id)->first();
|
||||
$card->delete();
|
||||
$this->redirect("/admin/card/");
|
||||
}
|
||||
}
|
@ -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/");
|
||||
}
|
||||
|
||||
}
|
25
kernel/app_modules/card/controllers/CardRestController.php
Normal file
25
kernel/app_modules/card/controllers/CardRestController.php
Normal file
@ -0,0 +1,25 @@
|
||||
<?php
|
||||
|
||||
namespace kernel\app_modules\card\controllers;
|
||||
|
||||
use kernel\app_modules\card\models\Card;
|
||||
use kernel\RestController;
|
||||
|
||||
class CardRestController extends RestController
|
||||
{
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->model = new Card();
|
||||
}
|
||||
|
||||
protected function expand(): array
|
||||
{
|
||||
return ["cardFile"];
|
||||
}
|
||||
|
||||
protected function filters(): array
|
||||
{
|
||||
return ['pin', 'user_id', 'payment_type', 'bank_id', 'info', 'program', 'username', 'status'];
|
||||
}
|
||||
}
|
125
kernel/app_modules/card/controllers/CardTemplateController.php
Normal file
125
kernel/app_modules/card/controllers/CardTemplateController.php
Normal file
@ -0,0 +1,125 @@
|
||||
<?php
|
||||
|
||||
namespace kernel\app_modules\card\controllers;
|
||||
|
||||
use Exception;
|
||||
use JetBrains\PhpStorm\NoReturn;
|
||||
use kernel\AdminController;
|
||||
use kernel\app_modules\card\models\Card;
|
||||
use kernel\app_modules\card\models\CardTemplate;
|
||||
use kernel\app_modules\card\models\forms\CreateCardForm;
|
||||
use kernel\app_modules\card\models\forms\CreateCardTemplateForm;
|
||||
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 CardTemplateController extends AdminController
|
||||
{
|
||||
|
||||
private CardService $cardService;
|
||||
private CardTemplateService $cardTemplateService;
|
||||
protected function init(): void
|
||||
{
|
||||
parent::init();
|
||||
$this->cgView->viewPath = KERNEL_APP_MODULES_DIR . "/card/views/card_template/";
|
||||
$this->cardService = new CardService();
|
||||
$this->cardTemplateService = new CardTemplateService();
|
||||
}
|
||||
|
||||
public function actionCreate(): void
|
||||
{
|
||||
$this->cgView->render("form.php");
|
||||
}
|
||||
|
||||
#[NoReturn] public function actionAdd(): void
|
||||
{
|
||||
$cardForm = new CreateCardTemplateForm();
|
||||
$cardForm->load($_REQUEST);
|
||||
|
||||
if (isset($_FILES['path']) && $_FILES['path']['error'] === UPLOAD_ERR_OK) {
|
||||
$file = new FileUpload($_FILES['path'], ['jpg', 'jpeg', 'png']);
|
||||
$file->upload();
|
||||
$cardForm->setItem('path', $file->getUploadFile());
|
||||
}
|
||||
|
||||
if ($cardForm->validate()){
|
||||
$cardTemplate = $this->cardTemplateService->create($cardForm);
|
||||
if ($cardTemplate){
|
||||
$this->redirect("/admin/card_template/" . $cardTemplate->id);
|
||||
}
|
||||
}
|
||||
|
||||
Flash::setMessage("error", $cardForm->getErrorsStr());
|
||||
$this->redirect("/admin/card_template/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 = CardTemplate::find($id);
|
||||
|
||||
if (!$card){
|
||||
throw new Exception(message: "The card template not found");
|
||||
}
|
||||
$this->cgView->render("view.php", ['card' => $card]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws Exception
|
||||
*/
|
||||
public function actionUpdate($id): void
|
||||
{
|
||||
$model = CardTemplate::find($id);
|
||||
if (!$model){
|
||||
throw new Exception(message: "The card template not found");
|
||||
}
|
||||
|
||||
$this->cgView->render("form.php", ['model' => $model]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws Exception
|
||||
*/
|
||||
public function actionEdit($id): void
|
||||
{
|
||||
$cardTemplate = CardTemplate::find($id);
|
||||
if (!$cardTemplate){
|
||||
throw new Exception(message: "The card not found");
|
||||
}
|
||||
$cardTemplateForm = new CreateCardTemplateForm();
|
||||
$cardTemplateForm->load($_REQUEST);
|
||||
|
||||
if (isset($_FILES['path']) && $_FILES['path']['error'] === UPLOAD_ERR_OK) {
|
||||
$file = new FileUpload($_FILES['path'], ['jpg', 'jpeg', 'png']);
|
||||
$file->upload();
|
||||
$cardTemplateForm->setItem('path', $file->getUploadFile());
|
||||
}
|
||||
|
||||
if ($cardTemplateForm->validateForUpdate()) {
|
||||
$card = $this->cardTemplateService->update($cardTemplateForm, $cardTemplate);
|
||||
if ($card) {
|
||||
$this->redirect("/admin/card_template/" . $card->id);
|
||||
}
|
||||
}
|
||||
Flash::setMessage("error", $cardTemplateForm->getErrorsStr());
|
||||
|
||||
$this->redirect("/admin/card_template/update/" . $id);
|
||||
}
|
||||
|
||||
#[NoReturn] public function actionDelete($id): void
|
||||
{
|
||||
$card = CardTemplate::find($id)->first();
|
||||
$card->delete();
|
||||
$this->redirect("/admin/card_template/");
|
||||
}
|
||||
|
||||
}
|
@ -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/");
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,105 @@
|
||||
<?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('card_template', function (Blueprint $table) {
|
||||
$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();
|
||||
});
|
||||
|
||||
\kernel\App::$db->schema->create('card_file', function (Blueprint $table) {
|
||||
$table->increments('id');
|
||||
$table->string('file')->nullable(false);
|
||||
$table->integer('card_id')->nullable(false);
|
||||
|
||||
$table->integer('status')->default(1);
|
||||
$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);
|
||||
$table->integer('balance')->nullable(false)->default(0);
|
||||
$table->integer('payment_type')->nullable(false);
|
||||
$table->integer('bank_id')->nullable(false);
|
||||
$table->integer('info')->nullable(false);
|
||||
$table->integer('program')->nullable(false);
|
||||
$table->integer('cvc')->nullable(false);
|
||||
$table->integer('pin')->nullable(false);
|
||||
$table->string('username')->nullable();
|
||||
$table->integer('card_template_id')->nullable();
|
||||
$table->integer('card_file_id')->nullable();
|
||||
|
||||
$table->integer('status')->default(1);
|
||||
$table->timestamps();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
\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");
|
||||
});
|
||||
}
|
||||
};
|
90
kernel/app_modules/card/models/Card.php
Normal file
90
kernel/app_modules/card/models/Card.php
Normal file
@ -0,0 +1,90 @@
|
||||
<?php
|
||||
|
||||
namespace kernel\app_modules\card\models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use kernel\modules\user\models\User;
|
||||
|
||||
// Добавить @property
|
||||
/**
|
||||
* @property int $id
|
||||
* @property int $status
|
||||
* @property int $balance
|
||||
* @property int $user_id
|
||||
* @property int $payment_type
|
||||
* @property int $bank_id
|
||||
* @property int $info
|
||||
* @property int $card_program_id
|
||||
* @property int $cvc
|
||||
* @property int $pin
|
||||
* @property int $card_template_id
|
||||
* @property int $card_file_id
|
||||
* @property string $username
|
||||
*/
|
||||
class Card extends Model
|
||||
{
|
||||
const DISABLE_STATUS = 0;
|
||||
const ACTIVE_STATUS = 1;
|
||||
|
||||
protected $table = 'card';
|
||||
|
||||
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
|
||||
{
|
||||
// Заполнить массив
|
||||
// Пример: [
|
||||
// 'label' => 'Заголовок',
|
||||
// 'entity' => 'Сущность',
|
||||
// 'slug' => 'Slug',
|
||||
// 'status' => 'Статус',
|
||||
// ]
|
||||
|
||||
return [
|
||||
'user_id' => 'ID пользователя',
|
||||
'payment_type' => 'Платежная система',
|
||||
'balance' => 'Баланс',
|
||||
'bank_id' => 'ID банка',
|
||||
'info' => 'Информация о банке',
|
||||
'card_program_id' => 'Программа',
|
||||
'cvc' => 'CVC',
|
||||
'pin' => 'PIN',
|
||||
'username' => 'Username',
|
||||
'card_template_id' => 'Шаблон',
|
||||
'card_file_id' => 'Карта',
|
||||
'status' => 'Статус',
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string[]
|
||||
*/
|
||||
public static function getStatus(): array
|
||||
{
|
||||
return [
|
||||
self::DISABLE_STATUS => "Не активный",
|
||||
self::ACTIVE_STATUS => "Активный",
|
||||
];
|
||||
}
|
||||
|
||||
public function cardTemplate(): \Illuminate\Database\Eloquent\Relations\BelongsTo
|
||||
{
|
||||
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);
|
||||
}
|
||||
|
||||
// public function user(): \Illuminate\Database\Eloquent\Relations\BelongsTo
|
||||
// {
|
||||
// return $this->belongsTo(User::class);
|
||||
// }
|
||||
|
||||
}
|
51
kernel/app_modules/card/models/CardFile.php
Normal file
51
kernel/app_modules/card/models/CardFile.php
Normal file
@ -0,0 +1,51 @@
|
||||
<?php
|
||||
|
||||
namespace kernel\app_modules\card\models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
/**
|
||||
* @property int $id;
|
||||
* @property string $file;
|
||||
* @property int $card_id;
|
||||
* @property int $status;
|
||||
*/
|
||||
class CardFile extends Model
|
||||
{
|
||||
|
||||
const DISABLE_STATUS = 0;
|
||||
const ACTIVE_STATUS = 1;
|
||||
|
||||
protected $table = 'card_file';
|
||||
|
||||
protected $fillable = ['file', 'card_id', 'status'];
|
||||
|
||||
public static function labels(): array
|
||||
{
|
||||
// Заполнить массив
|
||||
// Пример: [
|
||||
// 'label' => 'Заголовок',
|
||||
// 'entity' => 'Сущность',
|
||||
// 'slug' => 'Slug',
|
||||
// 'status' => 'Статус',
|
||||
// ]
|
||||
|
||||
return [
|
||||
'file' => 'Файл карты',
|
||||
'card_id' => 'Карта',
|
||||
'status' => 'Статус',
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string[]
|
||||
*/
|
||||
public static function getStatus(): array
|
||||
{
|
||||
return [
|
||||
self::DISABLE_STATUS => "Не активный",
|
||||
self::ACTIVE_STATUS => "Активный",
|
||||
];
|
||||
}
|
||||
|
||||
}
|
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 => "Активный",
|
||||
];
|
||||
}
|
||||
|
||||
}
|
52
kernel/app_modules/card/models/CardTemplate.php
Normal file
52
kernel/app_modules/card/models/CardTemplate.php
Normal file
@ -0,0 +1,52 @@
|
||||
<?php
|
||||
|
||||
namespace kernel\app_modules\card\models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
/**
|
||||
* @property string $path
|
||||
* @property string $title
|
||||
* @property string $settings
|
||||
* @property int $status
|
||||
*/
|
||||
class CardTemplate extends Model
|
||||
{
|
||||
|
||||
const DISABLE_STATUS = 0;
|
||||
const ACTIVE_STATUS = 1;
|
||||
|
||||
protected $table = 'card_template';
|
||||
|
||||
protected $fillable = ['path', 'title', 'status', 'settings'];
|
||||
|
||||
public static function labels(): array
|
||||
{
|
||||
// Заполнить массив
|
||||
// Пример: [
|
||||
// 'label' => 'Заголовок',
|
||||
// 'entity' => 'Сущность',
|
||||
// 'slug' => 'Slug',
|
||||
// 'status' => 'Статус',
|
||||
// ]
|
||||
|
||||
return [
|
||||
'path' => 'Шаблон',
|
||||
'title' => 'Название',
|
||||
'settings' => 'Настройки',
|
||||
'status' => 'Статус',
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string[]
|
||||
*/
|
||||
public static function getStatus(): array
|
||||
{
|
||||
return [
|
||||
self::DISABLE_STATUS => "Не активный",
|
||||
self::ACTIVE_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 => "В процессе",
|
||||
];
|
||||
}
|
||||
|
||||
}
|
36
kernel/app_modules/card/models/forms/CreateCardForm.php
Normal file
36
kernel/app_modules/card/models/forms/CreateCardForm.php
Normal file
@ -0,0 +1,36 @@
|
||||
<?php
|
||||
|
||||
namespace kernel\app_modules\card\models\forms;
|
||||
|
||||
use kernel\FormModel;
|
||||
|
||||
class CreateCardForm extends FormModel
|
||||
{
|
||||
|
||||
public function rules(): array
|
||||
{
|
||||
// Заполнить массив правил
|
||||
// Пример:
|
||||
// return [
|
||||
// 'label' => 'required|min-str-len:5|max-str-len:30',
|
||||
// 'entity' => 'required',
|
||||
// 'slug' => '',
|
||||
// 'status' => ''
|
||||
// ];
|
||||
return [
|
||||
'user_id' => 'required|alpha-numeric',
|
||||
'payment_type' => 'required|alpha-numeric',
|
||||
'balance' => 'alpha-numeric',
|
||||
'bank_id' => 'required|alpha-numeric',
|
||||
'info' => '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: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' => ''
|
||||
];
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,40 @@
|
||||
<?php
|
||||
|
||||
namespace kernel\app_modules\card\models\forms;
|
||||
|
||||
use kernel\FormModel;
|
||||
|
||||
class CreateCardTemplateForm extends FormModel
|
||||
{
|
||||
|
||||
public function rules(): array
|
||||
{
|
||||
// Заполнить массив правил
|
||||
// Пример:
|
||||
// return [
|
||||
// 'label' => 'required|min-str-len:5|max-str-len:30',
|
||||
// 'entity' => 'required',
|
||||
// 'slug' => '',
|
||||
// 'status' => ''
|
||||
// ];
|
||||
return [
|
||||
'path' => 'required|min-str-len:4',
|
||||
'title' => 'required',
|
||||
'settings' => 'min-str-len:4',
|
||||
'status' => ''
|
||||
];
|
||||
}
|
||||
|
||||
public function rulesForUpdate(): array
|
||||
{
|
||||
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' => ''
|
||||
];
|
||||
}
|
||||
|
||||
}
|
86
kernel/app_modules/card/routs/card.php
Normal file
86
kernel/app_modules/card/routs/card.php
Normal file
@ -0,0 +1,86 @@
|
||||
<?php
|
||||
|
||||
use kernel\App;
|
||||
use kernel\CgRouteCollector;
|
||||
use Phroute\Phroute\RouteCollector;
|
||||
|
||||
App::$collector->group(["prefix" => "admin"], function (CgRouteCollector $router) {
|
||||
App::$collector->group(["before" => "auth"], function (RouteCollector $router) {
|
||||
App::$collector->group(["prefix" => "card"], function (CGRouteCollector $router) {
|
||||
App::$collector->get('/', [\app\modules\card\controllers\CardController::class, 'actionIndex']);
|
||||
App::$collector->get('/page/{page_number}', [\app\modules\card\controllers\CardController::class, 'actionIndex']);
|
||||
App::$collector->get('/create', [\app\modules\card\controllers\CardController::class, 'actionCreate']);
|
||||
App::$collector->post("/", [\app\modules\card\controllers\CardController::class, 'actionAdd']);
|
||||
App::$collector->get('/{id}', [\app\modules\card\controllers\CardController::class, 'actionView']);
|
||||
App::$collector->any('/update/{id}', [\app\modules\card\controllers\CardController::class, 'actionUpdate']);
|
||||
App::$collector->any("/edit/{id}", [\app\modules\card\controllers\CardController::class, 'actionEdit']);
|
||||
App::$collector->get('/delete/{id}', [\app\modules\card\controllers\CardController::class, 'actionDelete']);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
App::$collector->group(["prefix" => "admin"], function (CgRouteCollector $router) {
|
||||
App::$collector->group(["before" => "auth"], function (RouteCollector $router) {
|
||||
App::$collector->group(["prefix" => "card_template"], function (CGRouteCollector $router) {
|
||||
App::$collector->get('/', [\kernel\app_modules\card\controllers\CardTemplateController::class, 'actionIndex']);
|
||||
App::$collector->get('/page/{page_number}', [\kernel\app_modules\card\controllers\CardTemplateController::class, 'actionIndex']);
|
||||
App::$collector->get('/create', [\kernel\app_modules\card\controllers\CardTemplateController::class, 'actionCreate']);
|
||||
App::$collector->post("/", [\kernel\app_modules\card\controllers\CardTemplateController::class, 'actionAdd']);
|
||||
App::$collector->get('/{id}', [\kernel\app_modules\card\controllers\CardTemplateController::class, 'actionView']);
|
||||
App::$collector->any('/update/{id}', [\kernel\app_modules\card\controllers\CardTemplateController::class, 'actionUpdate']);
|
||||
App::$collector->any("/edit/{id}", [\kernel\app_modules\card\controllers\CardTemplateController::class, 'actionEdit']);
|
||||
App::$collector->get('/delete/{id}', [\kernel\app_modules\card\controllers\CardTemplateController::class, 'actionDelete']);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
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]);
|
||||
});
|
||||
});
|
144
kernel/app_modules/card/services/CardFileService.php
Normal file
144
kernel/app_modules/card/services/CardFileService.php
Normal file
@ -0,0 +1,144 @@
|
||||
<?php
|
||||
|
||||
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\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;
|
||||
use Endroid\QrCode\ErrorCorrectionLevel;
|
||||
use Endroid\QrCode\QrCode;
|
||||
use Endroid\QrCode\RoundBlockSizeMode;
|
||||
use Endroid\QrCode\Writer\PngWriter;
|
||||
|
||||
class CardFileService
|
||||
{
|
||||
|
||||
public function create(Card $card): false|CardFile
|
||||
{
|
||||
$cardFile = self::createCardPNG($card);
|
||||
|
||||
$model = new CardFile();
|
||||
// Пример заполнения:
|
||||
$model->file = $cardFile;
|
||||
$model->status = CardFile::ACTIVE_STATUS;
|
||||
$model->card_id = $card->id;
|
||||
// $model->slug = Slug::createSlug($form_model->getItem('title'), Card::class); // Генерация уникального slug
|
||||
|
||||
if ($model->save()) {
|
||||
return $model;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public function update(FormModel $form_model, CardFile $cardTemplate): false|CardFile
|
||||
{
|
||||
// Пример обновления:
|
||||
$cardTemplate->file = $form_model->getItem('file');
|
||||
$cardTemplate->card_id = $form_model->getItem('card_id');
|
||||
$cardTemplate->status = $form_model->getItem('status');
|
||||
|
||||
if ($cardTemplate->save()) {
|
||||
return $cardTemplate;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
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->card_program_id)->client($card->id);
|
||||
|
||||
$cardNumber = CardNumber::generate($customer, $formatter);
|
||||
//Card
|
||||
$newFileName = md5(time() . $card->id) . '.png';
|
||||
$uploadDir = "/resources/cards/";
|
||||
$uploadDirUri = $uploadDir . mb_substr($newFileName, 0, 2) . '/' . mb_substr($newFileName, 2, 2) . '/';
|
||||
$oldMask = umask(0);
|
||||
if (!file_exists(ROOT_DIR . $uploadDirUri)){
|
||||
mkdir(ROOT_DIR . $uploadDirUri, 0775, true);
|
||||
}
|
||||
umask($oldMask);
|
||||
$uploadFileDir = ROOT_DIR . $uploadDirUri;
|
||||
|
||||
$cardSettings = json_decode($card->cardTemplate->settings ?? "", true);
|
||||
|
||||
$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: 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 false;
|
||||
}
|
||||
|
||||
public static function createQr(string|int $text, int $size = 131): \Endroid\QrCode\Writer\Result\ResultInterface
|
||||
{
|
||||
$writer = new PngWriter();
|
||||
|
||||
$qrCode = new QrCode(
|
||||
data: $text,
|
||||
encoding: new Encoding('UTF-8'),
|
||||
errorCorrectionLevel: ErrorCorrectionLevel::Low,
|
||||
size: $size,
|
||||
margin: 2,
|
||||
roundBlockSizeMode: RoundBlockSizeMode::Margin,
|
||||
foregroundColor: new Color(0, 0, 0),
|
||||
backgroundColor: new Color(255, 255, 255)
|
||||
);
|
||||
|
||||
return $writer->write($qrCode);
|
||||
}
|
||||
|
||||
}
|
@ -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 [];
|
||||
}
|
||||
|
||||
}
|
168
kernel/app_modules/card/services/CardService.php
Normal file
168
kernel/app_modules/card/services/CardService.php
Normal file
@ -0,0 +1,168 @@
|
||||
<?php
|
||||
|
||||
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
|
||||
{
|
||||
$model = new Card();
|
||||
// Пример заполнения:
|
||||
$model->user_id = $form_model->getItem('user_id');
|
||||
$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->card_program_id = $form_model->getItem('card_program_id') ?? 71;
|
||||
$model->balance = $form_model->getItem('balance') ?? 0;
|
||||
$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');
|
||||
|
||||
if ($model->save()) {
|
||||
$cardFile = $this->cardFileService->create($model);
|
||||
if ($cardFile) {
|
||||
$model->card_file_id = $cardFile->id;
|
||||
$model->save();
|
||||
}
|
||||
|
||||
return $model;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public function update(FormModel $form_model, Card $card): false|Card
|
||||
{
|
||||
// Пример обновления:
|
||||
$card->user_id = $form_model->getItem('user_id');
|
||||
$card->payment_type = $form_model->getItem('payment_type');
|
||||
$card->bank_id = $form_model->getItem('bank_id');
|
||||
$card->info = $form_model->getItem('info');
|
||||
$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')
|
||||
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) {
|
||||
$card->card_file_id = $cardFile->id;
|
||||
}
|
||||
}
|
||||
|
||||
if ($card->save()) {
|
||||
return $card;
|
||||
}
|
||||
|
||||
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->card_program_id)->client($card->id);
|
||||
|
||||
$cardNumber = CardNumber::generate($customer, $formatter);
|
||||
//Card
|
||||
$img = ROOT_DIR . "/" . $card->cardTemplate->path; // Ссылка на файл
|
||||
$font = RESOURCES_DIR . "/tmp/arialmt.ttf"; // Ссылка на шрифт
|
||||
|
||||
$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: 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;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
57
kernel/app_modules/card/services/CardTemplateService.php
Normal file
57
kernel/app_modules/card/services/CardTemplateService.php
Normal file
@ -0,0 +1,57 @@
|
||||
<?php
|
||||
|
||||
namespace kernel\app_modules\card\services;
|
||||
|
||||
use kernel\app_modules\card\models\Card;
|
||||
use kernel\app_modules\card\models\CardTemplate;
|
||||
use kernel\FormModel;
|
||||
|
||||
class CardTemplateService
|
||||
{
|
||||
|
||||
public function create(FormModel $form_model): false|CardTemplate
|
||||
{
|
||||
$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
|
||||
|
||||
if ($model->save()) {
|
||||
return $model;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public function update(FormModel $form_model, CardTemplate $cardTemplate): false|CardTemplate
|
||||
{
|
||||
// Пример обновления:
|
||||
$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');
|
||||
|
||||
if ($cardTemplate->save()) {
|
||||
return $cardTemplate;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public static function getTemplatesList(): array
|
||||
{
|
||||
$arr = [];
|
||||
foreach (CardTemplate::all()->toArray() as $cardTemplate){
|
||||
$arr[$cardTemplate['id']] = $cardTemplate['title'];
|
||||
}
|
||||
if (!empty($arr)) {
|
||||
return $arr;
|
||||
}
|
||||
|
||||
return [];
|
||||
}
|
||||
|
||||
}
|
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();
|
71
kernel/app_modules/card/views/card_template/form.php
Normal file
71
kernel/app_modules/card/views/card_template/form.php
Normal file
@ -0,0 +1,71 @@
|
||||
<?php
|
||||
/**
|
||||
* @var \kernel\app_modules\card\models\CardTemplate $model
|
||||
*/
|
||||
|
||||
use kernel\app_modules\card\models\Card;
|
||||
|
||||
$form = new \itguild\forms\ActiveForm();
|
||||
$form->beginForm(isset($model) ? "/admin/card_template/edit/" . $model->id : "/admin/card_template", '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, 'settings', [
|
||||
'class' => "form-control",
|
||||
'placeholder' => 'Настройки',
|
||||
'value' => $model->settings ?? ''
|
||||
])
|
||||
->setLabel("Настройки")
|
||||
->render();
|
||||
|
||||
$form->field(\itguild\forms\inputs\File::class, 'path', [
|
||||
'class' => "form-control",
|
||||
'placeholder' => 'Путь к файлу',
|
||||
'value' => $model->path ?? ''
|
||||
])
|
||||
->setLabel(\kernel\app_modules\card\models\CardTemplate::labels()['path'])
|
||||
->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();
|
81
kernel/app_modules/card/views/card_template/index.php
Normal file
81
kernel/app_modules/card/views/card_template/index.php
Normal file
@ -0,0 +1,81 @@
|
||||
<?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\CardTemplate::class, [
|
||||
'currentPage' => $page_number,
|
||||
'perPage' => 8,
|
||||
'params' => ["class" => "table table-bordered", "border" => "2"],
|
||||
'baseUrl' => "/admin/card_template"
|
||||
]));
|
||||
|
||||
|
||||
//$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_template/create'])->run();
|
||||
});
|
||||
|
||||
$table->columns([
|
||||
'status' => [
|
||||
'value' => function ($data) {
|
||||
return \kernel\app_modules\card\models\CardTemplate::getStatus()[$data];
|
||||
}
|
||||
],
|
||||
'path' => [
|
||||
'value' => function ($data) {
|
||||
return \kernel\helpers\Html::img($data, ['width' => '200px']);
|
||||
}
|
||||
]
|
||||
]);
|
||||
|
||||
$table->addAction(function($row) {
|
||||
return IconBtnViewWidget::create(['url' => '/admin/card_template/' . $row['id']])->run();
|
||||
});
|
||||
$table->addAction(function($row) {
|
||||
return IconBtnEditWidget::create(['url' => '/admin/card_template/update/' . $row['id']])->run();
|
||||
});
|
||||
$table->addAction(function($row) {
|
||||
return IconBtnDeleteWidget::create(['url' => '/admin/card_template/delete/' . $row['id']])->run();
|
||||
});
|
||||
$table->create();
|
||||
$table->render();
|
34
kernel/app_modules/card/views/card_template/view.php
Normal file
34
kernel/app_modules/card/views/card_template/view.php
Normal file
@ -0,0 +1,34 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @var \Illuminate\Database\Eloquent\Collection $card
|
||||
*/
|
||||
|
||||
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, [
|
||||
'params' => ["class" => "table table-bordered", "border" => "2"],
|
||||
'baseUrl' => "/admin/card_template",
|
||||
]));
|
||||
|
||||
$table->rows([
|
||||
'status' => [
|
||||
'value' => function ($data) {
|
||||
return \kernel\app_modules\card\models\CardTemplate::getStatus()[$data];
|
||||
}
|
||||
]
|
||||
]);
|
||||
|
||||
$table->beforePrint(function () use ($card) {
|
||||
$btn = IconBtnListWidget::create(['url' => '/admin/card_template'])->run();
|
||||
$btn .= IconBtnEditWidget::create(['url' => '/admin/card_template/update/' . $card->id])->run();
|
||||
$btn .= IconBtnDeleteWidget::create(['url' => '/admin/card_template/delete/' . $card->id])->run();
|
||||
return $btn;
|
||||
});
|
||||
|
||||
$table->create();
|
||||
$table->render();
|
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();
|
125
kernel/app_modules/card/views/form.php
Normal file
125
kernel/app_modules/card/views/form.php
Normal file
@ -0,0 +1,125 @@
|
||||
<?php
|
||||
/**
|
||||
* @var Card $model
|
||||
*/
|
||||
|
||||
use kernel\app_modules\card\models\Card;
|
||||
|
||||
$form = new \itguild\forms\ActiveForm();
|
||||
$form->beginForm(isset($model) ? "/admin/card/edit/" . $model->id : "/admin/card", 'multipart/form-data');
|
||||
|
||||
// Пример формы:
|
||||
|
||||
$form->field(class: \itguild\forms\inputs\Select::class, name: "user_id", params: [
|
||||
'class' => "form-control",
|
||||
'value' => $model->user_id ?? ''
|
||||
])
|
||||
->setLabel("Пользователи")
|
||||
->setOptions(\kernel\modules\user\service\UserService::createUsernameArr())
|
||||
->render();
|
||||
|
||||
$form->field(\itguild\forms\inputs\TextInput::class, 'username', [
|
||||
'class' => "form-control",
|
||||
'placeholder' => 'Username',
|
||||
'value' => $model->username ?? ''
|
||||
])
|
||||
->setLabel("Username")
|
||||
->render();
|
||||
|
||||
$form->field(\itguild\forms\inputs\TextInput::class, 'balance', [
|
||||
'class' => "form-control",
|
||||
'placeholder' => 'Баланс',
|
||||
'value' => $model->balance ?? ''
|
||||
])
|
||||
->setLabel("Баланс")
|
||||
->render();
|
||||
|
||||
$form->field(\itguild\forms\inputs\TextInput::class, 'payment_type', [
|
||||
'class' => "form-control",
|
||||
'placeholder' => 'Тип оплаты',
|
||||
'value' => $model->payment_type ?? ''
|
||||
])
|
||||
->setLabel("Тип оплаты")
|
||||
->render();
|
||||
|
||||
$form->field(\itguild\forms\inputs\TextInput::class, 'bank_id', [
|
||||
'class' => "form-control",
|
||||
'placeholder' => 'ID банка',
|
||||
'value' => $model->bank_id ?? ''
|
||||
])
|
||||
->setLabel("ID банка")
|
||||
->render();
|
||||
|
||||
$form->field(\itguild\forms\inputs\TextInput::class, 'info', [
|
||||
'class' => "form-control",
|
||||
'placeholder' => 'Информация',
|
||||
'value' => $model->info ?? ''
|
||||
])
|
||||
->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(\itguild\forms\inputs\TextInput::class, 'cvc', [
|
||||
'class' => "form-control",
|
||||
'placeholder' => 'CVC',
|
||||
'value' => $model->cvc ?? ''
|
||||
])
|
||||
->setLabel("CVC")
|
||||
->render();
|
||||
|
||||
$form->field(\itguild\forms\inputs\TextInput::class, 'pin', [
|
||||
'class' => "form-control",
|
||||
'placeholder' => 'PIN',
|
||||
'value' => $model->pin ?? ''
|
||||
])
|
||||
->setLabel("PIN")
|
||||
->render();
|
||||
|
||||
$form->field(class: \itguild\forms\inputs\Select::class, name: "card_template_id", params: [
|
||||
'class' => "form-control",
|
||||
'value' => $model->card_template_id ?? ''
|
||||
])
|
||||
->setLabel("Шаблон")
|
||||
->setOptions(\kernel\app_modules\card\services\CardTemplateService::getTemplatesList())
|
||||
->render();
|
||||
|
||||
$form->field(class: \itguild\forms\inputs\Select::class, name: "status", params: [
|
||||
'class' => "form-control",
|
||||
'value' => $model->status ?? ''
|
||||
])
|
||||
->setLabel("Статус")
|
||||
->setOptions(Card::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();
|
98
kernel/app_modules/card/views/index.php
Normal file
98
kernel/app_modules/card/views/index.php
Normal file
@ -0,0 +1,98 @@
|
||||
<?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\modules\user\models\User;
|
||||
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' => 'Список карт системы'
|
||||
]);
|
||||
|
||||
$get = (new \kernel\Request())->get();
|
||||
|
||||
//Для использования таблицы с моделью, необходимо создать таблицу в базе данных
|
||||
$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",
|
||||
'searchPrefix' => "",
|
||||
'searchParams' => $get,
|
||||
'fillable' => [
|
||||
'user_id',
|
||||
'balance',
|
||||
'username',
|
||||
'card_template_id',
|
||||
'card_file_id',
|
||||
'status',
|
||||
],
|
||||
]));
|
||||
|
||||
$table->columns([
|
||||
'user_id' => [
|
||||
'value' => function ($data) {
|
||||
return User::find($data)->username ?? '';
|
||||
}
|
||||
],
|
||||
'card_template_id' => [
|
||||
'value' => function ($data) {
|
||||
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;
|
||||
return $file ? \kernel\helpers\Html::img($file) : "";
|
||||
}
|
||||
],
|
||||
'status' => [
|
||||
'value' => function ($data) {
|
||||
return Card::getStatus()[$data];
|
||||
},
|
||||
'filter' => [
|
||||
'class' => \kernel\filters\BootstrapSelectFilter::class,
|
||||
'params' => [
|
||||
'options' => Card::getStatus(),
|
||||
'prompt' => 'Не выбрано'
|
||||
],
|
||||
'value' => $get['status'] ?? '',
|
||||
],
|
||||
]
|
||||
]);
|
||||
|
||||
$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) {
|
||||
return IconBtnViewWidget::create(['url' => '/admin/card/' . $row['id']])->run();
|
||||
});
|
||||
$table->addAction(function($row) {
|
||||
return IconBtnEditWidget::create(['url' => '/admin/card/update/' . $row['id']])->run();
|
||||
});
|
||||
$table->addAction(function($row) {
|
||||
return IconBtnDeleteWidget::create(['url' => '/admin/card/delete/' . $row['id']])->run();
|
||||
});
|
||||
$table->create();
|
||||
$table->render();
|
73
kernel/app_modules/card/views/view.php
Normal file
73
kernel/app_modules/card/views/view.php
Normal file
@ -0,0 +1,73 @@
|
||||
<?php
|
||||
/**
|
||||
* @var \Illuminate\Database\Eloquent\Collection $card
|
||||
*/
|
||||
|
||||
use Endroid\QrCode\Color\Color;
|
||||
use Endroid\QrCode\Encoding\Encoding;
|
||||
use Endroid\QrCode\ErrorCorrectionLevel;
|
||||
use Endroid\QrCode\QrCode;
|
||||
use Endroid\QrCode\RoundBlockSizeMode;
|
||||
use Endroid\QrCode\Writer\PngWriter;
|
||||
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, [
|
||||
'params' => ["class" => "table table-bordered", "border" => "2"],
|
||||
'baseUrl' => "/admin/card",
|
||||
]));
|
||||
$table->beforePrint(function () use ($card) {
|
||||
$btn = IconBtnListWidget::create(['url' => '/admin/card'])->run();
|
||||
$btn .= IconBtnEditWidget::create(['url' => '/admin/card/update/' . $card->id])->run();
|
||||
$btn .= IconBtnDeleteWidget::create(['url' => '/admin/card/delete/' . $card->id])->run();
|
||||
return $btn;
|
||||
});
|
||||
|
||||
$table->rows([
|
||||
'card_file_id' => function ($data) {
|
||||
$file = \kernel\app_modules\card\models\CardFile::find($data)->file;
|
||||
return $file ? \kernel\helpers\Html::img($file) : "";
|
||||
},
|
||||
'status' => function ($data) {
|
||||
return \kernel\app_modules\card\models\Card::getStatus()[$data];
|
||||
}
|
||||
]);
|
||||
|
||||
$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
|
||||
//$qrCode = new QrCode(
|
||||
// data: $card->id,
|
||||
// encoding: new Encoding('UTF-8'),
|
||||
// errorCorrectionLevel: ErrorCorrectionLevel::Low,
|
||||
// size: 120,
|
||||
// margin: 2,
|
||||
// roundBlockSizeMode: RoundBlockSizeMode::Margin,
|
||||
// foregroundColor: new Color(0, 0, 0),
|
||||
// backgroundColor: new Color(255, 255, 255)
|
||||
//);
|
||||
//
|
||||
//
|
||||
//$result = $writer->write($qrCode);
|
||||
//echo "<img src='".$result->getDataUri()."'>";
|
||||
//
|
||||
//$path = $card->cardFile->file;
|
||||
//$mainImg = new \kernel\helpers\ImageGD(ROOT_DIR . $path);
|
||||
//$qrImg = new \kernel\helpers\ImageGD($result->getDataUri());
|
||||
//$mainImg->addImg($qrImg->getImg(), 200, 15, 0, 0, 124, 124, 100);
|
||||
//$mainImg->save(RESOURCES_DIR . "/tmp/with_qr.png");
|
||||
|
||||
//$cardFile = \kernel\app_modules\card\services\CardService::createCardPNG($card);
|
||||
//echo \kernel\helpers\Html::img("/resources/tmp/card_tpl.png");
|
||||
//if ($cardFile) {
|
||||
// echo \kernel\helpers\Html::img($cardFile);
|
||||
//}
|
||||
|
@ -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 [];
|
||||
}
|
||||
|
||||
}
|
55
kernel/app_modules/tgbot/TgbotModule.php
Normal file
55
kernel/app_modules/tgbot/TgbotModule.php
Normal file
@ -0,0 +1,55 @@
|
||||
<?php
|
||||
|
||||
namespace kernel\app_modules\tgbot;
|
||||
|
||||
use kernel\Module;
|
||||
use kernel\modules\menu\service\MenuService;
|
||||
use kernel\services\MigrationService;
|
||||
|
||||
class TgbotModule extends Module
|
||||
{
|
||||
public MenuService $menuService;
|
||||
public MigrationService $migrationService;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->menuService = new MenuService();
|
||||
$this->migrationService = new MigrationService();
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function init(): void
|
||||
{
|
||||
$this->migrationService->runAtPath("{KERNEL_APP_MODULES}/tgbot/migrations");
|
||||
|
||||
$this->menuService->createItem([
|
||||
"label" => "TG bot",
|
||||
"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");
|
||||
}
|
||||
}
|
117
kernel/app_modules/tgbot/controllers/TgBotRestController.php
Normal file
117
kernel/app_modules/tgbot/controllers/TgBotRestController.php
Normal file
@ -0,0 +1,117 @@
|
||||
<?php
|
||||
|
||||
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;
|
||||
use kernel\modules\user\models\forms\CreateUserForm;
|
||||
use kernel\modules\user\service\UserService;
|
||||
use kernel\Request;
|
||||
use kernel\RestController;
|
||||
use kernel\services\TokenService;
|
||||
|
||||
class TgBotRestController extends RestController
|
||||
{
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->model = new Tgbot();
|
||||
}
|
||||
|
||||
#[NoReturn] public function actionStore(): void
|
||||
{
|
||||
$request = new Request();
|
||||
$data = $request->post();
|
||||
|
||||
$tgBot = $this->model->where("bot_id", $data['bot_id'])->where("dialog_id", $data['dialog_id'])->first();
|
||||
|
||||
if (!$tgBot) {
|
||||
foreach ($this->model->getFillable() as $item) {
|
||||
$this->model->{$item} = $data[$item] ?? null;
|
||||
}
|
||||
|
||||
$userService = new UserService();
|
||||
$userForm = new CreateUserForm();
|
||||
$username = $data['username'];
|
||||
$userForm->load([
|
||||
'username' => $username,
|
||||
'password' => TokenService::random_bytes(20),
|
||||
'email' => $username . "@hookahdnr.ru"
|
||||
]);
|
||||
|
||||
$user = $userService->create($userForm);
|
||||
if ($user) {
|
||||
$this->model->user_id = $user->id;
|
||||
}
|
||||
|
||||
$this->model->save();
|
||||
|
||||
$resArr = $this->model->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
|
||||
{
|
||||
$cardService = new CardService();
|
||||
$request = new Request();
|
||||
$data = $request->post();
|
||||
$form = new CreateCardForm();
|
||||
$form->load($data);
|
||||
$form->setItem('payment_type', 2);
|
||||
$form->setItem('bank_id', 323);
|
||||
$form->setItem('info', 42);
|
||||
$form->setItem('program', 71);
|
||||
$form->setItem('cvc', 101);
|
||||
$form->setItem('pin', 1111);
|
||||
$form->setItem('status', 1);
|
||||
|
||||
if ($form->validate()) {
|
||||
$model = $cardService->create($form);
|
||||
|
||||
$this->renderApi($model->load(['cardFile'])->toArray());
|
||||
}
|
||||
|
||||
$this->renderApi([]);
|
||||
}
|
||||
|
||||
#[NoReturn] public function actionGetByDialog(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) {
|
||||
$this->renderApi($model->toArray());
|
||||
}
|
||||
$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([]);
|
||||
}
|
||||
|
||||
}
|
111
kernel/app_modules/tgbot/controllers/TgbotController.php
Normal file
111
kernel/app_modules/tgbot/controllers/TgbotController.php
Normal file
@ -0,0 +1,111 @@
|
||||
<?php
|
||||
|
||||
namespace kernel\app_modules\tgbot\controllers;
|
||||
|
||||
use app\modules\tgbot\models\forms\CreateTgBotForm;
|
||||
use app\modules\tgbot\models\Tgbot;
|
||||
use app\modules\tgbot\services\TgBotService;
|
||||
use Exception;
|
||||
use JetBrains\PhpStorm\NoReturn;
|
||||
use kernel\AdminController;
|
||||
use kernel\helpers\Debug;
|
||||
use kernel\modules\user\models\forms\CreateUserForm;
|
||||
use kernel\modules\user\service\UserService;
|
||||
use kernel\services\TokenService;
|
||||
|
||||
class TgbotController extends AdminController
|
||||
{
|
||||
protected TgBotService $botService;
|
||||
|
||||
protected function init(): void
|
||||
{
|
||||
parent::init();
|
||||
$this->cgView->viewPath = KERNEL_APP_MODULES_DIR . "/tgbot/views/tgbot/";
|
||||
$this->botService = new TgBotService();
|
||||
}
|
||||
|
||||
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 CreateTgBotForm();
|
||||
$tgForm->load($_REQUEST);
|
||||
if ($tgForm->validate()) {
|
||||
$tg = $this->botService->create($tgForm);
|
||||
if ($tg) {
|
||||
$this->redirect("/admin/tg-bot/view/" . $tg->id);
|
||||
}
|
||||
}
|
||||
$this->redirect("/admin/tg-bot/create");
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws Exception
|
||||
*/
|
||||
public function actionUpdate($id): void
|
||||
{
|
||||
$model = Tgbot::find($id);
|
||||
if (!$model) {
|
||||
throw new Exception(message: "The dialog not found");
|
||||
}
|
||||
|
||||
$this->cgView->render("form.php", ['model' => $model]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws Exception
|
||||
*/
|
||||
public function actionEdit($id): void
|
||||
{
|
||||
$tg = Tgbot::find($id);
|
||||
if (!$tg) {
|
||||
throw new Exception(message: "The tag not found");
|
||||
}
|
||||
$tgForm = new CreateTgBotForm();
|
||||
$tgService = new TgBotService();
|
||||
$tgForm->load($_REQUEST);
|
||||
if ($tgForm->validate()) {
|
||||
$tg = $tgService->update($tgForm, $tg);
|
||||
if ($tg) {
|
||||
$this->redirect("/admin/tg-bot/view/" . $tg->id);
|
||||
}
|
||||
}
|
||||
$this->redirect("/admin/tg-bot/update/" . $id);
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws Exception
|
||||
*/
|
||||
public function actionView($id): void
|
||||
{
|
||||
$tg = Tgbot::find($id);
|
||||
|
||||
if (!$tg) {
|
||||
throw new Exception(message: "The dialog not found");
|
||||
}
|
||||
$this->cgView->render("view.php", ['tg' => $tg]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws Exception
|
||||
*/
|
||||
#[NoReturn] public function actionDelete(int $id): void
|
||||
{
|
||||
$post = Tgbot::find($id)->first();
|
||||
if (!$post){
|
||||
throw new Exception(message: "The tg client not found");
|
||||
}
|
||||
|
||||
$post->delete();
|
||||
$this->redirect("/admin/tg-bot/");
|
||||
}
|
||||
|
||||
}
|
@ -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,35 @@
|
||||
<?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', function (Blueprint $table) {
|
||||
$table->increments('id');
|
||||
$table->bigInteger('bot_id')->nullable(false);
|
||||
$table->bigInteger('dialog_id')->nullable(false);
|
||||
$table->integer('user_id')->nullable();
|
||||
$table->string('username', 255)->nullable(false);
|
||||
$table->string('first_name', 255)->nullable();
|
||||
$table->string('last_name', 255)->nullable();
|
||||
$table->integer('status')->nullable()->default(1);
|
||||
$table->timestamps();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
\kernel\App::$db->schema->dropIfExists('tgbot');
|
||||
}
|
||||
};
|
@ -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');
|
||||
}
|
||||
};
|
53
kernel/app_modules/tgbot/models/Tgbot.php
Normal file
53
kernel/app_modules/tgbot/models/Tgbot.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 integer $user_id
|
||||
* @property string $username
|
||||
* @property string $first_name
|
||||
* @property string $last_name
|
||||
* @property integer $status
|
||||
*/
|
||||
class Tgbot extends Model
|
||||
{
|
||||
const DISABLE_STATUS = 0;
|
||||
const ACTIVE_STATUS = 1;
|
||||
const ADMIN_STATUS = 9;
|
||||
|
||||
protected $table = 'tgbot';
|
||||
|
||||
protected $fillable = ['bot_id', 'dialog_id', 'user_id', 'username', 'first_name', 'last_name', 'status'];
|
||||
|
||||
public static function labels(): array
|
||||
{
|
||||
return [
|
||||
'bot_id' => 'Bot ID',
|
||||
'dialog_id' => 'Dialog ID',
|
||||
'user_id' => 'User ID',
|
||||
'username' => 'Username',
|
||||
'first_name' => 'First name',
|
||||
'last_name' => 'Last name',
|
||||
'status' => 'Статус',
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string[]
|
||||
*/
|
||||
public static function getStatus(): array
|
||||
{
|
||||
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 => "Отправлено",
|
||||
];
|
||||
}
|
||||
|
||||
}
|
31
kernel/app_modules/tgbot/models/forms/CreateTgBotForm.php
Normal file
31
kernel/app_modules/tgbot/models/forms/CreateTgBotForm.php
Normal file
@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
namespace kernel\app_modules\tgbot\models\forms;
|
||||
|
||||
use kernel\FormModel;
|
||||
|
||||
/**
|
||||
* @property integer $bot_id
|
||||
* @property integer $dialog_id
|
||||
* @property string $username
|
||||
* @property string $first_name
|
||||
* @property string $last_name
|
||||
* @property integer $status
|
||||
*/
|
||||
class CreateTgBotForm extends FormModel
|
||||
{
|
||||
|
||||
public function rules(): array
|
||||
{
|
||||
return [
|
||||
'user_id' => 'required',
|
||||
'bot_id' => 'required',
|
||||
'dialog_id' => 'required',
|
||||
'username' => 'required',
|
||||
'first_name' => '',
|
||||
'last_name' => '',
|
||||
'status' => ''
|
||||
];
|
||||
}
|
||||
|
||||
}
|
@ -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'
|
||||
];
|
||||
}
|
||||
|
||||
}
|
44
kernel/app_modules/tgbot/routs/tgbot.php
Normal file
44
kernel/app_modules/tgbot/routs/tgbot.php
Normal file
@ -0,0 +1,44 @@
|
||||
<?php
|
||||
|
||||
|
||||
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('/', [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" => "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']);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
App::$collector->group(["prefix" => "api"], function (CgRouteCollector $router){
|
||||
App::$collector->group(['before' => 'bearer'], function (CgRouteCollector $router){
|
||||
$router->rest("tg-bot", [\app\modules\tgbot\controllers\TgBotRestController::class]);
|
||||
$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']);
|
||||
});
|
61
kernel/app_modules/tgbot/services/TgBotService.php
Normal file
61
kernel/app_modules/tgbot/services/TgBotService.php
Normal file
@ -0,0 +1,61 @@
|
||||
<?php
|
||||
|
||||
namespace kernel\app_modules\tgbot\services;
|
||||
|
||||
use app\modules\tgbot\models\Tgbot;
|
||||
use kernel\app_modules\tag\models\Tag;
|
||||
use kernel\FormModel;
|
||||
use kernel\helpers\Debug;
|
||||
use kernel\helpers\Slug;
|
||||
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');
|
||||
$model->username = $form_model->getItem('username');
|
||||
$model->first_name = $form_model->getItem('first_name');
|
||||
$model->last_name = $form_model->getItem('last_name');
|
||||
$model->status = $form_model->getItem('status');
|
||||
if ($model->save()){
|
||||
return $model;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
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');
|
||||
$model->username = $form_model->getItem('username');
|
||||
$model->first_name = $form_model->getItem('first_name');
|
||||
$model->last_name = $form_model->getItem('last_name');
|
||||
$model->status = $form_model->getItem('status');
|
||||
|
||||
if ($model->save()){
|
||||
return $model;
|
||||
}
|
||||
|
||||
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();
|
91
kernel/app_modules/tgbot/views/tgbot/form.php
Normal file
91
kernel/app_modules/tgbot/views/tgbot/form.php
Normal file
@ -0,0 +1,91 @@
|
||||
<?php
|
||||
/**
|
||||
* @var Tgbot $model
|
||||
*/
|
||||
|
||||
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',
|
||||
'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: "username", params: [
|
||||
'class' => "form-control",
|
||||
'placeholder' => 'Username',
|
||||
'value' => $model->username ?? ''
|
||||
])
|
||||
->setLabel("Username")
|
||||
->render();
|
||||
|
||||
$form->field(class: \itguild\forms\inputs\TextInput::class, name: "first_name", params: [
|
||||
'class' => "form-control",
|
||||
'placeholder' => 'First name',
|
||||
'value' => $model->first_name ?? ''
|
||||
])
|
||||
->setLabel("First name")
|
||||
->render();
|
||||
|
||||
$form->field(class: \itguild\forms\inputs\TextInput::class, name: "last_name", params: [
|
||||
'class' => "form-control",
|
||||
'placeholder' => 'Last name',
|
||||
'value' => $model->last_name ?? ''
|
||||
])
|
||||
->setLabel("Last name")
|
||||
->render();
|
||||
|
||||
|
||||
$form->field(\itguild\forms\inputs\Select::class, 'status', [
|
||||
'class' => "form-control",
|
||||
'value' => $model->status ?? ''
|
||||
])
|
||||
->setLabel("Статус")
|
||||
->setOptions(Tgbot::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();
|
59
kernel/app_modules/tgbot/views/tgbot/index.php
Normal file
59
kernel/app_modules/tgbot/views/tgbot/index.php
Normal file
@ -0,0 +1,59 @@
|
||||
<?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;
|
||||
|
||||
$view->setTitle("Список существующих диалогов");
|
||||
|
||||
$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"],
|
||||
'baseUrl' => "/admin/tg-bot",
|
||||
'searchPrefix' => "",
|
||||
'searchParams' => (new \kernel\Request())->get(),
|
||||
]));
|
||||
|
||||
$table->beforePrint(function () {
|
||||
return PrimaryBtn::create("Создать", "/admin/tg-bot/create")->fetch();
|
||||
});
|
||||
|
||||
$table->columns([
|
||||
"status" => [
|
||||
"value" => function ($cell) {
|
||||
return \app\modules\tgbot\models\Tgbot::getStatus()[$cell] ?? 0;
|
||||
}
|
||||
],
|
||||
"username" => [
|
||||
"filter" => [
|
||||
"class" => \Itguild\Tables\Filter\InputTextFilter::class
|
||||
]
|
||||
],
|
||||
"bot_id" => [
|
||||
"filter" => [
|
||||
"class" => \Itguild\Tables\Filter\InputTextFilter::class
|
||||
]
|
||||
],
|
||||
"dialog_id" => [
|
||||
"filter" => [
|
||||
"class" => \Itguild\Tables\Filter\InputTextFilter::class
|
||||
]
|
||||
]
|
||||
]);
|
||||
|
||||
|
||||
$table->addAction(\kernel\IGTabel\action_column\ViewActionColumn::class);
|
||||
$table->addAction(\kernel\IGTabel\action_column\DeleteActionColumn::class);
|
||||
$table->addAction(\kernel\IGTabel\action_column\EditActionColumn::class);
|
||||
$table->create();
|
||||
$table->render();
|
30
kernel/app_modules/tgbot/views/tgbot/view.php
Normal file
30
kernel/app_modules/tgbot/views/tgbot/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",
|
||||
]));
|
||||
$table->beforePrint(function () use ($tg) {
|
||||
$btn = PrimaryBtn::create("Список", "/admin/tg-bot")->fetch();
|
||||
$btn .= SuccessBtn::create("Редактировать", "/admin/tg-bot/update/" . $tg->id)->fetch();
|
||||
$btn .= DangerBtn::create("Удалить", "/admin/tg-bot/delete/" . $tg->id)->fetch();
|
||||
return $btn;
|
||||
});
|
||||
$table->rows([
|
||||
'status' => (function ($data) {
|
||||
return \app\modules\tgbot\models\Tgbot::getStatus()[$data];
|
||||
})
|
||||
]);
|
||||
$table->create();
|
||||
$table->render();
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user