This commit is contained in:
Kavalar 2025-01-19 17:15:58 +03:00
parent 40369fb515
commit b18378bcb1
41 changed files with 1257 additions and 30 deletions

View File

@ -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 "";
}
}

View File

@ -2,7 +2,9 @@
namespace app\modules\tgbot\controllers;
use kernel\app_modules\tag\service\TagService;
use kernel\Controller;
use kernel\modules\post\models\Post;
class TgMainController extends Controller
{
@ -21,4 +23,18 @@ class TgMainController extends Controller
$this->cgView->render("index.php");
}
public function actionNews(): void
{
$news = TagService::getEntityByTagId(2, Post::class);
$this->cgView->render("news.php", ['news' => $news]);
}
public function actionPromo(): void
{
$news = TagService::getEntityByTagId(1, Post::class);
$this->cgView->render("news.php", ['news' => $news]);
}
}

View File

@ -8,4 +8,6 @@ include KERNEL_APP_MODULES_DIR . "/tgbot/routs/tgbot.php";
App::$collector->group(["prefix" => "miniapp"], function (CGRouteCollector $router) {
App::$collector->get('/', [\app\modules\tgbot\controllers\TgMainController::class, 'actionMain']);
App::$collector->get('/news', [\app\modules\tgbot\controllers\TgMainController::class, 'actionNews']);
App::$collector->get('/promo', [\app\modules\tgbot\controllers\TgMainController::class, 'actionPromo']);
});

View File

@ -41,10 +41,10 @@
<div class="collapse navbar-collapse" id="navbarSupportedContent">
<ul class="nav navbar-nav ml-auto">
<li class="nav-item active">
<a class="nav-link" href="/miniapp/card">Карта</a>
<a class="nav-link" href="/miniapp/news">Новости</a>
</li>
<li class="nav-item">
<a class="nav-link" href="/miniapp/sale">Акции</a>
<a class="nav-link" href="/miniapp/promo">Акции</a>
</li>
</ul>
</div>

View 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; ?>

View File

@ -1,7 +1,7 @@
<?php
$secure_config = [
'web_auth_type' => 'login_password', // login_password, email_code
'web_auth_type' => 'email_code', // login_password, email_code
'token_type' => 'hash', // random_bytes, md5, crypt, hash, JWT
'token_expired_time' => "+30 days", // +1 day
];

View File

@ -50,6 +50,20 @@ class CardModule extends Module
"slug" => "card_template",
"parent_slug" => "card"
]);
$this->menuService->createItem([
"label" => "Программы",
"url" => "/admin/card_program",
"slug" => "card_program",
"parent_slug" => "card"
]);
$this->menuService->createItem([
"label" => "Условия",
"url" => "/admin/card_program_conditions",
"slug" => "card_program_conditions",
"parent_slug" => "card"
]);
}
/**
@ -60,6 +74,8 @@ class CardModule extends Module
$this->menuService->removeItemBySlug("card");
$this->menuService->removeItemBySlug("card_list");
$this->menuService->removeItemBySlug("card_template");
$this->menuService->removeItemBySlug("card_program");
$this->menuService->removeItemBySlug("card_program_conditions");
$this->migrationService->rollbackAtPath("{KERNEL_APP_MODULES}/card/migrations");
$this->consoleService->runComposerRemove("dragon-code/card-number");
$this->consoleService->runComposerRemove("endroid/qr-code");

View File

@ -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/");
}
}

View 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/");
}
}

View File

@ -16,6 +16,7 @@ return new class extends Migration
$table->increments('id')->from(105545);
$table->string('path')->nullable(false);
$table->string('title')->nullable(false);
$table->text('settings')->nullable();
$table->integer('status')->default(1);
$table->timestamps();
@ -30,6 +31,35 @@ return new class extends Migration
$table->timestamps();
});
\kernel\App::$db->schema->create('card_program', function (Blueprint $table) {
$table->increments('id')->from(71);
$table->string('slug')->nullable(false)->unique();
$table->string('title')->nullable(false);
$table->integer('status')->default(1);
$table->timestamps();
});
\kernel\App::$db->schema->create('card_program_conditions', function (Blueprint $table) {
$table->increments('id');
$table->integer("card_program_id")->nullable(false);
$table->string('slug')->nullable(false)->unique();
$table->string('title')->nullable(false);
$table->string('type')->nullable(false);
$table->string('value');
$table->integer('status')->default(1);
$table->timestamps();
});
\kernel\App::$db->schema->create('card_card_program', function (Blueprint $table) {
$table->increments('id');
$table->string('card_program_id')->nullable(false);
$table->string('card_id')->nullable(false);
$table->timestamps();
});
\kernel\App::$db->schema->create('card', function (Blueprint $table) {
$table->increments('id')->from(105545);
$table->integer('user_id')->nullable(false);
@ -56,6 +86,9 @@ return new class extends Migration
{
\kernel\App::$db->schema->dropIfExists('card');
\kernel\App::$db->schema->dropIfExists('card_template');
\kernel\App::$db->schema->dropIfExists('card_card_program');
\kernel\App::$db->schema->dropIfExists('card_program_conditions');
\kernel\App::$db->schema->dropIfExists('card_program');
\kernel\App::$db->schema->dropIfExists('card_file');
}
};

View File

@ -0,0 +1,51 @@
<?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' => 'Статус',
];
}
/**
* @return string[]
*/
public static function getStatus(): array
{
return [
self::DISABLE_STATUS => "Не активный",
self::ACTIVE_STATUS => "Активный",
];
}
}

