notification
This commit is contained in:
		| @@ -8,8 +8,13 @@ use app\modules\tgbot\services\TgBotService; | ||||
| use Cassandra\Decimal; | ||||
| use kernel\app_modules\card\conditions\CashbackCondition; | ||||
| use kernel\app_modules\card\models\Card; | ||||
| use kernel\app_modules\card\models\CardTransaction; | ||||
| use kernel\app_modules\card\services\CardService; | ||||
| use kernel\app_modules\card\services\CardTransactionService; | ||||
| use kernel\app_modules\tag\service\TagService; | ||||
| use kernel\app_modules\tgbot\models\forms\CreateTgbotNotificationForm; | ||||
| use kernel\app_modules\tgbot\models\TgbotNotification; | ||||
| use kernel\app_modules\tgbot\services\TgbotNotificationService; | ||||
| use kernel\Controller; | ||||
| use kernel\Flash; | ||||
| use kernel\helpers\Debug; | ||||
| @@ -76,15 +81,15 @@ class TgMainController extends Controller | ||||
|  | ||||
|         $card = CardService::getCardById($params->getItem("card_id")); | ||||
|  | ||||
|         if ($params->getItem('type') === 'add_money'){ | ||||
|         if ($params->getItem('type') === 'add_money') { | ||||
|             Flash::setMessage("success", "Баланс пополнен на " . $params->getItem('amount')); | ||||
|             $transaction = CardService::addMoneyToCard($card, (int)$params->getItem('amount')); | ||||
|         } | ||||
|         if ($params->getItem('type') === 'withdraw'){ | ||||
|         if ($params->getItem('type') === 'withdraw') { | ||||
|             Flash::setMessage("success", "С карты списано " . $params->getItem('amount')); | ||||
|             $transaction = CardService::withdrawMoneyFromCard($card, (int)$params->getItem('amount')); | ||||
|         } | ||||
|         if ($params->getItem('type') === 'add_purchase'){ | ||||
|         if ($params->getItem('type') === 'add_purchase') { | ||||
| //            Flash::setMessage("success", "С карты списано " . $params->getItem('amount')); | ||||
| //            CardService::withdrawMoneyFromCard($card, (int)$params->getItem('amount')); | ||||
|             $cashback = new CashbackCondition(); | ||||
| @@ -94,7 +99,30 @@ class TgMainController extends Controller | ||||
|  | ||||
|         $card = $card->fresh(); | ||||
|  | ||||
|         $tgbot = Tgbot::where("user_id", $card->user_id)->first(); | ||||
|         if ($tgbot) { | ||||
|             $notificationForm = new CreateTgbotNotificationForm(); | ||||
|             $notificationForm->load([ | ||||
|                 'bot_id' => $tgbot->bot_id, | ||||
|                 'dialog_id' => $tgbot->dialog_id, | ||||
|                 'content' => "На вашу карту начисленно " . $transaction->amount . " бонуса.", | ||||
|                 'status' => TgbotNotification::TO_SEND_STATUS, | ||||
|             ]); | ||||
|             $notificationService = new TgbotNotificationService(); | ||||
|             $notificationService->create($notificationForm); | ||||
|         } | ||||
|  | ||||
|  | ||||
|         $this->cgView->render("card_action_step_3.php", ['card' => $card, 'transaction' => $transaction ?? null]); | ||||
|     } | ||||
|  | ||||
|     public function actionCardInfo(int $cardId): void | ||||
|     { | ||||
|         $card = Card::where("id", $cardId)->first(); | ||||
|  | ||||
|         $transactions = CardTransaction::where("from", $cardId)->orWhere("to", $cardId)->get(); | ||||
|  | ||||
|         $this->cgView->render("card_info.php", ['card' => $card, 'transactions' => $transactions]); | ||||
|     } | ||||
|  | ||||
| } | ||||
| @@ -18,6 +18,7 @@ App::$collector->group(["prefix" => "miniapp"], function (CGRouteCollector $rout | ||||
|             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']); | ||||
|         }); | ||||
|     }); | ||||
| }); | ||||
| @@ -35,4 +35,9 @@ use kernel\helpers\Html; | ||||
|     <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> | ||||
							
								
								
									
										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,7 +1,7 @@ | ||||
