From 3eea63b14765071d1bedf449cb82ef767030fc5d Mon Sep 17 00:00:00 2001 From: Rustem Date: Tue, 3 Jun 2025 00:30:33 +0500 Subject: [PATCH] master --- app/Console/PipiCarInstallCommands.php | 3 +- app/Http/Controllers/MobileApiController.php | 48 ++++++ modules/faq/access.json | 9 ++ modules/faq/app.json | 149 +++++++++++++++++++ modules/faq/migrate.php | 25 ++++ modules/faq/script.php | 40 +++++ routes/api.php | 3 + 7 files changed, 276 insertions(+), 1 deletion(-) create mode 100644 modules/faq/access.json create mode 100644 modules/faq/app.json create mode 100644 modules/faq/migrate.php create mode 100644 modules/faq/script.php diff --git a/app/Console/PipiCarInstallCommands.php b/app/Console/PipiCarInstallCommands.php index 86bf7d4..5c94092 100644 --- a/app/Console/PipiCarInstallCommands.php +++ b/app/Console/PipiCarInstallCommands.php @@ -38,7 +38,8 @@ class PipiCarInstallCommands extends InstallCommand 'auto', // авто 'applications', //Заявки 'pipi_users', // Добавление логики для пользователей - 'auto_calendar' // Добавление логики для пользователей + 'auto_calendar', // Добавление логики для пользователей + 'faq' // FAQ ]; } diff --git a/app/Http/Controllers/MobileApiController.php b/app/Http/Controllers/MobileApiController.php index e0bb2ac..4911bfb 100644 --- a/app/Http/Controllers/MobileApiController.php +++ b/app/Http/Controllers/MobileApiController.php @@ -474,4 +474,52 @@ class MobileApiController extends Controller return response()->json($data); } + + public function getFAQCategory(): JsonResponse + { + $faqs = UniModel::model('pipi_faq')->distinct('category')->get(); + $data = []; + foreach ($faqs as $faq) { + $data[] = $faq->category; + } + + if (empty($data)) { + $data = (object) []; + } + + return response()->json($data); + } + public function getFAQSubCategory(Request $request): JsonResponse + { + $category = $request->query('category'); + + $query = UniModel::model('pipi_faq'); + if (isset($category)) { + $query->where('category', $category); + } + $faqs = $query->distinct('subcategory')->get(); + $data = []; + foreach ($faqs as $faq) { + $data[] = $faq->subcategory; + } + + if (empty($data)) { + $data = (object) []; + } + + return response()->json($data); + } + public function getFAQText(Request $request): JsonResponse + { + $subcategory = $request->query('subcategory'); + + $query = UniModel::model('pipi_faq'); + if (isset($subcategory)) { + $query->where('subcategory', $subcategory); + } + $text = $query->first()->text; + + + return response()->json($text); + } } diff --git a/modules/faq/access.json b/modules/faq/access.json new file mode 100644 index 0000000..9e4f179 --- /dev/null +++ b/modules/faq/access.json @@ -0,0 +1,9 @@ +{ + "admin": [ + "default", + "add", + "show", + "edit", + "delete" + ] +} diff --git a/modules/faq/app.json b/modules/faq/app.json new file mode 100644 index 0000000..df321b5 --- /dev/null +++ b/modules/faq/app.json @@ -0,0 +1,149 @@ +{ + "module": "pipicar", + "name": "pipicar.faq", + "type": "crud", + "title": "FAQ", + "withHeader": false, + "data": { + "table": "pipi_faq", + "pk": "id", + "limit": 25, + "segment": true, + "timestamp": false, + "fields": { + "id": { + "type": "pk" + }, + "text": { + "type": "text" + }, + "category": { + "type": "string" + }, + "subcategory": { + "type": "string" + } + } + }, + "ui": { + "grid": { + "title": "FAQ", + "component": "App.components.Grid", + "cols": [ + { + "name": "category", + "caption": "Категория" + }, + { + "name": "subcategory", + "caption": "Подкатегория" + } + ], + "action": { + "head": [ + "add" + ], + "row": [ + "edit", + "delete" + ] + }, + "filter": { + "template": "app.base.crud.filter", + "rows": [ + { + "cols": [ + { + "size": 6, + "input": { + "name": "category", + "label": "Категория" + } + }, + { + "size": 6, + "input": { + "name": "subcategory", + "label": "Подкатегория" + } + } + ] + } + ] + } + }, + "forms": { + "add": { + "title": "FAQ", + "template": "app.base.crud.form", + "component": "App.components.Show", + "form": { + "submits": "struct:crud.form.edit.submits", + "rows": [ + { + "cols": [ + { + "size": 6, + "input": { + "name": "category", + "label": "Категория" + } + }, + { + "size": 6, + "input": { + "name": "subcategory", + "label": "Подкатегория" + } + }, + { + "size": 12, + "input": { + "name": "text", + "label": "Текст" + } + } + ] + } + ] + } + }, + "edit": { + "title": "Редактирование типа", + "template": "app.base.crud.form", + "component": "App.components.Show", + "form": { + "rows": [ + { + "cols": [ + { + "size": 6, + "input": { + "name": "category", + "label": "Категория" + } + }, + { + "size": 6, + "input": { + "name": "subcategory", + "label": "Подкатегория" + } + }, + { + "size": 12, + "input": { + "name": "text", + "label": "Текст" + } + } + ] + } + ], + "submits": "struct:crud.form.edit.submits" + } + } + } + }, + "actions": "struct:crud.actions" +} diff --git a/modules/faq/migrate.php b/modules/faq/migrate.php new file mode 100644 index 0000000..f324c25 --- /dev/null +++ b/modules/faq/migrate.php @@ -0,0 +1,25 @@ +connector)->create('pipi_faq', static function (Blueprint $table) { + $table->id(); + $table->longText('text')->nullable()->comment('Текст'); + $table->string('category')->nullable()->comment('Категория'); + $table->string('subcategory')->nullable()->comment('Подкатегория'); + $table->timestamps(); + $table->softDeletes(); + }); + } + } +}; diff --git a/modules/faq/script.php b/modules/faq/script.php new file mode 100644 index 0000000..3d0f49d --- /dev/null +++ b/modules/faq/script.php @@ -0,0 +1,40 @@ +upgrade(); + } + + private function upgrade(): void + { + $segments = Segment::listActive(); + foreach ($segments as $segment) { + if (!Schema::connection($segment->connector)->hasTable('pipi_faq')) { + Schema::connection($segment->connector)->create('pipi_faq', static function (Blueprint $table) { + $table->id(); + $table->longText('text')->nullable()->comment('Текст'); + $table->string('category')->nullable()->comment('Категория'); + $table->string('subcategory')->nullable()->comment('Подкатегория'); + $table->timestamps(); + $table->softDeletes(); + }); + } + } + } +}; diff --git a/routes/api.php b/routes/api.php index 2efbd28..ef1a845 100644 --- a/routes/api.php +++ b/routes/api.php @@ -26,6 +26,9 @@ Route::prefix('1c')->group(function () { Route::prefix('mobile')->group(function () { Route::get('getMarks', [MobileApiController::class, 'getMarks']); + Route::get('getFAQCategory', [MobileApiController::class, 'getFAQCategory']); + Route::get('getFAQSubCategory', [MobileApiController::class, 'getFAQSubCategory']); + Route::get('getFAQText', [MobileApiController::class, 'getFAQText']); Route::get('getAddress', [MobileApiController::class, 'getAddress']); Route::get('getAvailableMarksList', [MobileApiController::class, 'getAvailableMarksList']); Route::post('checkAvailableCar', [MobileApiController::class, 'checkAvailableCar']);