View 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 => "Активный",
];
}
}

View File

@ -7,6 +7,7 @@ use Illuminate\Database\Eloquent\Model;
/**
* @property string $path
* @property string $title
* @property string $settings
* @property int $status
*/
class CardTemplate extends Model
@ -17,7 +18,7 @@ class CardTemplate extends Model
protected $table = 'card_template';
protected $fillable = ['path', 'title', 'status'];
protected $fillable = ['path', 'title', 'status', 'settings'];
public static function labels(): array
{
@ -32,6 +33,7 @@ class CardTemplate extends Model
return [
'path' => 'Шаблон',
'title' => 'Название',
'settings' => 'Настройки',
'status' => 'Статус',
];
}

View File

@ -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' => ''
];
}
}

View File

@ -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' => ''
];
}
}

View File

@ -20,6 +20,7 @@ class CreateCardTemplateForm extends FormModel
return [
'path' => 'required|min-str-len:4',
'title' => 'required',
'settings' => 'min-str-len:4',
'status' => ''
];
}
@ -29,6 +30,7 @@ class CreateCardTemplateForm extends FormModel
return [
'path' => '',
'title' => 'required',
'settings' => 'min-str-len:4',
'status' => ''
];
}

View File

@ -34,6 +34,36 @@ App::$collector->group(["prefix" => "admin"], function (CgRouteCollector $router
});
});
App::$collector->group(["prefix" => "admin"], function (CgRouteCollector $router) {
App::$collector->group(["before" => "auth"], function (RouteCollector $router) {
App::$collector->group(["prefix" => "card_program"], function (CGRouteCollector $router) {
App::$collector->get('/', [\kernel\app_modules\card\controllers\CardProgramController::class, 'actionIndex']);
App::$collector->get('/page/{page_number}', [\kernel\app_modules\card\controllers\CardProgramController::class, 'actionIndex']);
App::$collector->get('/create', [\kernel\app_modules\card\controllers\CardProgramController::class, 'actionCreate']);
App::$collector->post("/", [\kernel\app_modules\card\controllers\CardProgramController::class, 'actionAdd']);
App::$collector->get('/{id}', [\kernel\app_modules\card\controllers\CardProgramController::class, 'actionView']);
App::$collector->any('/update/{id}', [\kernel\app_modules\card\controllers\CardProgramController::class, 'actionUpdate']);
App::$collector->any("/edit/{id}", [\kernel\app_modules\card\controllers\CardProgramController::class, 'actionEdit']);
App::$collector->get('/delete/{id}', [\kernel\app_modules\card\controllers\CardProgramController::class, 'actionDelete']);
});
});
});
App::$collector->group(["prefix" => "admin"], function (CgRouteCollector $router) {
App::$collector->group(["before" => "auth"], function (RouteCollector $router) {
App::$collector->group(["prefix" => "card_program_conditions"], function (CGRouteCollector $router) {
App::$collector->get('/', [\kernel\app_modules\card\controllers\CardProgramConditionsController::class, 'actionIndex']);
App::$collector->get('/page/{page_number}', [\kernel\app_modules\card\controllers\CardProgramConditionsController::class, 'actionIndex']);
App::$collector->get('/create', [\kernel\app_modules\card\controllers\CardProgramConditionsController::class, 'actionCreate']);
App::$collector->post("/", [\kernel\app_modules\card\controllers\CardProgramConditionsController::class, 'actionAdd']);
App::$collector->get('/{id}', [\kernel\app_modules\card\controllers\CardProgramConditionsController::class, 'actionView']);
App::$collector->any('/update/{id}', [\kernel\app_modules\card\controllers\CardProgramConditionsController::class, 'actionUpdate']);
App::$collector->any("/edit/{id}", [\kernel\app_modules\card\controllers\CardProgramConditionsController::class, 'actionEdit']);
App::$collector->get('/delete/{id}', [\kernel\app_modules\card\controllers\CardProgramConditionsController::class, 'actionDelete']);
});
});
});
App::$collector->group(["prefix" => "api"], function (CgRouteCollector $router){
App::$collector->group(['before' => 'bearer'], function (CgRouteCollector $router){
$router->rest("card", [\kernel\app_modules\card\controllers\CardRestController::class]);

View File

@ -8,6 +8,7 @@ use DragonCode\CardNumber\Formatters\BankFormatter;
use kernel\app_modules\card\models\Card;
use kernel\app_modules\card\models\CardFile;
use kernel\FormModel;
use kernel\helpers\Debug;
use kernel\helpers\ImageGD;
use Endroid\QrCode\Color\Color;
use Endroid\QrCode\Encoding\Encoding;
@ -68,22 +69,45 @@ class CardFileService
umask($oldMask);
$uploadFileDir = ROOT_DIR . $uploadDirUri;
$img = ROOT_DIR . "/" . $card->cardTemplate->path; // Ссылка на файл
$font = RESOURCES_DIR . "/arialmt.ttf"; // Ссылка на шрифт
$cardSettings = json_decode($card->cardTemplate->settings ?? "", true);
$qr = self::createQr($card->id);
$img = ROOT_DIR . "/" . $card->cardTemplate->path; // Ссылка на файл
$font = RESOURCES_DIR . "/Montserrat-SemiBold.ttf"; // Ссылка на шрифт
$qr = self::createQr($card->id, $cardSettings['qr_size'] ?? 131);
$qrImg = new ImageGD($qr->getDataUri());
$img = new ImageGD($img);
$pngFilePath = RESOURCES_DIR . "/tmp/" . $card->id . ".png";
$pngFileUrl = "/resources/tmp/" . $card->id . ".png";
$img->addText(font_size: 14, degree: 0, x: 15, y: 25, color: "#000000", font: $font, text: "KO coin");
$img->addText(font_size: 14, degree: 0, x: 15, y: 45, color: "#000000", font: $font, text: "BGroup\ITGuild");
$img->addText(font_size: 14, degree: 0, x: 15, y: 65, color: "#000000", font: $font, text: $card->cardTemplate->title . " card");
$img->addText(font_size: 18, degree: 0, x: 15, y: 180, color: "#000000", font: $font, text: $cardNumber);
$img->addText(font_size: 12, degree: 0, x: 15, y: 200, color: "#000000", font: $font, text: $card->username);
$img->addImg($qrImg->getImg(), 200, 15, 0, 0, 124, 124, 100);
$img->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
);
$img->save($uploadFileDir . $newFileName);
return $uploadDirUri . $newFileName;
@ -92,7 +116,7 @@ class CardFileService
return false;
}
public static function createQr(string|int $text): \Endroid\QrCode\Writer\Result\ResultInterface
public static function createQr(string|int $text, int $size = 131): \Endroid\QrCode\Writer\Result\ResultInterface
{
$writer = new PngWriter();
@ -100,7 +124,7 @@ class CardFileService
data: $text,
encoding: new Encoding('UTF-8'),
errorCorrectionLevel: ErrorCorrectionLevel::Low,
size: 120,
size: $size,
margin: 2,
roundBlockSizeMode: RoundBlockSizeMode::Margin,
foregroundColor: new Color(0, 0, 0),

View File

@ -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;
}
}

View 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 [];
}
}

