From 5a7c805978ba9d7a16d7f5e53ec131fceb6c4e28 Mon Sep 17 00:00:00 2001 From: Rustem Date: Thu, 30 Jan 2025 00:13:59 +0500 Subject: [PATCH] api, application, fix --- app/Console/PipiCarInstallCommands.php | 3 +- app/Http/Controllers/MobileApiController.php | 48 +- .../applications/Enum/ApplicationStatus.php | 10 + modules/applications/migrate.php | 13 +- modules/applications/script.php | 15 +- modules/auto/script.php | 2 +- modules/auto_tariffs/script.php | 11 + modules/auto_tariffs/seeds/seed.json | 444 ++++++++++++++++++ modules/brand_models/app.json | 37 +- modules/owner_contracts/script.php | 2 +- modules/owners/script.php | 2 +- routes/api.php | 2 + 12 files changed, 550 insertions(+), 39 deletions(-) create mode 100644 modules/applications/Enum/ApplicationStatus.php create mode 100644 modules/auto_tariffs/seeds/seed.json diff --git a/app/Console/PipiCarInstallCommands.php b/app/Console/PipiCarInstallCommands.php index 4d1fe26..46f7683 100644 --- a/app/Console/PipiCarInstallCommands.php +++ b/app/Console/PipiCarInstallCommands.php @@ -32,7 +32,8 @@ class PipiCarInstallCommands extends InstallCommand 'auto_tariffs', // Тарифы авто 'owner_contracts', // Договор Владельца 'owners', // Владелец авто - 'auto' // авто + 'auto', // авто + 'applications', //Заявки ]; } diff --git a/app/Http/Controllers/MobileApiController.php b/app/Http/Controllers/MobileApiController.php index 1104e34..461a34e 100644 --- a/app/Http/Controllers/MobileApiController.php +++ b/app/Http/Controllers/MobileApiController.php @@ -4,8 +4,11 @@ namespace App\Http\Controllers; use A7kz\Platform\Models\UniModel; use A7kz\Platform\Modules\Platform\Segment\Facades\Segment; +use App\Modules\applications\Enum\ApplicationStatus; use Exception; +use Illuminate\Http\JsonResponse; use Illuminate\Http\Request; +use Illuminate\Support\Carbon; use Illuminate\Support\Facades\DB; use Illuminate\Support\Facades\Log; use Illuminate\Support\Facades\Notification; @@ -14,7 +17,7 @@ use Mpdf\Tag\Mark; class MobileApiController extends Controller { - public function getMarks() { + public function getMarks(): JsonResponse { $data = []; $marks = UniModel::model('pipi_brand_models')->get(); if (!isset($marks)) { @@ -24,13 +27,52 @@ class MobileApiController extends Controller $brand = UniModel::model('pipi_auto_brands')->find($mark->brand_id); $tariffs = UniModel::model('pipi_auto_tariffs')->where('model_id', $mark->id)->first(); if ($mark->name != 'Ввод остатков') { - $data[$mark->name] = [ + $tariffs = [ + 'name' => $tariffs?->name, + 'price' => $tariffs?->base_rate, + 'min' => $tariffs?->day_range_start, + 'max' => $tariffs?->day_range_end, + ]; + $data[$mark->name . '-' . $mark->year] = [ + 'id' => $mark->id, 'brand' => $brand->name, 'mark' => $mark->name, - 'tariffs' => $tariffs?->toArray() + 'year' => $mark->year, + 'tariffs' => $tariffs ]; } } return response()->json($data); } + + public function sendApplication(Request $request): JsonResponse { + $data = $request->all(); + $data['started_at'] = Carbon::parse($data['started_at'])?->format('Y-m-d H:i:s'); + $data['ended_at'] = Carbon::parse($data['ended_at'])?->format('Y-m-d H:i:s'); + $data['user_id'] = UniModel::model('core_users') + ->where('email',$data['email'])->first()?->id; + $data['car_id'] = null; + UniModel::model('pipi_applications')->create([ + 'rent_day' => $data['rent_day'], + 'started_at' => $data['started_at'], + 'ended_at' => $data['ended_at'], + 'user_id' => $data['user_id'], + 'phone' => $data['phone'], + 'car_id' => $data['car_id'], + 'user_name' => $data['name'] ?? null, + 'user_surname' => $data['surname'] ?? null, + 'user_email' => $data['email'] ?? null, + 'status' => ApplicationStatus::pending->value + ]); + + if (!isset($data['user_id'])) { + return response()->json(['status' => 'OK', 'message' => 'Заявка создана, с вами свяжется наш оператор']); + } + return response()->json(['status' => 'OK', 'message' => 'Заявка создана']); + } + + public function getApplications(): JsonResponse + { + return response()->json(UniModel::model('pipi_applications')->get()); + } } diff --git a/modules/applications/Enum/ApplicationStatus.php b/modules/applications/Enum/ApplicationStatus.php new file mode 100644 index 0000000..9be9869 --- /dev/null +++ b/modules/applications/Enum/ApplicationStatus.php @@ -0,0 +1,10 @@ +connector)->create('pipi_auto_colors', static function (Blueprint $table) { + Schema::connection($segment->connector)->create('pipi_applications', static function (Blueprint $table) { $table->id(); - $table->string('name')->nullable()->comment('Наименование'); + $table->unsignedBigInteger('car_id')->nullable(); + $table->unsignedBigInteger('user_id')->nullable(); + $table->integer('rent_day')->nullable(); + $table->string('phone')->nullable(); + $table->dateTime('started_at')->nullable(); + $table->dateTime('ended_at')->nullable(); + $table->string('status')->nullable(); + $table->string('user_name')->nullable(); + $table->string('user_surname')->nullable(); + $table->string('user_email')->nullable(); $table->timestamps(); $table->softDeletes(); }); diff --git a/modules/applications/script.php b/modules/applications/script.php index 57ce277..06d2b8c 100644 --- a/modules/applications/script.php +++ b/modules/applications/script.php @@ -25,10 +25,19 @@ return new class extends \A7kz\Platform\Commands\InstallScript { { $segments = Segment::listActive(); foreach ($segments as $segment) { - if (!Schema::connection($segment->connector)->hasTable('pipi_auto_colors')) { - Schema::connection($segment->connector)->create('pipi_auto_colors', static function (Blueprint $table) { + if (!Schema::connection($segment->connector)->hasTable('pipi_applications')) { + Schema::connection($segment->connector)->create('pipi_applications', static function (Blueprint $table) { $table->id(); - $table->string('name')->nullable()->comment('Наименование'); + $table->unsignedBigInteger('car_id')->nullable(); + $table->unsignedBigInteger('user_id')->nullable(); + $table->integer('rent_day')->nullable(); + $table->string('phone')->nullable(); + $table->dateTime('started_at')->nullable(); + $table->dateTime('ended_at')->nullable(); + $table->string('status')->nullable(); + $table->string('user_name')->nullable(); + $table->string('user_surname')->nullable(); + $table->string('user_email')->nullable(); $table->timestamps(); $table->softDeletes(); }); diff --git a/modules/auto/script.php b/modules/auto/script.php index 2ef7794..c5b75fe 100644 --- a/modules/auto/script.php +++ b/modules/auto/script.php @@ -25,7 +25,7 @@ return new class extends \A7kz\Platform\Commands\InstallScript { #[NoReturn] private function seed(): void { - $seed = Storage::disk('pipicar_crm')->get('auto/seeds/seed.json'); + $seed = Storage::disk('pipicar_crm')->get('auto/seeds/seeds.json'); if (str_starts_with($seed, "\xef\xbb\xbf")) { $seed = substr($seed, 3); // Удаляем первые 3 байта diff --git a/modules/auto_tariffs/script.php b/modules/auto_tariffs/script.php index a675784..b666b6d 100644 --- a/modules/auto_tariffs/script.php +++ b/modules/auto_tariffs/script.php @@ -19,6 +19,7 @@ return new class extends \A7kz\Platform\Commands\InstallScript { public function update($module_name, $module_version): void { $this->upgrade(); + $this->seed(); } private function upgrade(): void @@ -43,4 +44,14 @@ return new class extends \A7kz\Platform\Commands\InstallScript { } } } + + private function seed() + { + $seed = Storage::disk('pipicar_crm')->get('auto_tariffs/seeds/seed.json'); + + $data = json_decode($seed, true); + foreach ($data as $item) { + dd(str_contains($item)); + } + } }; diff --git a/modules/auto_tariffs/seeds/seed.json b/modules/auto_tariffs/seeds/seed.json new file mode 100644 index 0000000..41fa2d8 --- /dev/null +++ b/modules/auto_tariffs/seeds/seed.json @@ -0,0 +1,444 @@ +[ + { + "model": "Huyndai Accent", + "manufacture_year": 2015, + "rental_periods": [ + { + "min_days": 1, + "max_days": 2, + "rate_may_oct": 14000, + "rate_nov_apr": 14000, + "deposit": 30000 + }, + { + "min_days": 3, + "max_days": 5, + "rate_may_oct": 13000, + "rate_nov_apr": 13000, + "deposit": 30000 + }, + { + "min_days": 6, + "max_days": 15, + "rate_may_oct": 11000, + "rate_nov_apr": 12000, + "deposit": 30000 + }, + { + "min_days": 15, + "max_days": 30, + "rate_may_oct": 10000, + "rate_nov_apr": 11000, + "deposit": 30000 + } + ] + }, + { + "model": "KIA RIO", + "manufacture_year": 2015, + "rental_periods": [ + { + "min_days": 1, + "max_days": 2, + "rate_may_oct": 14000, + "rate_nov_apr": 14000, + "deposit": 30000 + }, + { + "min_days": 3, + "max_days": 5, + "rate_may_oct": 13000, + "rate_nov_apr": 13000, + "deposit": 30000 + }, + { + "min_days": 6, + "max_days": 15, + "rate_may_oct": 12000, + "rate_nov_apr": 12000, + "deposit": 30000 + }, + { + "min_days": 15, + "max_days": 30, + "rate_may_oct": 11000, + "rate_nov_apr": 11000, + "deposit": 30000 + } + ] + }, + { + "model": "Huyndai Accent", + "manufacture_year": "2017 - 2019", + "rental_periods": [ + { + "min_days": 1, + "max_days": 2, + "rate_may_oct": 16000, + "rate_nov_apr": 15000, + "deposit": 30000 + }, + { + "min_days": 3, + "max_days": 5, + "rate_may_oct": 15000, + "rate_nov_apr": 13000, + "deposit": 30000 + }, + { + "min_days": 6, + "max_days": 15, + "rate_may_oct": 14000, + "rate_nov_apr": 12000, + "deposit": 30000 + }, + { + "min_days": 15, + "max_days": 30, + "rate_may_oct": 13000, + "rate_nov_apr": 10000, + "deposit": 30000 + } + ] + }, + { + "model": "Toyota Camry 50", + "manufacture_year": 2014, + "rental_periods": [ + { + "min_days": 1, + "max_days": 2, + "rate_may_oct": 20000, + "rate_nov_apr": 21000, + "deposit": 50000 + }, + { + "min_days": 3, + "max_days": 5, + "rate_may_oct": 18000, + "rate_nov_apr": 19000, + "deposit": 50000 + }, + { + "min_days": 6, + "max_days": 15, + "rate_may_oct": 16000, + "rate_nov_apr": 17000, + "deposit": 50000 + }, + { + "min_days": 15, + "max_days": 30, + "rate_may_oct": 15000, + "rate_nov_apr": 16000, + "deposit": 50000 + } + ] + }, + { + "model": "Toyota Camry 55", + "manufacture_year": 2016, + "rental_periods": [ + { + "min_days": 1, + "max_days": 2, + "rate_may_oct": 22000, + "rate_nov_apr": 20000, + "deposit": 50000 + }, + { + "min_days": 3, + "max_days": 5, + "rate_may_oct": 20000, + "rate_nov_apr": 18000, + "deposit": 50000 + }, + { + "min_days": 6, + "max_days": 15, + "rate_may_oct": 18000, + "rate_nov_apr": 16000, + "deposit": 50000 + }, + { + "min_days": 15, + "max_days": 30, + "rate_may_oct": 17000, + "rate_nov_apr": 15000, + "deposit": 50000 + } + ] + }, + { + "model": "Huyndai Accent", + "manufacture_year": 2021, + "rental_periods": [ + { + "min_days": 1, + "max_days": 2, + "rate_may_oct": 17000, + "rate_nov_apr": 16000, + "deposit": 30000 + }, + { + "min_days": 3, + "max_days": 5, + "rate_may_oct": 16000, + "rate_nov_apr": 14000, + "deposit": 30000 + }, + { + "min_days": 6, + "max_days": 15, + "rate_may_oct": 15000, + "rate_nov_apr": 13000, + "deposit": 30000 + }, + { + "min_days": 15, + "max_days": 30, + "rate_may_oct": 14000, + "rate_nov_apr": 12000, + "deposit": 30000 + } + ] + }, + { + "model": "Huyndai Accent", + "manufacture_year": 2023, + "rental_periods": [ + { + "min_days": 1, + "max_days": 2, + "rate_may_oct": 18000, + "rate_nov_apr": 18000, + "deposit": 40000 + }, + { + "min_days": 3, + "max_days": 5, + "rate_may_oct": 17000, + "rate_nov_apr": 16000, + "deposit": 40000 + }, + { + "min_days": 6, + "max_days": 15, + "rate_may_oct": 16000, + "rate_nov_apr": 14000, + "deposit": 40000 + }, + { + "min_days": 15, + "max_days": 30, + "rate_may_oct": 15000, + "rate_nov_apr": 13000, + "deposit": 40000 + } + ] + }, + { + "model": "Huyndai Elantra", + "manufacture_year": 2021, + "rental_periods": [ + { + "min_days": 1, + "max_days": 2, + "rate_may_oct": 21000, + "rate_nov_apr": 20000, + "deposit": 50000 + }, + { + "min_days": 3, + "max_days": 5, + "rate_may_oct": 19000, + "rate_nov_apr": 18000, + "deposit": 50000 + }, + { + "min_days": 6, + "max_days": 15, + "rate_may_oct": 17000, + "rate_nov_apr": 17000, + "deposit": 50000 + }, + { + "min_days": 15, + "max_days": 30, + "rate_may_oct": 16000, + "rate_nov_apr": 16000, + "deposit": 50000 + } + ] + }, + { + "model": "Huyndai Elantra", + "manufacture_year": "2022 - 2023", + "rental_periods": [ + { + "min_days": 1, + "max_days": 2, + "rate_may_oct": 22000, + "rate_nov_apr": 21000, + "deposit": 50000 + }, + { + "min_days": 3, + "max_days": 5, + "rate_may_oct": 20000, + "rate_nov_apr": 20000, + "deposit": 50000 + }, + { + "min_days": 6, + "max_days": 15, + "rate_may_oct": 18000, + "rate_nov_apr": 18000, + "deposit": 50000 + }, + { + "min_days": 15, + "max_days": 30, + "rate_may_oct": 17000, + "rate_nov_apr": 17000, + "deposit": 50000 + } + ] + }, + { + "model": "Huyndai Elantra", + "manufacture_year": 2024, + "rental_periods": [ + { + "min_days": 1, + "max_days": 2, + "rate_may_oct": 24000, + "rate_nov_apr": 21000, + "deposit": 50000 + }, + { + "min_days": 3, + "max_days": 5, + "rate_may_oct": 22000, + "rate_nov_apr": 20000, + "deposit": 50000 + }, + { + "min_days": 6, + "max_days": 15, + "rate_may_oct": 20000, + "rate_nov_apr": 18000, + "deposit": 50000 + }, + { + "min_days": 15, + "max_days": 30, + "rate_may_oct": 18000, + "rate_nov_apr": 17000, + "deposit": 50000 + } + ] + }, + { + "model": "Huyndai Sonata", + "manufacture_year": "2022 - 2023", + "rental_periods": [ + { + "min_days": 1, + "max_days": 2, + "rate_may_oct": 30000, + "rate_nov_apr": 30000, + "deposit": 50000 + }, + { + "min_days": 3, + "max_days": 5, + "rate_may_oct": 28000, + "rate_nov_apr": 28000, + "deposit": 50000 + }, + { + "min_days": 6, + "max_days": 15, + "rate_may_oct": 26000, + "rate_nov_apr": 26000, + "deposit": 50000 + }, + { + "min_days": 15, + "max_days": 30, + "rate_may_oct": 24000, + "rate_nov_apr": 24000, + "deposit": 50000 + } + ] + }, + { + "model": "Huyndai Tucson", + "manufacture_year": "2023 - 2024", + "rental_periods": [ + { + "min_days": 1, + "max_days": 2, + "rate_may_oct": 32000, + "rate_nov_apr": 32000, + "deposit": 60000 + }, + { + "min_days": 3, + "max_days": 5, + "rate_may_oct": 30000, + "rate_nov_apr": 30000, + "deposit": 60000 + }, + { + "min_days": 6, + "max_days": 15, + "rate_may_oct": 27000, + "rate_nov_apr": 27000, + "deposit": 60000 + }, + { + "min_days": 15, + "max_days": 30, + "rate_may_oct": 26000, + "rate_nov_apr": 25000, + "deposit": 60000 + } + ] + }, + { + "model": "KIA K5", + "manufacture_year": 2021, + "rental_periods": [ + { + "min_days": 1, + "max_days": 2, + "rate_may_oct": 30000, + "rate_nov_apr": 28000, + "deposit": 50000 + }, + { + "min_days": 3, + "max_days": 5, + "rate_may_oct": 28000, + "rate_nov_apr": 26000, + "deposit": 50000 + }, + { + "min_days": 6, + "max_days": 15, + "rate_may_oct": 26000, + "rate_nov_apr": 24000, + "deposit": 50000 + }, + { + "min_days": 15, + "max_days": 30, + "rate_may_oct": 24000, + "rate_nov_apr": 23000, + "deposit": 50000 + } + ] + } +] diff --git a/modules/brand_models/app.json b/modules/brand_models/app.json index 5534d0a..20a4b45 100644 --- a/modules/brand_models/app.json +++ b/modules/brand_models/app.json @@ -47,7 +47,8 @@ "type": "string" }, "type": { - "type": "string" + "type": "string", + "default": "dynamic" }, "day_range_start": { "type": "int" @@ -75,10 +76,6 @@ "name": "name", "caption": "Название" }, - { - "name": "type", - "caption": "Тип" - }, { "name": "base_rate", "caption": "Цена" @@ -111,15 +108,15 @@ { "size": 4, "input": { - "name": "type", - "label": "Тип тарифа" + "name": "base_rate", + "label": "Базовая стоймость" } }, { "size": 4, "input": { - "name": "base_rate", - "label": "Базовая стоймость" + "name": "deposit", + "label": "Депозит" } } ] @@ -139,13 +136,6 @@ "name": "day_range_end", "label": "до скольки дней" } - }, - { - "size": 4, - "input": { - "name": "deposit", - "label": "Депозит" - } } ] } @@ -169,15 +159,15 @@ { "size": 4, "input": { - "name": "type", - "label": "Тип тарифа" + "name": "base_rate", + "label": "Базовая стоймость" } }, { "size": 4, "input": { - "name": "base_rate", - "label": "Базовая стоймость" + "name": "deposit", + "label": "Депозит" } } ] @@ -197,13 +187,6 @@ "name": "day_range_end", "label": "до скольки дней" } - }, - { - "size": 4, - "input": { - "name": "deposit", - "label": "Депозит" - } } ] } diff --git a/modules/owner_contracts/script.php b/modules/owner_contracts/script.php index b029e64..7351916 100644 --- a/modules/owner_contracts/script.php +++ b/modules/owner_contracts/script.php @@ -53,7 +53,7 @@ return new class extends \A7kz\Platform\Commands\InstallScript { #[NoReturn] private function seed(): void { - $seed = Storage::disk('pipicar_crm')->get('owner_contracts/seeds/seed.json'); + $seed = Storage::disk('pipicar_crm')->get('owner_contracts/seeds/seeds.json'); if (str_starts_with($seed, "\xef\xbb\xbf")) { $seed = substr($seed, 3); // Удаляем первые 3 байта diff --git a/modules/owners/script.php b/modules/owners/script.php index 65a024f..d798c16 100644 --- a/modules/owners/script.php +++ b/modules/owners/script.php @@ -60,7 +60,7 @@ return new class extends \A7kz\Platform\Commands\InstallScript { private function seed(): void { - $seed = Storage::disk('pipicar_crm')->get('owners/seeds/seed.json'); + $seed = Storage::disk('pipicar_crm')->get('owners/seeds/seeds.json'); if (str_starts_with($seed, "\xef\xbb\xbf")) { $seed = substr($seed, 3); // Удаляем первые 3 байта diff --git a/routes/api.php b/routes/api.php index e7baac0..3401bf0 100644 --- a/routes/api.php +++ b/routes/api.php @@ -24,4 +24,6 @@ Route::prefix('1c')->group(function () { Route::prefix('mobile')->group(function () { Route::get('getMarks', [MobileApiController::class, 'getMarks']); + Route::post('sendApplication', [MobileApiController::class, 'sendApplication']); + Route::post('getApplications', [MobileApiController::class, 'getApplications']); });