From 6ad0fe85e64477f9eeed64afb8a764c7a5dd6254 Mon Sep 17 00:00:00 2001 From: Rustem Date: Sun, 10 Aug 2025 00:06:01 +0500 Subject: [PATCH] new --- app/Http/Controllers/MobileApiController.php | 12 +- modules/main/Components/Main.php | 155 ++++++++++++++-- modules/main/access.json | 30 ++-- modules/main/views/main.blade.php | 178 +++++++++++++++---- 4 files changed, 304 insertions(+), 71 deletions(-) diff --git a/app/Http/Controllers/MobileApiController.php b/app/Http/Controllers/MobileApiController.php index 2f73f6f..4b47123 100644 --- a/app/Http/Controllers/MobileApiController.php +++ b/app/Http/Controllers/MobileApiController.php @@ -242,12 +242,14 @@ class MobileApiController extends Controller } } - public function checkAvailableCar($started_at = null, $ended_at = null, $modelId = null, $color = null): bool { - if (!$started_at || !$ended_at || !$modelId) { + public function checkAvailableCar($started_at = null, $ended_at = null, $modelId = null, $color = null): bool|JsonResponse + { + if (!$started_at || !$ended_at || !$modelId || !$color) { $request = request(); $started_at = $started_at ?? $request->input('started_at'); $ended_at = $ended_at ?? $request->input('ended_at'); $modelId = $modelId ?? $request->input('model_id'); + $color = Unimodel::model('pipi_auto_colors')->where('code', $request->input('color'))->first()->id; } if (!$started_at || !$ended_at || !$modelId) { @@ -259,7 +261,7 @@ class MobileApiController extends Controller $cars = UniModel::model('pipi_auto') ->where('is_inactive', '=', false) ->where('model_id', $modelId) - ->where('color_id', $color->id) + ->where('color_id', $color) ->get(); $busyCars = UniModel::model('pipi_auto_calendar') ->whereBetween('date', [$started_at, $ended_at]) @@ -268,7 +270,7 @@ class MobileApiController extends Controller $availableCars = $cars->reject(fn($car) => in_array($car->id, $busyCars)); - return $availableCars->isNotEmpty(); + return response()->json($availableCars->isNotEmpty()); } public function getAvailableMarksList(Request $request): JsonResponse @@ -341,7 +343,7 @@ class MobileApiController extends Controller $colorPath = url('api/files/file/' . ltrim($photo->path, '/')); } - if (!$this->checkAvailableCar($started_at, $ended_at, $mark->id, $carColor)) { + if (!$this->checkAvailableCar($started_at, $ended_at, $mark->id, $carColor->code)) { continue; } diff --git a/modules/main/Components/Main.php b/modules/main/Components/Main.php index 7ddc931..2015e8d 100644 --- a/modules/main/Components/Main.php +++ b/modules/main/Components/Main.php @@ -9,6 +9,7 @@ namespace App\Modules\main\Components; +use A7kz\Platform\Models\UniModel; use A7kz\Platform\Modules\Platform\Core\Services\Base\Component; use Illuminate\Support\Facades\Request; use Illuminate\Support\Carbon; @@ -21,21 +22,11 @@ class Main extends Component parent::__construct($params, $module); $this->template = 'pipicar::main.views.main'; - $class_filters = Request::input('class_filters') ?? null; - $started_at = Request::input('started_at') ?? null; - $ended_at = Request::input('ended_at') ?? null; - $bodywork_filters = Request::input('bodywork_filters') ?? null; + $request = request(); - $request = new \Illuminate\Http\Request([ - 'started_at' => $started_at ?? Carbon::now()->toDateString(), - 'ended_at' => $ended_at ?? Carbon::now()->addDays(3)->toDateString(), - 'class' => $class_filters ?? null, - 'bodywork' => $bodywork_filters ?? null, - ]); + $response = $this->getAuto($request); - $response = (new \App\Http\Controllers\MobileApiController)->getAvailableMarksList($request); - - $this->params['cars'] = collect($response->getData(true))->filter(function ($item) { + $this->params['cars'] = collect($response)->filter(function ($item) { return !empty($item['tariffs']); })->values(); @@ -50,4 +41,142 @@ class Main extends Component // return !empty($item['tariffs']); // })->values(); } + + private function getAuto($request) + { + $started_at = $request->query('started_at'); + $ended_at = $request->query('ended_at'); + $class = $request->query('class'); + $bodywork = $request->query('bodywork'); + + $marks = UniModel::model('pipi_brand_models')->get(); + + $availableMarks = []; + + if ($class) { + $class_id = UniModel::model('pipi_auto_classes')->where('name', $class)->first()?->id; + $marks = $marks->where('class_id', $class_id); + } + if ($bodywork) { + $bodywork_id = UniModel::model('pipi_auto_bodywork')->where('name', $bodywork)->first()?->id; + $marks = $marks->where('bodywork_id', $bodywork_id); + } + + foreach ($marks as $mark) { + if ($mark->name === 'Ввод остатков') { + continue; + } + + $tariffs = UniModel::model('pipi_auto_tariffs')->where('model_id', $mark->id)->get(); + if ($tariffs->isEmpty()) { + continue; + } + + $cars = UniModel::model('pipi_auto')->where('model_id', $mark->id)->get(); + + + if ($cars->isEmpty()) { + continue; + } + + $brand = UniModel::model('pipi_auto_brands')->find($mark->brand_id); + $tariffs = UniModel::model('pipi_auto_tariffs')->where('model_id', $mark->id)->get(); + $equipment = UniModel::model('pipi_auto_equipment')->where('id', $mark->equipment_id)->first(); + $class = UniModel::model('pipi_auto_classes')->find($mark->class_id); + $bodywork = UniModel::model('pipi_auto_bodywork')->find($mark->bodywork_id); + $photo = UniModel::model('core_files')->find($mark?->photo_id); + + $path = null; + if ($photo) { + $path = url('api/files/file/' . ltrim($photo->path, '/')); + } + + $tariffs_new = []; + foreach ($tariffs as $tariff) { + $tariffs_new[] = [ + 'name' => $tariff?->name, + 'price' => $tariff?->base_rate, + 'min' => $tariff?->day_range_start, + 'max' => $tariff?->day_range_end, + 'deposit' => $tariff?->deposit, + ]; + } + $carsByColor = $cars->groupBy('color_id'); + + foreach ($carsByColor as $carColor => $carsOfColor) { + $carColor = UniModel::model('pipi_auto_colors')->find($carColor); + + $colorPath = $path; + if ($carsOfColor->first()->photo_id) { + $photo = UniModel::model('core_files')->find($carsOfColor->first()->photo_id); + $colorPath = url('api/files/file/' . ltrim($photo->path, '/')); + } + + $key = $mark->name . '-' . $mark->year . '-' . $carColor->code; + + $availableMarks[$key] = [ + 'id' => $mark->id, + 'brand' => $brand?->name, + 'mark' => $mark->name, + 'year' => $mark->year, + 'color' => $carColor->code, + 'configuration' => $equipment?->name, + 'people' => $mark?->people ?? '5', + 'actuator' => $mark?->actuator ?? 'Передний', + 'fuel_type' => $mark?->fuel_type ?? 'АКПП', + 'hp' => $mark?->hp ?? '1.6', + 'engine_capacity' => $mark?->engine_capacity ?? '1591', + 'fuel_tank' => $mark?->fuel_tank ?? '50', + 'class' => $class->name ?? 'Эконом', + 'bodywork' => $bodywork->name ?? 'Седан', + 'deposit' => $tariffs_new[0]['deposit'] ?? 30000, + 'conditioner' => $mark?->conditioner, + 'photo' => $colorPath, + 'free' => $this->checkAvailableCar($started_at, $ended_at, $mark->id, $carColor), + 'tariffs' => $tariffs_new, + ]; + } + } + + if (empty($availableMarks)) { + $availableMarks = (object) []; + } + return $availableMarks; + } + + private function checkAvailableCar($started_at = null, $ended_at = null, $modelId = null, $color = null): bool { + if (!$started_at || !$ended_at || !$modelId) { + $request = request(); + $started_at = $started_at ?? $request->input('started_at'); + $ended_at = $ended_at ?? $request->input('ended_at'); + $modelId = $modelId ?? $request->input('model_id'); + } + + if (is_null($started_at) or is_null($ended_at)) { + $started_at = Carbon::now()->format('Y-m-d'); + $ended_at = Carbon::now()->addDays(3)->format('Y-m-d'); + } + + $started_at = Carbon::parse($started_at)->format('Y-m-d'); + $ended_at = Carbon::parse($ended_at)->format('Y-m-d'); + $cars = UniModel::model('pipi_auto') + ->where('is_inactive', '=', false) + ->where('model_id', $modelId) + ->where('color_id', $color->id) + ->get(); + $busyCars = UniModel::model('pipi_auto_calendar') + ->whereBetween('date', [$started_at, $ended_at]) + ->pluck('auto_id') + ->toArray(); + + $availableCars = $cars->reject(fn($car) => in_array($car->id, $busyCars)); + + return $availableCars->isNotEmpty(); + } + + public function action_rent() + { + $request = Request::input(); + dd($request); + } } diff --git a/modules/main/access.json b/modules/main/access.json index 61daa35..1a51f02 100644 --- a/modules/main/access.json +++ b/modules/main/access.json @@ -1,16 +1,18 @@ { - "admin": [ - "default", - "add", - "show", - "edit", - "delete" - ], - "user": [ - "default", - "add", - "show", - "edit", - "delete" - ] + "admin": [ + "default", + "add", + "show", + "edit", + "delete", + "rent" + ], + "user": [ + "default", + "add", + "show", + "edit", + "delete", + "rent" + ] } diff --git a/modules/main/views/main.blade.php b/modules/main/views/main.blade.php index c26a171..2bb8fe1 100644 --- a/modules/main/views/main.blade.php +++ b/modules/main/views/main.blade.php @@ -1,7 +1,10 @@ +@php $request = \Illuminate\Support\Facades\Request::input(); +$address = \A7kz\Platform\Models\UniModel::model('pipi_address')->get(); +@endphp
-

Доступные автомобили

-

Выберите лучший автомобиль

+

@lang('Доступные автомобили')

+

@lang('Выберите лучший автомобиль')

@@ -115,11 +118,10 @@
@php $carsValues = array_values($cars->toArray()); @endphp @foreach($carsValues as $car) -{{-- @dump($car)--}}
Car Image -
{{ $car['brand'] . ' ' . $car['mark'] . ' - ' . $car['year'] }}
+
{{ $car['brand'] . ' ' . $car['mark'] . ' - ' . $car['year']. ' ' . \A7kz\Platform\Models\UniModel::model('pipi_auto_colors')->where('code', $car['color'])->first()?->name }}
ac_unit

 Кондиционер

auto_transmission

 {{ $car['fuel_type'] }}

@@ -140,24 +142,20 @@ @endif

- - @lang('Арендовать') - - + @if($car['free']) + + @lang('Арендовать') + + @else + + @lang('Машина занята выберете другую дату') + + @endif
@@ -173,7 +171,8 @@