| <?php | ||||
|  | ||||
| $secure_config = [ | ||||
|     'web_auth_type' => 'email_code', // login_password, email_code | ||||
|     'web_auth_type' => 'login_password', // login_password, email_code | ||||
|     'token_type' => 'hash', // random_bytes, md5, crypt, hash, JWT | ||||
|     'token_expired_time' => "+30 days", // +1 day | ||||
| ]; | ||||
|   | ||||
| @@ -43,6 +43,11 @@ class CardTransaction extends Model | ||||
|         ]; | ||||
|     } | ||||
|  | ||||
|     public function fromCard(): \Illuminate\Database\Eloquent\Relations\BelongsTo | ||||
|     { | ||||
|         return $this->belongsTo(Card::class, ownerKey: "from"); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * @return string[] | ||||
|      */ | ||||
|   | ||||
| @@ -27,32 +27,12 @@ $table = new ListEloquentTable(new EloquentDataProvider(\kernel\app_modules\card | ||||
|     'baseUrl' => "/admin/card_transaction" | ||||
| ])); | ||||
|  | ||||
|  | ||||
| //$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_transaction/create'])->run(); | ||||
|     $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([ | ||||
| @@ -61,7 +41,28 @@ $table->columns([ | ||||
|             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) { | ||||
|   | ||||
| @@ -29,11 +29,27 @@ class TgbotModule extends Module | ||||
|             "url" => "/admin/tg-bot", | ||||
|             "slug" => "tg-bot", | ||||
|         ]); | ||||
|  | ||||
|         $this->menuService->createItem([ | ||||
|             "label" => "Диалоги", | ||||
|             "url" => "/admin/tg-bot", | ||||
|             "slug" => "tg-bot-dialogs", | ||||
|             "parent_slug" => "tg-bot", | ||||
|         ]); | ||||
|  | ||||
|         $this->menuService->createItem([ | ||||
|             "label" => "Уведомления", | ||||
|             "url" => "/admin/tg-bot-notification", | ||||
|             "slug" => "tg-bot-notification", | ||||
|             "parent_slug" => "tg-bot", | ||||
|         ]); | ||||
|     } | ||||
|  | ||||
|     public function deactivate() | ||||
|     { | ||||
|         $this->menuService->removeItemBySlug("tg-bot"); | ||||
|         $this->menuService->removeItemBySlug("tg-bot-dialogs"); | ||||
|         $this->menuService->removeItemBySlug("tg-bot-notification"); | ||||
|         $this->migrationService->rollbackAtPath("{KERNEL_APP_MODULES}/tgbot/migrations"); | ||||
|     } | ||||
| } | ||||
| @@ -0,0 +1,114 @@ | ||||
| <?php | ||||
|  | ||||
| namespace kernel\app_modules\tgbot\controllers; | ||||
|  | ||||
| use Exception; | ||||
| use JetBrains\PhpStorm\NoReturn; | ||||
| use kernel\AdminController; | ||||
| use kernel\app_modules\tgbot\models\forms\CreateTgbotNotificationForm; | ||||
| use kernel\app_modules\tgbot\models\TgbotNotification; | ||||
| use kernel\app_modules\tgbot\services\TgbotNotificationService; | ||||
| use kernel\Flash; | ||||
|  | ||||
| class TgbotNotificationController extends AdminController | ||||
| { | ||||
|     protected TgbotNotificationService $notificationService; | ||||
|  | ||||
|     protected function init(): void | ||||
|     { | ||||
|         parent::init(); | ||||
|         $this->cgView->viewPath = KERNEL_APP_MODULES_DIR . "/tgbot/views/notification/"; | ||||
|         $this->notificationService = new TgbotNotificationService(); | ||||
|     } | ||||
|  | ||||
|     public function actionCreate(): void | ||||
|     { | ||||
|         $this->cgView->render("form.php"); | ||||
|     } | ||||
|  | ||||
|     public function actionIndex($page_number = 1): void | ||||
|     { | ||||
|         $this->cgView->render("index.php", ['page_number' => $page_number]); | ||||
|     } | ||||
|  | ||||
|     #[NoReturn] public function actionAdd(): void | ||||
|     { | ||||
|         $tgForm = new CreateTgbotNotificationForm(); | ||||
|         $tgForm->load($_REQUEST); | ||||
|         if ($tgForm->validate()) { | ||||
|             $tg = $this->notificationService->create($tgForm); | ||||
|             if ($tg) { | ||||
|                 $this->redirect("/admin/tg-bot-notification/view/" . $tg->id); | ||||
|             } | ||||
|         } | ||||
|  | ||||
|         Flash::setMessage("error", $tgForm->getErrorsStr()); | ||||
|         $this->redirect("/admin/tg-bot-notification/create"); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * @throws Exception | ||||
|      */ | ||||
|     public function actionUpdate($id): void | ||||
|     { | ||||
|         $model = TgbotNotification::find($id); | ||||
|         if (!$model) { | ||||
|             throw new Exception(message: "The notification not found"); | ||||
|         } | ||||
|  | ||||
|         $this->cgView->render("form.php", ['model' => $model]); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * @throws Exception | ||||
|      */ | ||||
|     public function actionEdit($id): void | ||||
|     { | ||||
|         $tg = TgbotNotification::find($id); | ||||
|         if (!$tg) { | ||||
|             throw new Exception(message: "The tag not found"); | ||||
|         } | ||||
|         $tgForm = new CreateTgbotNotificationForm(); | ||||
|         $tgService = new TgbotNotificationService(); | ||||
|         $tgForm->load($_REQUEST); | ||||
|         if ($tgForm->validate()) { | ||||
|             $tg = $tgService->update($tgForm, $tg); | ||||
|             if ($tg) { | ||||
|                 $this->redirect("/admin/tg-bot-notification/view/" . $tg->id); | ||||
|             } | ||||
|         } | ||||
|  | ||||
|         Flash::setMessage("error", $tgForm->getErrorsStr()); | ||||
|         $this->redirect("/admin/tg-bot-notification/update/" . $id); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * @throws Exception | ||||
|      */ | ||||
|     public function actionView($id): void | ||||
|     { | ||||
|         $tg = TgbotNotification::find($id); | ||||
|  | ||||
|         if (!$tg) { | ||||
|             throw new Exception(message: "The notification not found"); | ||||
|         } | ||||
|         $this->cgView->render("view.php", ['tg' => $tg]); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * @throws Exception | ||||
|      */ | ||||
|     #[NoReturn] public function actionDelete(int $id): void | ||||
|     { | ||||
|         $post = TgbotNotification::find($id)->first(); | ||||
|         if (!$post){ | ||||
|             throw new Exception(message: "The tg notification not found"); | ||||
|         } | ||||
|  | ||||
|         Flash::setMessage("success", "Notification deleted"); | ||||
|         $post->delete(); | ||||
|         $this->redirect("/admin/tg-bot-notification/"); | ||||
|     } | ||||
|  | ||||
|  | ||||
| } | ||||
| @@ -0,0 +1,30 @@ | ||||
| <?php | ||||
|  | ||||
| namespace kernel\app_modules\tgbot\controllers; | ||||
|  | ||||
| use JetBrains\PhpStorm\NoReturn; | ||||
| use kernel\app_modules\tgbot\models\TgbotNotification; | ||||
| use kernel\RestController; | ||||
|  | ||||
| class TgbotNotificationRestController extends RestController | ||||
| { | ||||
|  | ||||
|     public function __construct() | ||||
|     { | ||||
|         $this->model = new TgbotNotification(); | ||||
|     } | ||||
|  | ||||
|     #[NoReturn] public function actionGetToSend(): void | ||||
|     { | ||||
|         $notification = TgbotNotification::where("status", TgbotNotification::TO_SEND_STATUS)->first(); | ||||
|         if ($notification){ | ||||
|             $notification->status = TgbotNotification::SENT_STATUS; | ||||
|             $notification->save(); | ||||
|  | ||||
|             $this->renderApi($notification->toArray()); | ||||
|         } | ||||
|  | ||||
|         $this->renderApi([]); | ||||
|     } | ||||
|  | ||||
| } | ||||
| @@ -0,0 +1,34 @@ | ||||
| <?php | ||||
|  | ||||
| use Illuminate\Database\Migrations\Migration; | ||||
| use Illuminate\Database\Schema\Blueprint; | ||||
| use Illuminate\Support\Facades\Schema; | ||||
|  | ||||
| return new class extends Migration | ||||
| { | ||||
|     public string $migration; | ||||
|     /** | ||||
|      * Run the migrations. | ||||
|      */ | ||||
|     public function up(): void | ||||
|     { | ||||
|         \kernel\App::$db->schema->create('tgbot_notification', function (Blueprint $table) { | ||||
|             $table->increments('id'); | ||||
|             $table->bigInteger('bot_id')->nullable(false); | ||||
|             $table->bigInteger('dialog_id')->nullable(); | ||||
|             $table->string('to_group')->nullable(); | ||||
|             $table->text('content')->nullable(); | ||||
|             $table->string('photo')->nullable(); | ||||
|             $table->integer('status')->nullable()->default(1); | ||||
|             $table->timestamps(); | ||||
|         }); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Reverse the migrations. | ||||
|      */ | ||||
|     public function down(): void | ||||
|     { | ||||
|         \kernel\App::$db->schema->dropIfExists('tgbot_notification'); | ||||
|     } | ||||
| }; | ||||
							
								
								
									
										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 => "Отправлено", | ||||
|         ]; | ||||
|     } | ||||
|  | ||||
| } | ||||
| @@ -0,0 +1,30 @@ | ||||
| <?php | ||||
|  | ||||
| namespace kernel\app_modules\tgbot\models\forms; | ||||
|  | ||||
| use kernel\FormModel; | ||||
|  | ||||
| /** | ||||
|  * @property int $bot_id | ||||
|  * @property int $dialog_id | ||||
|  * @property string $to_group | ||||
|  * @property string $content | ||||
|  * @property string $photo | ||||
|  * @property int $status | ||||
|  */ | ||||
| class CreateTgbotNotificationForm extends FormModel | ||||
| { | ||||
|  | ||||
|     public function rules(): array | ||||
|     { | ||||
|         return [ | ||||
|             'bot_id' => 'required|alpha-numeric', | ||||
|             'dialog_id' => 'alpha-numeric', | ||||
|             'to_group' => 'alpha-numeric', | ||||
|             'content' => 'min-str-len:5', | ||||
|             'photo' => 'min-str-len:5', | ||||
|             'status' => 'alpha-numeric' | ||||
|         ]; | ||||
|     } | ||||
|  | ||||
| } | ||||
| @@ -4,18 +4,30 @@ | ||||
| use kernel\App; | ||||
| use kernel\CgRouteCollector; | ||||
| use Phroute\Phroute\RouteCollector; | ||||
| use kernel\app_modules\tgbot\controllers\TgbotNotificationController; | ||||
| use kernel\app_modules\tgbot\controllers\TgbotController; | ||||
|  | ||||
| App::$collector->group(["prefix" => "admin"], function (CgRouteCollector $router) { | ||||
|     App::$collector->group(["before" => "auth"], function (RouteCollector $router) { | ||||
|         App::$collector->group(["prefix" => "tg-bot"], function (CGRouteCollector $router) { | ||||
|             App::$collector->get('/', [\app\modules\tgbot\controllers\TgbotController::class, 'actionIndex']); | ||||
|             App::$collector->get('/page/{page_number}', [\app\modules\tgbot\controllers\TgbotController::class, 'actionIndex']); | ||||
|             App::$collector->get('/create', [\app\modules\tgbot\controllers\TgbotController::class, 'actionCreate']); | ||||
|             App::$collector->post("/", [\app\modules\tgbot\controllers\TgbotController::class, 'actionAdd']); | ||||
|             App::$collector->get('/view/{id}', [\app\modules\tgbot\controllers\TgbotController::class, 'actionView']); | ||||
|             App::$collector->any('/update/{id}', [\app\modules\tgbot\controllers\TgbotController::class, 'actionUpdate']); | ||||
|             App::$collector->any("/edit/{id}", [\app\modules\tgbot\controllers\TgbotController::class, 'actionEdit']); | ||||
|             App::$collector->get('/delete/{id}', [\app\modules\tgbot\controllers\TgbotController::class, 'actionDelete']); | ||||
|             App::$collector->get('/', [TgbotController::class, 'actionIndex']); | ||||
|             App::$collector->get('/page/{page_number}', [TgbotController::class, 'actionIndex']); | ||||
|             App::$collector->get('/create', [TgbotController::class, 'actionCreate']); | ||||
|             App::$collector->post("/", [TgbotController::class, 'actionAdd']); | ||||
|             App::$collector->get('/view/{id}', [TgbotController::class, 'actionView']); | ||||
|             App::$collector->any('/update/{id}', [TgbotController::class, 'actionUpdate']); | ||||
|             App::$collector->any("/edit/{id}", [TgbotController::class, 'actionEdit']); | ||||
|             App::$collector->get('/delete/{id}', [TgbotController::class, 'actionDelete']); | ||||
|         }); | ||||
|         App::$collector->group(["prefix" => "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']); | ||||
|         }); | ||||
|     }); | ||||
| }); | ||||
| @@ -28,4 +40,5 @@ App::$collector->group(["prefix" => "api"], function (CgRouteCollector $router){ | ||||
|     }); | ||||
|     $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']); | ||||
| }); | ||||
| @@ -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(); | ||||
| @@ -6,6 +6,7 @@ use Exception; | ||||
| use JetBrains\PhpStorm\NoReturn; | ||||
| use kernel\AdminController; | ||||
| use kernel\FileUpload; | ||||
| use kernel\Flash; | ||||
| use kernel\models\Menu; | ||||
| use kernel\modules\menu\models\forms\CreateMenuForm; | ||||
| use kernel\modules\menu\service\MenuService; | ||||
| @@ -46,6 +47,7 @@ class MenuController extends AdminController | ||||
|                 $this->redirect("/admin/settings/menu/view/" . $menuItem->id, code: 302); | ||||
|             } | ||||
|         } | ||||
|         Flash::setMessage("error", $menuForm->getErrorsStr()); | ||||
|         $this->redirect("/admin/settings/menu/create", code: 302); | ||||
|     } | ||||
|  | ||||
|   | ||||
		Reference in New Issue
	
	Block a user