diff --git a/app/Http/Controllers/MobileApiController.php b/app/Http/Controllers/MobileApiController.php index 461a34e..c5df13a 100644 --- a/app/Http/Controllers/MobileApiController.php +++ b/app/Http/Controllers/MobileApiController.php @@ -25,20 +25,22 @@ class MobileApiController extends Controller } foreach ($marks as $mark) { $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)->get(); if ($mark->name != 'Ввод остатков') { - $tariffs = [ - 'name' => $tariffs?->name, - 'price' => $tariffs?->base_rate, - 'min' => $tariffs?->day_range_start, - 'max' => $tariffs?->day_range_end, - ]; + foreach ($tariffs as $tariff) { + $tariffs_new[$tariff?->day_range_start . '-' . $tariff->day_range_end] = [ + 'name' => $tariff?->name, + 'price' => $tariff?->base_rate, + 'min' => $tariff?->day_range_start, + 'max' => $tariff?->day_range_end, + ]; + } $data[$mark->name . '-' . $mark->year] = [ 'id' => $mark->id, 'brand' => $brand->name, 'mark' => $mark->name, 'year' => $mark->year, - 'tariffs' => $tariffs + 'tariffs' => $tariffs_new ]; } } diff --git a/modules/auto_tariffs/script.php b/modules/auto_tariffs/script.php index 1861c55..51669f4 100644 --- a/modules/auto_tariffs/script.php +++ b/modules/auto_tariffs/script.php @@ -47,8 +47,33 @@ return new class extends \A7kz\Platform\Commands\InstallScript { private function seed() { - $seed = Storage::disk('pipicar_crm')->get('auto_tariffs/seeds/seed.json'); + $count = UniModel::model('pipi_auto_tariffs')->count(); + if ($count === 0) { + $seed = Storage::disk('pipicar_crm')->get('auto_tariffs/seeds/seed.json'); - $data = json_decode($seed, true); + $data = json_decode($seed, true); + foreach ($data as $item) { + $models = explode(' ', $item['model']); + if (isset($models[1])) { + $model = $models[1]; + if (isset($models[2])) { + $model = $models[1] . ' ' . $models[2]; + } + } + + foreach ($item['rental_periods'] as $rental) { + UniModel::model('pipi_auto_tariffs')->create([ + 'name' => $item['model'] . '-' . $item['manufacture_year'] . ' ' . $rental['min_days'] . '-' . $rental['max_days'], + 'type' => 'dynamic', + 'day_range_start' => $rental['min_days'], + 'day_range_end' => $rental['max_days'], + 'base_rate' => $rental['rate_may_oct'], + 'deposit' => $rental['deposit'], + 'model_id' => UniModel::model('pipi_brand_models') + ->where('name', $model)->where('year', $item['manufacture_year'])->first()?->id, + ]); + } + } + } } }; diff --git a/modules/auto_tariffs/seeds/seed.json b/modules/auto_tariffs/seeds/seed.json index 41fa2d8..2d27c21 100644 --- a/modules/auto_tariffs/seeds/seed.json +++ b/modules/auto_tariffs/seeds/seed.json @@ -69,7 +69,75 @@ }, { "model": "Huyndai Accent", - "manufacture_year": "2017 - 2019", + "manufacture_year": 2017, + "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": "Huyndai Accent", + "manufacture_year": 2018, + "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": "Huyndai Accent", + "manufacture_year": 2019, "rental_periods": [ { "min_days": 1, @@ -273,7 +341,41 @@ }, { "model": "Huyndai Elantra", - "manufacture_year": "2022 - 2023", + "manufacture_year": 2022, + "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": 2023, "rental_periods": [ { "min_days": 1, @@ -341,7 +443,41 @@ }, { "model": "Huyndai Sonata", - "manufacture_year": "2022 - 2023", + "manufacture_year": 2022, + "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 Sonata", + "manufacture_year": 2023, "rental_periods": [ { "min_days": 1, @@ -375,7 +511,41 @@ }, { "model": "Huyndai Tucson", - "manufacture_year": "2023 - 2024", + "manufacture_year": 2023, + "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": "Huyndai Tucson", + "manufacture_year": 2024, "rental_periods": [ { "min_days": 1,