api, application, fix

pull/3/head
Rustem 2025-01-30 00:13:59 +05:00
parent 18fffad0d9
commit 5a7c805978
12 changed files with 550 additions and 39 deletions

View File

@ -32,7 +32,8 @@ class PipiCarInstallCommands extends InstallCommand
'auto_tariffs', // Тарифы авто 'auto_tariffs', // Тарифы авто
'owner_contracts', // Договор Владельца 'owner_contracts', // Договор Владельца
'owners', // Владелец авто 'owners', // Владелец авто
'auto' // авто 'auto', // авто
'applications', //Заявки
]; ];
} }

View File

@ -4,8 +4,11 @@ namespace App\Http\Controllers;
use A7kz\Platform\Models\UniModel; use A7kz\Platform\Models\UniModel;
use A7kz\Platform\Modules\Platform\Segment\Facades\Segment; use A7kz\Platform\Modules\Platform\Segment\Facades\Segment;
use App\Modules\applications\Enum\ApplicationStatus;
use Exception; use Exception;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request; use Illuminate\Http\Request;
use Illuminate\Support\Carbon;
use Illuminate\Support\Facades\DB; use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Log; use Illuminate\Support\Facades\Log;
use Illuminate\Support\Facades\Notification; use Illuminate\Support\Facades\Notification;
@ -14,7 +17,7 @@ use Mpdf\Tag\Mark;
class MobileApiController extends Controller class MobileApiController extends Controller
{ {
public function getMarks() { public function getMarks(): JsonResponse {
$data = []; $data = [];
$marks = UniModel::model('pipi_brand_models')->get(); $marks = UniModel::model('pipi_brand_models')->get();
if (!isset($marks)) { if (!isset($marks)) {
@ -24,13 +27,52 @@ class MobileApiController extends Controller
$brand = UniModel::model('pipi_auto_brands')->find($mark->brand_id); $brand = UniModel::model('pipi_auto_brands')->find($mark->brand_id);
$tariffs = UniModel::model('pipi_auto_tariffs')->where('model_id', $mark->id)->first(); $tariffs = UniModel::model('pipi_auto_tariffs')->where('model_id', $mark->id)->first();
if ($mark->name != 'Ввод остатков') { 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, 'brand' => $brand->name,
'mark' => $mark->name, 'mark' => $mark->name,
'tariffs' => $tariffs?->toArray() 'year' => $mark->year,
'tariffs' => $tariffs
]; ];
} }
} }
return response()->json($data); 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());
}
} }

View File

@ -0,0 +1,10 @@
<?php
namespace App\Modules\applications\Enum;
enum ApplicationStatus: string
{
case pending = 'pending';
case approved = 'approved';
case rejected = 'rejected';
}

View File

@ -12,9 +12,18 @@ return new class extends Migration
{ {
$segments = Segment::listActive(); $segments = Segment::listActive();
foreach ($segments as $segment) { foreach ($segments as $segment) {
Schema::connection($segment->connector)->create('pipi_auto_colors', static function (Blueprint $table) { Schema::connection($segment->connector)->create('pipi_applications', static function (Blueprint $table) {
$table->id(); $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->timestamps();
$table->softDeletes(); $table->softDeletes();
}); });

View File

@ -25,10 +25,19 @@ return new class extends \A7kz\Platform\Commands\InstallScript {
{ {
$segments = Segment::listActive(); $segments = Segment::listActive();
foreach ($segments as $segment) { foreach ($segments as $segment) {
if (!Schema::connection($segment->connector)->hasTable('pipi_auto_colors')) { if (!Schema::connection($segment->connector)->hasTable('pipi_applications')) {
Schema::connection($segment->connector)->create('pipi_auto_colors', static function (Blueprint $table) { Schema::connection($segment->connector)->create('pipi_applications', static function (Blueprint $table) {
$table->id(); $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->timestamps();
$table->softDeletes(); $table->softDeletes();
}); });

View File

@ -25,7 +25,7 @@ return new class extends \A7kz\Platform\Commands\InstallScript {
#[NoReturn] private function seed(): void #[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")) { if (str_starts_with($seed, "\xef\xbb\xbf")) {
$seed = substr($seed, 3); // Удаляем первые 3 байта $seed = substr($seed, 3); // Удаляем первые 3 байта

View File

@ -19,6 +19,7 @@ return new class extends \A7kz\Platform\Commands\InstallScript {
public function update($module_name, $module_version): void public function update($module_name, $module_version): void
{ {
$this->upgrade(); $this->upgrade();
$this->seed();
} }
private function upgrade(): void 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));
}
}
}; };

View File

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

View File

@ -47,7 +47,8 @@
"type": "string" "type": "string"
}, },
"type": { "type": {
"type": "string" "type": "string",
"default": "dynamic"
}, },
"day_range_start": { "day_range_start": {
"type": "int" "type": "int"
@ -75,10 +76,6 @@
"name": "name", "name": "name",
"caption": "Название" "caption": "Название"
}, },
{
"name": "type",
"caption": "Тип"
},
{ {
"name": "base_rate", "name": "base_rate",
"caption": "Цена" "caption": "Цена"
@ -111,15 +108,15 @@
{ {
"size": 4, "size": 4,
"input": { "input": {
"name": "type", "name": "base_rate",
"label": "Тип тарифа" "label": "Базовая стоймость"
} }
}, },
{ {
"size": 4, "size": 4,
"input": { "input": {
"name": "base_rate", "name": "deposit",
"label": "Базовая стоймость" "label": "Депозит"
} }
} }
] ]
@ -139,13 +136,6 @@
"name": "day_range_end", "name": "day_range_end",
"label": "до скольки дней" "label": "до скольки дней"
} }
},
{
"size": 4,
"input": {
"name": "deposit",
"label": "Депозит"
}
} }
] ]
} }
@ -169,15 +159,15 @@
{ {
"size": 4, "size": 4,
"input": { "input": {
"name": "type", "name": "base_rate",
"label": "Тип тарифа" "label": "Базовая стоймость"
} }
}, },
{ {
"size": 4, "size": 4,
"input": { "input": {
"name": "base_rate", "name": "deposit",
"label": "Базовая стоймость" "label": "Депозит"
} }
} }
] ]
@ -197,13 +187,6 @@
"name": "day_range_end", "name": "day_range_end",
"label": "до скольки дней" "label": "до скольки дней"
} }
},
{
"size": 4,
"input": {
"name": "deposit",
"label": "Депозит"
}
} }
] ]
} }

View File

@ -53,7 +53,7 @@ return new class extends \A7kz\Platform\Commands\InstallScript {
#[NoReturn] private function seed(): void #[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")) { if (str_starts_with($seed, "\xef\xbb\xbf")) {
$seed = substr($seed, 3); // Удаляем первые 3 байта $seed = substr($seed, 3); // Удаляем первые 3 байта

View File

@ -60,7 +60,7 @@ return new class extends \A7kz\Platform\Commands\InstallScript {
private function seed(): void 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")) { if (str_starts_with($seed, "\xef\xbb\xbf")) {
$seed = substr($seed, 3); // Удаляем первые 3 байта $seed = substr($seed, 3); // Удаляем первые 3 байта

View File

@ -24,4 +24,6 @@ Route::prefix('1c')->group(function () {
Route::prefix('mobile')->group(function () { Route::prefix('mobile')->group(function () {
Route::get('getMarks', [MobileApiController::class, 'getMarks']); Route::get('getMarks', [MobileApiController::class, 'getMarks']);
Route::post('sendApplication', [MobileApiController::class, 'sendApplication']);
Route::post('getApplications', [MobileApiController::class, 'getApplications']);
}); });