card action
This commit is contained in:
@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
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));
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,29 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
public string $migration;
|
||||
/**
|
||||
* Run the migrations.
|
||||
*/
|
||||
public function up(): void
|
||||
{
|
||||
\kernel\App::$db->schema->table('card', function(Blueprint $table) {
|
||||
$table->renameColumn('program', 'card_program_id');
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
\kernel\App::$db->schema->table('card', function(Blueprint $table) {
|
||||
$table->renameColumn('card_program_id', 'program');
|
||||
});
|
||||
}
|
||||
};
|
@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
public string $migration;
|
||||
/**
|
||||
* Run the migrations.
|
||||
*/
|
||||
public function up(): void
|
||||
{
|
||||
\kernel\App::$db->schema->table('card_transaction', function(Blueprint $table) {
|
||||
$table->integer("from_balance")->after("from")->default(0);
|
||||
$table->integer("to_balance")->after("to")->default(0);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
\kernel\App::$db->schema->table('card_transaction', function(Blueprint $table) {
|
||||
$table->dropColumn("from_balance");
|
||||
$table->dropColumn("to_balance");
|
||||
});
|
||||
}
|
||||
};
|
@ -14,7 +14,7 @@ use kernel\modules\user\models\User;
|
||||
* @property int $payment_type
|
||||
* @property int $bank_id
|
||||
* @property int $info
|
||||
* @property int $program
|
||||
* @property int $card_program_id
|
||||
* @property int $cvc
|
||||
* @property int $pin
|
||||
* @property int $card_template_id
|
||||
@ -28,7 +28,7 @@ class Card extends Model
|
||||
|
||||
protected $table = 'card';
|
||||
|
||||
protected $fillable = ['user_id', 'payment_type', 'balance', 'bank_id', 'info', 'program', 'cvc', 'pin', 'username', 'card_template_id', 'card_file_id', 'status'];
|
||||
protected $fillable = ['user_id', 'payment_type', 'balance', 'bank_id', 'info', 'card_program_id', 'cvc', 'pin', 'username', 'card_template_id', 'card_file_id', 'status'];
|
||||
|
||||
public static function labels(): array
|
||||
{
|
||||
@ -46,7 +46,7 @@ class Card extends Model
|
||||
'balance' => 'Баланс',
|
||||
'bank_id' => 'ID банка',
|
||||
'info' => 'Информация о банке',
|
||||
'program' => 'Программа',
|
||||
'card_program_id' => 'Программа',
|
||||
'cvc' => 'CVC',
|
||||
'pin' => 'PIN',
|
||||
'username' => 'Username',
|
||||
@ -72,6 +72,11 @@ class Card extends Model
|
||||
return $this->belongsTo(CardTemplate::class);
|
||||
}
|
||||
|
||||
public function cardProgram(): \Illuminate\Database\Eloquent\Relations\BelongsTo
|
||||
{
|
||||
return $this->belongsTo(related: CardProgram::class);
|
||||
}
|
||||
|
||||
public function cardFile(): \Illuminate\Database\Eloquent\Relations\BelongsTo
|
||||
{
|
||||
return $this->belongsTo(CardFile::class);
|
||||
|
@ -37,6 +37,11 @@ class CardProgram extends Model
|
||||
];
|
||||
}
|
||||
|
||||
public function cardProgramConditions(): \Illuminate\Database\Eloquent\Relations\HasMany
|
||||
{
|
||||
return $this->hasMany(CardProgramConditions::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string[]
|
||||
*/
|
||||
|
@ -7,6 +7,8 @@ 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
|
||||
@ -20,7 +22,7 @@ class CardTransaction extends Model
|
||||
|
||||
protected $table = 'card_transaction';
|
||||
|
||||
protected $fillable = ['from', 'to', 'amount', 'type', 'status'];
|
||||
protected $fillable = ['from', 'from_balance', 'to', 'to_balance', 'amount', 'type', 'status'];
|
||||
|
||||
public static function labels(): array
|
||||
{
|
||||
|
@ -23,7 +23,7 @@ class CreateCardForm extends FormModel
|
||||
'balance' => 'alpha-numeric',
|
||||
'bank_id' => 'required|alpha-numeric',
|
||||
'info' => 'required|alpha-numeric',
|
||||
'program' => 'required|alpha-numeric',
|
||||
'card_program_id' => 'required|alpha-numeric',
|
||||
'cvc' => 'required|alpha-numeric',
|
||||
'pin' => 'required|alpha-numeric',
|
||||
'username' => 'required|min-str-len:5|max-str-len:20',
|
||||
|
@ -19,7 +19,9 @@ class CreateCardTransactionForm extends FormModel
|
||||
// ];
|
||||
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' => ''
|
||||
|
@ -57,7 +57,7 @@ class CardFileService
|
||||
if ($card->cardTemplate) {
|
||||
$formatter = BankFormatter::create();
|
||||
|
||||
$customer = BankFactory::create()->paymentType($card->payment_type)->bank($card->bank_id, $card->info, $card->program)->client($card->id);
|
||||
$customer = BankFactory::create()->paymentType($card->payment_type)->bank($card->bank_id, $card->info, $card->card_program_id)->client($card->id);
|
||||
|
||||
$cardNumber = CardNumber::generate($customer, $formatter);
|
||||
//Card
|
||||
|
@ -5,6 +5,8 @@ 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;
|
||||
@ -14,10 +16,12 @@ 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
|
||||
@ -28,7 +32,7 @@ class CardService
|
||||
$model->payment_type = $form_model->getItem('payment_type') ?? 2;
|
||||
$model->bank_id = $form_model->getItem('bank_id') ?? 232;
|
||||
$model->info = $form_model->getItem('info') ?? 42;
|
||||
$model->program = $form_model->getItem('program') ?? 71;
|
||||
$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;
|
||||
@ -56,7 +60,7 @@ class CardService
|
||||
$card->payment_type = $form_model->getItem('payment_type');
|
||||
$card->bank_id = $form_model->getItem('bank_id');
|
||||
$card->info = $form_model->getItem('info');
|
||||
$card->program = $form_model->getItem('program');
|
||||
$card->card_program_id = $form_model->getItem('card_program_id');
|
||||
$card->balance = $form_model->getItem('balance');
|
||||
$card->cvc = $form_model->getItem('cvc');
|
||||
$card->pin = $form_model->getItem('pin');
|
||||
@ -81,12 +85,44 @@ class CardService
|
||||
return false;
|
||||
}
|
||||
|
||||
public static function addMoneyToCard(Card $card, int $amount): CardTransaction
|
||||
{
|
||||
$transactionForm = new CreateCardTransactionForm();
|
||||
$transactionForm->load([
|
||||
'from' => 1001,
|
||||
'to' => $card->id,
|
||||
'amount' => $amount,
|
||||
'type' => 1,
|
||||
'status' => 1,
|
||||
]);
|
||||
|
||||
$transactionService = new CardTransactionService();
|
||||
|
||||
return $transactionService->create($transactionForm);
|
||||
}
|
||||
|
||||
public static function withdrawMoneyFromCard(Card $card, int $amount): CardTransaction
|
||||
{
|
||||
$transactionForm = new CreateCardTransactionForm();
|
||||
$transactionForm->load([
|
||||
'from' => $card->id,
|
||||
'to' => 1001,
|
||||
'amount' => $amount,
|
||||
'type' => 1,
|
||||
'status' => 1,
|
||||
]);
|
||||
|
||||
$transactionService = new CardTransactionService();
|
||||
|
||||
return $transactionService->create($transactionForm);
|
||||
}
|
||||
|
||||
public static function createCardPNG(Card $card): false|string
|
||||
{
|
||||
if ($card->cardTemplate) {
|
||||
$formatter = BankFormatter::create();
|
||||
|
||||
$customer = BankFactory::create()->paymentType($card->payment_type)->bank($card->bank_id, $card->info, $card->program)->client($card->id);
|
||||
$customer = BankFactory::create()->paymentType($card->payment_type)->bank($card->bank_id, $card->info, $card->card_program_id)->client($card->id);
|
||||
|
||||
$cardNumber = CardNumber::generate($customer, $formatter);
|
||||
//Card
|
||||
@ -110,6 +146,16 @@ class CardService
|
||||
return false;
|
||||
}
|
||||
|
||||
public static function getCardById(int $id)
|
||||
{
|
||||
$card = Card::find($id);
|
||||
if ($card) {
|
||||
return $card;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public static function userHasCard(int $userId): bool
|
||||
{
|
||||
$card = Card::where("user_id", $userId)->first();
|
||||
|
@ -24,6 +24,7 @@ class CardTransactionService
|
||||
$this->errors[] = ["error_id" => 3, "error_msg" => "Sender not found"];
|
||||
return false;
|
||||
}
|
||||
$model->from_balance = $fromCard->balance;
|
||||
}
|
||||
|
||||
if ($toId !== 1001){
|
||||
@ -32,6 +33,7 @@ class CardTransactionService
|
||||
$this->errors[] = ["error_id" => 3, "error_msg" => "Recipient not found"];
|
||||
return false;
|
||||
}
|
||||
$model->to_balance = $toCard->balance;
|
||||
}
|
||||
|
||||
if ($fromId !== 1001){
|
||||
@ -49,11 +51,11 @@ class CardTransactionService
|
||||
// $model->slug = Slug::createSlug($form_model->getItem('title'), Card::class); // Генерация уникального slug
|
||||
|
||||
if ($model->save()) {
|
||||
if ($fromCard){
|
||||
if (isset($fromCard)){
|
||||
$fromCard->balance = $fromCard->balance - (int)$form_model->getItem('amount');
|
||||
$fromCard->save();
|
||||
}
|
||||
if ($toCard){
|
||||
if (isset($toCard)){
|
||||
$toCard->balance = $toCard->balance + (int)$form_model->getItem('amount');
|
||||
$toCard->save();
|
||||
}
|
||||
|
@ -58,9 +58,9 @@ $form->field(\itguild\forms\inputs\TextInput::class, 'info', [
|
||||
->setLabel("Информация")
|
||||
->render();
|
||||
|
||||
$form->field(class: \itguild\forms\inputs\Select::class, name: "program", params: [
|
||||
$form->field(class: \itguild\forms\inputs\Select::class, name: "card_program_id", params: [
|
||||
'class' => "form-control",
|
||||
'value' => $model->program ?? ''
|
||||
'value' => $model->card_program_id ?? ''
|
||||
])
|
||||
->setLabel("Программа")
|
||||
->setOptions(\kernel\app_modules\card\services\CardProgramService::getProgramList())
|
||||
|
@ -18,6 +18,7 @@ class Tgbot extends Model
|
||||
{
|
||||
const DISABLE_STATUS = 0;
|
||||
const ACTIVE_STATUS = 1;
|
||||
const ADMIN_STATUS = 9;
|
||||
|
||||
protected $table = 'tgbot';
|
||||
|
||||
|
@ -11,6 +11,8 @@ use kernel\services\ModuleService;
|
||||
|
||||
class TgBotService
|
||||
{
|
||||
public static null|Tgbot $currentDialog = null;
|
||||
|
||||
public function create(FormModel $form_model): false|Tgbot
|
||||
{
|
||||
$model = new Tgbot();
|
||||
@ -45,4 +47,13 @@ class TgBotService
|
||||
return false;
|
||||
}
|
||||
|
||||
public static function isAdmin(): bool
|
||||
{
|
||||
if (self::$currentDialog->status === Tgbot::ADMIN_STATUS){
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
@ -71,10 +71,15 @@ class MigrationController extends ConsoleController
|
||||
$dmr = new DatabaseMigrationRepository(App::$db->capsule->getDatabaseManager(), 'migration');
|
||||
|
||||
$m = new Migrator($dmr, App::$db->capsule->getDatabaseManager(), new Filesystem());
|
||||
if (\kernel\App::$db->schema->hasTable('option')) {
|
||||
$migrationPaths = array_merge($this->moduleService->getModulesMigrationsPaths(), [ROOT_DIR . '/migrations']);
|
||||
} else {
|
||||
$migrationPaths = [ROOT_DIR . '/migrations'];
|
||||
if (isset($this->argv['path'])){
|
||||
$migrationPaths = [ROOT_DIR . $this->argv['path']];
|
||||
}
|
||||
else {
|
||||
if (\kernel\App::$db->schema->hasTable('option')) {
|
||||
$migrationPaths = array_merge($this->moduleService->getModulesMigrationsPaths(), [ROOT_DIR . '/migrations']);
|
||||
} else {
|
||||
$migrationPaths = [ROOT_DIR . '/migrations'];
|
||||
}
|
||||
}
|
||||
|
||||
$res = $m->run($migrationPaths);
|
||||
@ -94,7 +99,13 @@ class MigrationController extends ConsoleController
|
||||
|
||||
$m = new Migrator($dmr, App::$db->capsule->getDatabaseManager(), new Filesystem());
|
||||
//$migrationPaths = array_merge(App::$migrationsPaths, [WORKSPACE_DIR . '/console/migrations']);
|
||||
$migrationPaths = [ROOT_DIR . '/migrations'];
|
||||
if (isset($this->argv['path'])){
|
||||
$migrationPaths = [ROOT_DIR . $this->argv['path']];
|
||||
}
|
||||
else {
|
||||
$migrationPaths = [ROOT_DIR . '/migrations'];
|
||||
}
|
||||
|
||||
$res = $m->rollback($migrationPaths, ['step' => $step]);
|
||||
print_r($step);
|
||||
foreach ($res as $re) {
|
||||
|
Reference in New Issue
Block a user