From 18fffad0d9c7b1f5cc09baa9c4e2420958ad9e8f Mon Sep 17 00:00:00 2001 From: Rustem Date: Wed, 29 Jan 2025 21:08:43 +0500 Subject: [PATCH] fix --- app/Http/Controllers/MobileApiController.php | 36 ++++++++++ app/Http/Controllers/Sync1cApiController.php | 25 +++---- .../Notifications/TelegramNotification.php | 72 +++++++++++++++++++ modules/auto/script.php | 12 ++-- modules/auto_tariffs/migrate.php | 10 ++- modules/brand_models/app.json | 35 +++++++-- modules/brand_models/script.php | 1 + modules/owner_contracts/script.php | 13 ++-- modules/owners/script.php | 9 ++- routes/api.php | 5 ++ 10 files changed, 182 insertions(+), 36 deletions(-) create mode 100644 app/Http/Controllers/MobileApiController.php create mode 100644 app/Http/Notifications/TelegramNotification.php diff --git a/app/Http/Controllers/MobileApiController.php b/app/Http/Controllers/MobileApiController.php new file mode 100644 index 0000000..1104e34 --- /dev/null +++ b/app/Http/Controllers/MobileApiController.php @@ -0,0 +1,36 @@ +get(); + if (!isset($marks)) { + return response()->json(); + } + 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(); + if ($mark->name != 'Ввод остатков') { + $data[$mark->name] = [ + 'brand' => $brand->name, + 'mark' => $mark->name, + 'tariffs' => $tariffs?->toArray() + ]; + } + } + return response()->json($data); + } +} diff --git a/app/Http/Controllers/Sync1cApiController.php b/app/Http/Controllers/Sync1cApiController.php index cbab4bb..543aaec 100644 --- a/app/Http/Controllers/Sync1cApiController.php +++ b/app/Http/Controllers/Sync1cApiController.php @@ -6,6 +6,7 @@ use A7kz\Platform\Models\UniModel; use A7kz\Platform\Modules\Platform\Segment\Facades\Segment; use Exception; use Illuminate\Http\Request; +use Illuminate\Support\Carbon; use Illuminate\Support\Facades\DB; use Illuminate\Support\Facades\Log; use Illuminate\Support\Facades\Storage; @@ -13,13 +14,12 @@ use Illuminate\Support\Facades\Storage; class Sync1cApiController extends Controller { - private function formatDate($date): ?string + private function formatDate($date): ?Carbon { $date = trim($date); try { - $dateObject = \Carbon\Carbon::createFromFormat('d.m.Y', $date); - return $dateObject->format('Y-m-d'); + return Carbon::parse($date); } catch (\Exception $e) { return null; } @@ -62,14 +62,15 @@ class Sync1cApiController extends Controller 'name' => $value['Модель'], 'brand_id' => UniModel::model('pipi_auto_brands', $segment->connector) ->firstOrCreate(['name' => $value['Марка']])->id, + 'year' => $this->formatDate($value['ГодПроизводства'])?->format('Y'), ])->id, 'color_id' => UniModel::model('pipi_auto_colors', $segment->connector) ->firstOrCreate(['name' => $value['Цвет']])->id, 'serial_number' => $value['СерийныйНомер'], 'state_number' => $value['ГосНомер'], - 'manufacture_year' => $this->formatDate($value['ГодПроизводства']), + 'manufacture_year' => $this->formatDate($value['ГодПроизводства'])?->format('Y-m-d'), 'passport_number' => $value['НомерТехПаспорта'], - 'passport_date' => $this->formatDate($value['ДатаТехпаспорта']), + 'passport_date' => $this->formatDate($value['ДатаТехпаспорта'])?->format('Y-m-d'), 'estimated_cost' => $value['ОценочнаяСтоимость'], 'owner_id' => UniModel::model('pipi_owners', $segment->connector) ->firstOrCreate(['name' => $value['ВладелецИмущества']])->id, @@ -79,7 +80,7 @@ class Sync1cApiController extends Controller 'is_predefined' => (bool)$value['Предопределенный'], 'predefined_data_name' => $value['ИмяПредопределенныхДанных'], 'inspection_kit' => $inspectionKit, - 'deleted_at' => (bool) $value['ПометкаУдаления'] ? now() : null, + 'deleted_at' => $value['ПометкаУдаления'] == 'Да' ? now() : null, ] ); } @@ -126,12 +127,12 @@ class Sync1cApiController extends Controller 'phone' => $value['Телефон'], 'mail' => $value['Почта'], 'id_number' => $value['УдНомер'], - 'id_date' => $this->formatDate($value['УдДата']), + 'id_date' => $this->formatDate($value['УдДата'])?->format('Y-m-d'), 'issued' => $value['УдВыдан'], 'contract_id' => $value['ОсновнойДоговор'] ? UniModel::model('pipi_owner_contracts', $segment->connector)->firstOrCreate([ 'name' => $value['ОсновнойДоговор'] ])->id : null, - 'deleted_at' => $value['ПометкаУдаления'] ? now() : null, + 'deleted_at' => $value['ПометкаУдаления'] == 'Да' ? now() : null, ] ); } @@ -179,11 +180,11 @@ class Sync1cApiController extends Controller 'comments' => $value['Комментарий'], 'organization' => $value['Организация'], 'contract_number' => $value['НомерДоговора'], - 'contract_date' => $this->formatDate($value['ДатаДоговора']), - 'started_at' => $this->formatDate($value['ДатаНачалаДействияДоговора']), - 'ended_at' => $this->formatDate($value['ДатаОкончанияДействияДоговора']), + 'contract_date' => $this->formatDate($value['ДатаДоговора'])?->format('Y-m-d'), + 'started_at' => $this->formatDate($value['ДатаНачалаДействияДоговора'])?->format('Y-m-d'), + 'ended_at' => $this->formatDate($value['ДатаОкончанияДействияДоговора'])?->format('Y-m-d'), 'payment_type' => $value['УсловияОплаты'], - 'deleted_at' => $value['ПометкаУдаления'] ? now() : null, + 'deleted_at' => $value['ПометкаУдаления'] == 'Да' ? now() : null, ] ); } diff --git a/app/Http/Notifications/TelegramNotification.php b/app/Http/Notifications/TelegramNotification.php new file mode 100644 index 0000000..c3158df --- /dev/null +++ b/app/Http/Notifications/TelegramNotification.php @@ -0,0 +1,72 @@ + + */ + public function via($notifiable) + { + return ['telegram']; + } + + public function toTelegram($notifiable) + { + print_r($notifiable); + return TelegramMessage::create() + ->to(env('TELEGRAM_CHAT_ID')) + ->content($notifiable['car']) + ->line('') + ->line($notifiable['base_price']) + ->line($notifiable['period']) + ->line($notifiable['pickup_location']) + ->line($notifiable['return_location']) + ->line($notifiable['customer_type']) + ->line($notifiable['customer_full_name']) + ->line($notifiable['customer_email']) + ->line($notifiable['customer_phone']); + } + + /** + * Get the mail representation of the notification. + */ + public function toMail(object $notifiable): MailMessage + { + return (new MailMessage) + ->line('The introduction to the notification.') + ->action('Notification Action', url('/')) + ->line('Thank you for using our application!'); + } + + /** + * Get the array representation of the notification. + * + * @return array + */ + public function toArray(object $notifiable): array + { + return [ + // + ]; + } +} diff --git a/modules/auto/script.php b/modules/auto/script.php index 39022af..2ef7794 100644 --- a/modules/auto/script.php +++ b/modules/auto/script.php @@ -60,6 +60,7 @@ return new class extends \A7kz\Platform\Commands\InstallScript { ->firstOrCreate([ 'name' => $value['Модель'], 'brand_id' => $autoBrand->id, + 'year' => $this->formatDate($value['ГодПроизводства'])?->format('Y'), ])->id; $car->color_id = UniModel::model('pipi_auto_colors', $segment->connector) ->firstOrCreate([ @@ -67,9 +68,9 @@ return new class extends \A7kz\Platform\Commands\InstallScript { ])->id; $car->serial_number = $value['СерийныйНомер']; $car->state_number = $value['ГосНомер']; - $car->manufacture_year = $this->formatDate($value['ГодПроизводства']); + $car->manufacture_year = $this->formatDate($value['ГодПроизводства'])?->format('Y-m-d'); $car->passport_number = $value['НомерТехПаспорта']; - $car->passport_date = $this->formatDate($value['ДатаТехпаспорта']); + $car->passport_date = $this->formatDate($value['ДатаТехпаспорта'])?->format('Y-m-d'); $car->estimated_cost = $value['ОценочнаяСтоимость']; $owner = UniModel::model('pipi_owners', $segment->connector) ->firstOrCreate([ @@ -83,7 +84,7 @@ return new class extends \A7kz\Platform\Commands\InstallScript { $car->is_predefined = (bool) $value['Предопределенный']; $car->predefined_data_name = $value['ИмяПредопределенныхДанных']; $car->inspection_kit = json_validate($value['КомпректацияДляОсмотра']) ? $value['КомпректацияДляОсмотра'] : null; - if ((bool) $value['ПометкаУдаления']) { + if ($value['ПометкаУдаления'] == 'Да') { $car->deleted_at = now(); } $car->save(); @@ -135,13 +136,12 @@ return new class extends \A7kz\Platform\Commands\InstallScript { } } - private function formatDate($date): ?string + private function formatDate($date): ?Carbon { $date = trim($date); try { - $dateObject = \Carbon\Carbon::createFromFormat('d.m.Y', $date); - return $dateObject->format('Y-m-d'); + return Carbon::parse($date); } catch (\Exception $e) { return null; } diff --git a/modules/auto_tariffs/migrate.php b/modules/auto_tariffs/migrate.php index 98bd923..8909037 100644 --- a/modules/auto_tariffs/migrate.php +++ b/modules/auto_tariffs/migrate.php @@ -14,9 +14,17 @@ return new class extends Migration foreach ($segments as $segment) { Schema::connection($segment->connector)->create('pipi_auto_tariffs', static function (Blueprint $table) { $table->id(); - $table->string('name')->nullable()->comment('Наименование'); + $table->string('name'); + $table->string('type'); + $table->integer('day_range_start'); + $table->integer('day_range_end'); + $table->integer('base_rate'); + $table->integer('deposit'); $table->timestamps(); $table->softDeletes(); + + $table->unsignedBigInteger('model_id')->nullable()->comment('Тариф'); + $table->foreign('model_id')->references('id')->on('pipi_brand_models'); }); } } diff --git a/modules/brand_models/app.json b/modules/brand_models/app.json index 414d2a2..5534d0a 100644 --- a/modules/brand_models/app.json +++ b/modules/brand_models/app.json @@ -16,6 +16,9 @@ "name": { "type": "string" }, + "year": { + "type": "string" + }, "brand_id": { "type": "foreign", "table": "pipi_auto_brands", @@ -219,9 +222,17 @@ "title": "Модели автомобилей", "template": "app.base.crud.grid", "cols": [ + { + "name": "brand_id", + "caption": "Название марки" + }, { "name": "name", - "caption": "Название цвета" + "caption": "Название модели" + }, + { + "name": "year", + "caption": "Год выпуска" } ], "action": { @@ -260,18 +271,25 @@ { "cols": [ { - "size": 6, + "size": 5, "input": { "name": "name", "label": "Название" } }, { - "size": 6, + "size": 5, "input": { "name": "brand_id", "label": "Марка" } + }, + { + "size": 2, + "input": { + "name": "year", + "label": "Год" + } } ] } @@ -286,18 +304,25 @@ { "cols": [ { - "size": 6, + "size": 5, "input": { "name": "name", "label": "Название" } }, { - "size": 6, + "size": 5, "input": { "name": "brand_id", "label": "Марка" } + }, + { + "size": 2, + "input": { + "name": "year", + "label": "Год" + } } ] }, diff --git a/modules/brand_models/script.php b/modules/brand_models/script.php index 633fd94..5652ca0 100644 --- a/modules/brand_models/script.php +++ b/modules/brand_models/script.php @@ -29,6 +29,7 @@ return new class extends \A7kz\Platform\Commands\InstallScript { Schema::connection($segment->connector)->create('pipi_brand_models', static function (Blueprint $table) { $table->id(); $table->string('name')->nullable()->comment('Наименование'); + $table->integer('year')->nullable()->comment('Год выпуска'); $table->timestamps(); $table->softDeletes(); diff --git a/modules/owner_contracts/script.php b/modules/owner_contracts/script.php index 9d4d1eb..b029e64 100644 --- a/modules/owner_contracts/script.php +++ b/modules/owner_contracts/script.php @@ -75,11 +75,11 @@ return new class extends \A7kz\Platform\Commands\InstallScript { $model->comments = $value['Комментарий']; $model->organization = $value['Организация']; $model->contract_number = $value['НомерДоговора']; - $model->contract_date = $this->formatDate($value['ДатаДоговора']); - $model->started_at = $this->formatDate($value['ДатаНачалаДействияДоговора']); - $model->ended_at = $this->formatDate($value['ДатаОкончанияДействияДоговора']); + $model->contract_date = $this->formatDate($value['ДатаДоговора'])?->format('Y-m-d'); + $model->started_at = $this->formatDate($value['ДатаНачалаДействияДоговора'])?->format('Y-m-d'); + $model->ended_at = $this->formatDate($value['ДатаОкончанияДействияДоговора'])?->format('Y-m-d'); $model->payment_type = $value['УсловияОплаты']; - if ((bool) $value['ПометкаУдаления']) { + if ($value['ПометкаУдаления'] = 'Да') { $model->deleted_at = now(); } $model->save(); @@ -101,13 +101,12 @@ return new class extends \A7kz\Platform\Commands\InstallScript { } } - private function formatDate($date): ?string + private function formatDate($date): ?Carbon { $date = trim($date); try { - $dateObject = \Carbon\Carbon::createFromFormat('d.m.Y', $date); - return $dateObject->format('Y-m-d'); + return Carbon::parse($date); } catch (\Exception $e) { return null; } diff --git a/modules/owners/script.php b/modules/owners/script.php index 12ce2e8..65a024f 100644 --- a/modules/owners/script.php +++ b/modules/owners/script.php @@ -88,7 +88,7 @@ return new class extends \A7kz\Platform\Commands\InstallScript { $model->mail = $value['Почта']; $model->id_number = $value['УдНомер']; if ($value['УдДата']) { - $model->id_date = $this->formatDate($value['УдДата']); + $model->id_date = $this->formatDate($value['УдДата'])->format('Y-m-d'); } $model->issued = $value['УдВыдан']; if ($value['ОсновнойДоговор']) { @@ -97,7 +97,7 @@ return new class extends \A7kz\Platform\Commands\InstallScript { 'name' => $value['ОсновнойДоговор'] ])->id; } - if ((bool) $value['ПометкаУдаления']) { + if ($value['ПометкаУдаления'] == 'Да') { $model->deleted_at = now(); } $model->save(); @@ -118,13 +118,12 @@ return new class extends \A7kz\Platform\Commands\InstallScript { } } - private function formatDate($date): ?string + private function formatDate($date): ?Carbon { $date = trim($date); try { - $dateObject = \Carbon\Carbon::createFromFormat('d.m.Y', $date); - return $dateObject->format('Y-m-d'); + return Carbon::parse($date); } catch (\Exception $e) { return null; } diff --git a/routes/api.php b/routes/api.php index ba5648d..e7baac0 100644 --- a/routes/api.php +++ b/routes/api.php @@ -1,5 +1,6 @@ group(function () { Route::post('syncOwners', [Sync1cApiController::class, 'syncOwners']); Route::post('syncOwnerContracts', [Sync1cApiController::class, 'syncOwnerContracts']); }); + +Route::prefix('mobile')->group(function () { + Route::get('getMarks', [MobileApiController::class, 'getMarks']); +});