diff --git a/app/Console/PipiCarInstallCommands.php b/app/Console/PipiCarInstallCommands.php index 1de8f98..86bf7d4 100644 --- a/app/Console/PipiCarInstallCommands.php +++ b/app/Console/PipiCarInstallCommands.php @@ -24,6 +24,7 @@ class PipiCarInstallCommands extends InstallCommand $this->packages = [ 'main', // Главная страница + 'address', // Главная страница 'auto_brands', // Бренд авто 'auto_bodywork', // Кузов авто 'auto_colors', // Цвета авто diff --git a/app/Http/Controllers/MobileApiController.php b/app/Http/Controllers/MobileApiController.php index 5271864..d42655b 100644 --- a/app/Http/Controllers/MobileApiController.php +++ b/app/Http/Controllers/MobileApiController.php @@ -7,6 +7,7 @@ use A7kz\Platform\Modules\Platform\Acl\Facades\Acl; use A7kz\Platform\Modules\Platform\Segment\Facades\Segment; use App\Modules\applications\Enum\ApplicationStatus; use App\Modules\auto\Enums\AutoStatusEnums; +use App\Service\DepositService; use Carbon\CarbonPeriod; use Exception; use Illuminate\Http\JsonResponse; @@ -110,6 +111,8 @@ class MobileApiController extends Controller } elseif (!isset($data['user_id'])) { $response['message'] = 'Заявка создана, с вами свяжется наш оператор'; } + $address_end = UniModel::model('pipi_address')->where('name', $data['address_end'])->first(); + $address_start = UniModel::model('pipi_address')->where('name', $data['address_start'])->first(); UniModel::model('pipi_applications')->create([ 'rent_day' => $data['rent_day'], @@ -121,6 +124,9 @@ class MobileApiController extends Controller 'user_name' => $data['name'] ?? null, 'user_surname' => $data['surname'] ?? null, 'user_email' => $data['email'] ?? null, + 'address_end' => $address_end, + 'address_start' => $address_start, + 'deposit' => $data['deposit'] ?? null, 'status' => ApplicationStatus::pending->value ]); @@ -226,8 +232,6 @@ class MobileApiController extends Controller return $availableCars->isNotEmpty(); } - - public function getAvailableMarksList(Request $request): JsonResponse { $started_at = $request->query('started_at'); @@ -371,20 +375,26 @@ class MobileApiController extends Controller $discountRate = null; $basePrice = null; + $deposit = null; foreach ($tariffs as $range) { if ($range->day_range_start == 1 && $range->day_range_end == 2) { $basePrice = $range->base_rate; } + if (isset($range->deposit)) { + $deposit = $range->deposit; + } if ($days >= $range->day_range_start && $days <= $range->day_range_end) { $discountRate = $range->base_rate; } } + $deposit_without = new DepositService(); + // Если не нашли подходящий тариф, но дней больше 30 — применяем скидку if (is_null($discountRate) && $days > 30 && count($tariffs) > 0) { - $discountRate = round($tariffs[0]->base_rate * 0.6); + $discountRate = round($basePrice * 0.6); } // Считаем суммы @@ -397,6 +407,8 @@ class MobileApiController extends Controller 'discount_price_per_day' => $discountRate, 'base_sum' => $baseSum, 'discounted_sum' => $discountedSum, + 'deposit_base' => $deposit, + 'without_deposit' => $deposit_without->calcWithoutDeposit($deposit, $days), ]); } @@ -456,4 +468,18 @@ class MobileApiController extends Controller $folder2 = substr($storage_file_name, 2, 3); return $folder1 . '/' . $folder2 . '/' . $storage_file_name . '.' . $ext; } + + public function getAddress(): JsonResponse + { + $addresses = UniModel::model('pipi_address')->get(); + foreach ($addresses as $address) { + $data[$address->id] = $address->name; + } + + if (empty($data)) { + $data = (object) []; + } + + return response()->json($data); + } } diff --git a/app/Service/DepositService.php b/app/Service/DepositService.php new file mode 100644 index 0000000..39b55f3 --- /dev/null +++ b/app/Service/DepositService.php @@ -0,0 +1,29 @@ +connector)->create('pipi_address', static function (Blueprint $table) { + $table->id(); + $table->string('name')->nullable()->comment('Наименование'); + $table->timestamps(); + $table->softDeletes(); + }); + } + } +}; diff --git a/modules/address/script.php b/modules/address/script.php new file mode 100644 index 0000000..2a43bbc --- /dev/null +++ b/modules/address/script.php @@ -0,0 +1,38 @@ +upgrade(); + } + + private function upgrade(): void + { + $segments = Segment::listActive(); + foreach ($segments as $segment) { + if (!Schema::connection($segment->connector)->hasTable('pipi_auto_colors')) { + Schema::connection($segment->connector)->create('pipi_address', static function (Blueprint $table) { + $table->id(); + $table->string('name')->nullable()->comment('Наименование'); + $table->timestamps(); + $table->softDeletes(); + }); + } + } + } +}; diff --git a/modules/applications/Logic/Approve.php b/modules/applications/Logic/Approve.php index 9297aa0..95ee3da 100644 --- a/modules/applications/Logic/Approve.php +++ b/modules/applications/Logic/Approve.php @@ -5,13 +5,81 @@ namespace App\Modules\applications\Logic; use A7kz\Platform\Models\UniModel; use A7kz\Platform\Modules\Platform\Acl\Facades\Acl; use A7kz\Platform\Modules\Platform\Core\Services\Base\Logic; +use App\Models\User; +use App\Modules\applications\Enum\ApplicationStatus; use Illuminate\Support\Carbon; +use Illuminate\Support\Facades\Hash; class Approve extends Logic { public function run() { - dd(123); + $user = new User(); + + $checkUser = UniModel::model('core_users')->where('email', $this->row->user_email)->first(); + if (isset($checkUser)) { + $this->row->user_id = $checkUser->id; + $this->row->status = ApplicationStatus::approved; + $this->row->save(); + return $this->response(); + } + $user->forceFill([ + 'name' => $this->row->user_name . ' ' . $this->row->surname_name, + 'username' => $this->row->user_email, + 'email' => $this->row->user_email, + 'phone' => $this->row->user_phone, + 'password' => Hash::make('password'), + ]); + + $user->save(); + + $this->row->user_id = $user->id; + $this->row->status = ApplicationStatus::approved; + $this->row->save(); + $userRole = UniModel::model('core_roles') + ->where('alias', 'user') + ->first(); + + if (!empty($userRole)) { + $userRoleModel = UniModel::model('core_user_roles'); + + $userRoleModel->forceFill([ + 'user_id' => $user->id, + 'role_id' => $userRole->id + ]); + + $userRoleModel->save(); + } + $company = UniModel::model(config('platform.company.tables.company')) + ->firstOrCreate([ + 'name' => $this->row->user_name . ' ' . $this->row->surname_name, + 'biniin' => $this->row->biniin ?? '', + 'fullname' => $this->row->user_name . ' ' . $this->row->surname_name, + 'segment' => 'sol' + ]); + + $ucr = UniModel::model(config('platform.company.tables.company_user_role')) + ->firstOrCreate([ + 'user_id' => $user->id, + 'role_id' => 7, + 'company_id' => $company->id + ]); + if (!$ucr) { + UniModel::model(config('platform.company.tables.company_user_role')) + ->create([ + 'user_id' => $user->id, + 'role_id' => 6, + 'company_id' => $company->id + ]); + } + + UniModel::model(config('platform.company.tables.company_user')) + ->firstOrCreate([ + 'company_id' => $company->id, + 'user_id' => $user->id, + 'default' => true, + ]); + return $this->response(); } } diff --git a/modules/applications/app.json b/modules/applications/app.json index e8a2c04..4c91be8 100644 --- a/modules/applications/app.json +++ b/modules/applications/app.json @@ -82,7 +82,6 @@ "add" ], "row": [ - "edit", "delete" ] }, @@ -233,6 +232,21 @@ "btn": "btn btn-success", "condition": "status,==,pending" }, + { + "type": "logic", + "name": "App.Modules.applications.Logic.Extend", + "label": "Продлить аренду", + "icon": "bi bi-check", + "btn": "btn btn-success", + "condition": "status,==,approved" + }, + { + "type": "logic", + "name": "App.Modules.applications.Logic.Cancel", + "label": "Отменить заявку", + "icon": "bi bi-check", + "btn": "btn btn-danger" + }, "struct:crud.form.submit.save", "struct:crud.form.submit.close" ] diff --git a/modules/applications/script.php b/modules/applications/script.php index e047165..428abfc 100644 --- a/modules/applications/script.php +++ b/modules/applications/script.php @@ -48,6 +48,12 @@ return new class extends \A7kz\Platform\Commands\InstallScript { $table->json('photos')->nullable(); }); } + if (!Schema::connection($segment->connector)->hasColumn('pipi_applications', 'address_start')) { + Schema::connection($segment->connector)->table('pipi_applications', static function (Blueprint $table) { + $table->unsignedBigInteger('address_end')->nullable(); + $table->unsignedBigInteger('address_start')->nullable(); + }); + } } } }; diff --git a/routes/api.php b/routes/api.php index a77371d..2efbd28 100644 --- a/routes/api.php +++ b/routes/api.php @@ -26,6 +26,7 @@ Route::prefix('1c')->group(function () { Route::prefix('mobile')->group(function () { Route::get('getMarks', [MobileApiController::class, 'getMarks']); + Route::get('getAddress', [MobileApiController::class, 'getAddress']); Route::get('getAvailableMarksList', [MobileApiController::class, 'getAvailableMarksList']); Route::post('checkAvailableCar', [MobileApiController::class, 'checkAvailableCar']); Route::post('sendApplication', [MobileApiController::class, 'sendApplication']);