View File

@ -97,8 +97,8 @@ class CardService
$img->addText(font_size: 14, degree: 0, x: 15, y: 25, color: "#000000", font: $font, text: "KO coin");
$img->addText(font_size: 14, degree: 0, x: 15, y: 45, color: "#000000", font: $font, text: "BGroup\ITGuild");
$img->addText(font_size: 18, degree: 0, x: 15, y: 180, color: "#000000", font: $font, text: $cardNumber);
$img->addText(font_size: 12, degree: 0, x: 15, y: 200, color: "#000000", font: $font, text: $card->username);
$img->addText(font_size: 18, degree: 0, x: 15, y: 180, color: "#ffffff", font: $font, text: $cardNumber);
$img->addText(font_size: 12, degree: 0, x: 15, y: 200, color: "#ffffff", font: $font, text: $card->username);
$img->save($pngFilePath);
return $pngFileUrl;

View File

@ -14,6 +14,7 @@ class CardTemplateService
$model = new CardTemplate();
// Пример заполнения:
$model->path = $form_model->getItem('path');
$model->settings = $form_model->getItem('settings');
$model->status = $form_model->getItem('status');
$model->title = $form_model->getItem('title');
// $model->slug = Slug::createSlug($form_model->getItem('title'), Card::class); // Генерация уникального slug
@ -29,6 +30,7 @@ class CardTemplateService
{
// Пример обновления:
$cardTemplate->title = $form_model->getItem('title');
$cardTemplate->settings = $form_model->getItem('settings');
$cardTemplate->path = $form_model->getItem('path') ?? $cardTemplate->path;
$cardTemplate->status = $form_model->getItem('status');

View 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();

View 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();

View 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();

View File

@ -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();

View 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("Список условий");
$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();

View File

@ -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();

View File

@ -19,6 +19,14 @@ $form->field(\itguild\forms\inputs\TextInput::class, 'title', [
->setLabel("Заголовок")
->render();
$form->field(\itguild\forms\inputs\TextInput::class, 'settings', [
'class' => "form-control",
'placeholder' => 'Настройки',
'value' => $model->settings ?? ''
])
->setLabel("Настройки")
->render();
$form->field(\itguild\forms\inputs\File::class, 'path', [
'class' => "form-control",
'placeholder' => 'Путь к файлу',

View File

@ -58,12 +58,12 @@ $form->field(\itguild\forms\inputs\TextInput::class, 'info', [
->setLabel("Информация")
->render();
$form->field(\itguild\forms\inputs\TextInput::class, 'program', [
$form->field(class: \itguild\forms\inputs\Select::class, name: "program", params: [
'class' => "form-control",
'placeholder' => 'Программа',
'value' => $model->program ?? ''
])
->setLabel("Программа")
->setOptions(\kernel\app_modules\card\services\CardProgramService::getProgramList())
->render();
$form->field(\itguild\forms\inputs\TextInput::class, 'cvc', [

View File

@ -39,6 +39,8 @@ $table->rows([
$table->create();
$table->render();
echo \kernel\helpers\Html::img(\kernel\app_modules\card\services\CardFileService::createCardPNG($card));
//$writer = new PngWriter();
//
//// Create QR code

View File

@ -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,19 @@ 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();
}
}

View File

@ -17,10 +17,6 @@ App::$collector->group(["prefix" => "admin"], function (CgRouteCollector $router
App::$collector->any("/edit/{id}", [\app\modules\tgbot\controllers\TgbotController::class, 'actionEdit']);
App::$collector->get('/delete/{id}', [\app\modules\tgbot\controllers\TgbotController::class, 'actionDelete']);
});
App::$collector->group(["prefix" => "settings"], function (CGRouteCollector $router) {
App::$collector->get('/tag', [\app\modules\tag\controllers\TagController::class, 'actionSettings']);
App::$collector->post('/tag/update', [\app\modules\tag\controllers\TagController::class, 'actionSaveSettings']);
});
});
});

View File

@ -40,9 +40,43 @@ class ImageGD
imagedestroy($this->img);
}
public function makeCornersForImage($radius, $background): void
{
// включаем режим сопряжения цветов
imagealphablending($this->img, true);
// размер исходной картинки
$width = imagesx($this->img);
$height = imagesy($this->img);
// создаем изображение для углов
$corner = imagecreatetruecolor($radius, $radius);
imagealphablending($corner, false);
// прозрачный цвет
$trans = imagecolorallocatealpha($corner, 255, 255, 255, 127);
// заливаем картинку для углов
imagefill($corner, 0, 0, $background);
// рисуем прозрачный эллипс
imagefilledellipse($corner, $radius, $radius, $radius * 2, $radius * 2, $trans);
// массив положений. Для расположения по углам
$positions = array(
array(0, 0),
array($width - $radius, 0),
array($width - $radius, $height - $radius),
array(0, $height - $radius),
);
// накладываем на углы картинки изображение с прозрачными эллипсами
foreach ($positions as $pos) {
imagecopyresampled($this->img, $corner, $pos[0], $pos[1], 0, 0, $radius, $radius, $radius, $radius);
// поворачиваем картинку с эллипсов каждый раз на 90 градусов
$corner = imagerotate($corner, -90, $background);
}
}
protected function hexToRgb(string $hex)
{
return sscanf($hex, "#%02x%02x%02x");
}
}

View File

@ -1,6 +1,6 @@
{
"name": "Kernel",
"version": "0.1.2",
"version": "0.1.3",
"author": "ITGuild",
"slug": "kernel",
"type": "kernel",

View File

@ -13,21 +13,28 @@ use kernel\services\TokenService;
class SecureService
{
public static function createSecretCode(User $user): void
public static function createSecretCode(User $user): SecretCode
{
$secretCode = new SecretCode();
$secretCode->user_id = $user->id;
$secretCode->code = mt_rand(100000, 999999);
$secretCode->code_expires_at = date("Y-m-d H:i:s", strtotime("+5 minutes"));;
$secretCode->save();
return $secretCode;
}
public static function updateSecretCode(User $user): void
public static function updateSecretCode(User $user): SecretCode
{
$secretCode = SecretCode::where('user_id', $user->id)->first();
if(!$secretCode){
return self::createSecretCode($user);
}
$secretCode->code = mt_rand(100000, 999999);
$secretCode->code_expires_at = date("Y-m-d H:i:s", strtotime("+5 minutes"));;
$secretCode->save();
return $secretCode;
}
public static function getCodeByUserId(int $user_id)

Binary file not shown.

Binary file not shown.

View File

@ -1,7 +1,18 @@
import {TgApp} from "./tg_app/TgApp.js";
import Router from "./tg_app/Router.js";
document.addEventListener("DOMContentLoaded", () => {
let tg = window.Telegram.WebApp;
let tgApp = new TgApp("tg_app", tg.initDataUnsafe.user.id);
const router = new Router({
mode: 'hash',
root: '/miniapp'
});
router
.add('', () => {
tgApp.actionMain();
});
});

View File

@ -0,0 +1,84 @@
class Router {
routes = [];
mode = null;
root = '/';
constructor(options) {
this.mode = window.history.pushState ? 'history' : 'hash';
if (options.mode) this.mode = options.mode;
if (options.root) this.root = options.root;
this.listen();
}
add = (path, cb) => {
this.routes.push({ path, cb });
return this;
};
remove = path => {
for (let i = 0; i < this.routes.length; i += 1) {
if (this.routes[i].path === path) {
this.routes.slice(i, 1);
return this;
}
}
return this;
};
flush = () => {
this.routes = [];
return this;
};
clearSlashes = path =>
path
.toString()
.replace(/\/$/, '')
.replace(/^\//, '');
getFragment = () => {
let fragment = '';
if (this.mode === 'history') {
fragment = this.clearSlashes(decodeURI(window.location.pathname + window.location.search));
fragment = fragment.replace(/\?(.*)$/, '');
fragment = this.root !== '/' ? fragment.replace(this.root, '') : fragment;
} else {
const match = window.location.href.match(/#(.*)$/);
fragment = match ? match[1] : '';
}
return this.clearSlashes(fragment);
};
navigate = (path = '') => {
if (this.mode === 'history') {
window.history.pushState(null, null, this.root + this.clearSlashes(path));
} else {
window.location.href = `${window.location.href.replace(/#(.*)$/, '')}#${path}`;
}
return this;
};
listen = () => {
clearInterval(this.interval);
this.interval = setInterval(this.interval, 50);
};
interval = () => {
if (this.current === this.getFragment()) return;
this.current = this.getFragment();
this.routes.some(route => {
const match = this.current.match(route.path);
if (match) {
match.shift();
route.cb.apply({}, match);
return match;
}
return false;
});
};
}
export default Router;

View File

@ -3,13 +3,17 @@ import config from "./config_local.js";
class TgApp {
constructor(containerId, userId) {
this.container = document.getElementById(containerId);
this.userId = userId;
}
actionMain(){
console.log("main 123")
this.createCardBox();
this.createDefaultBox();
this.userId = userId;
this.getCard();
}
setUserId(userId){
setUserId(userId) {
this.userId = userId;
}
@ -31,7 +35,7 @@ class TgApp {
this.container.appendChild(this.defaultBox);
}
getCard(){
getCard() {
let botId = config.config.botId;
fetch(config.config.apiUrl + `api/tg-bot/get-card-by-dialog/${this.userId}/${botId}`, {
method: 'GET', // Здесь так же могут быть GET, PUT, DELETE
@ -47,6 +51,15 @@ class TgApp {
})
}
getAction(action){
if (action === "actionMain"){
return this.actionMain;
}
return false;
}
}
const templates =
@ -68,7 +81,7 @@ const templates =
return `<div class="card" style="padding: 10px;">
<img src="${cardUrl}" class="card-img-top"/>
<div class="card-body">
<h6 class="card-title">Баланс: ${balance}</h6>
<h4 class="card-title">Баланс: ${balance}</h4>
</div>
</div>`;
}