deposit
parent
dce5c1e30f
commit
a46dc1ec01
|
|
@ -24,6 +24,7 @@ class PipiCarInstallCommands extends InstallCommand
|
||||||
|
|
||||||
$this->packages = [
|
$this->packages = [
|
||||||
'main', // Главная страница
|
'main', // Главная страница
|
||||||
|
'address', // Главная страница
|
||||||
'auto_brands', // Бренд авто
|
'auto_brands', // Бренд авто
|
||||||
'auto_bodywork', // Кузов авто
|
'auto_bodywork', // Кузов авто
|
||||||
'auto_colors', // Цвета авто
|
'auto_colors', // Цвета авто
|
||||||
|
|
|
||||||
|
|
@ -7,6 +7,7 @@ use A7kz\Platform\Modules\Platform\Acl\Facades\Acl;
|
||||||
use A7kz\Platform\Modules\Platform\Segment\Facades\Segment;
|
use A7kz\Platform\Modules\Platform\Segment\Facades\Segment;
|
||||||
use App\Modules\applications\Enum\ApplicationStatus;
|
use App\Modules\applications\Enum\ApplicationStatus;
|
||||||
use App\Modules\auto\Enums\AutoStatusEnums;
|
use App\Modules\auto\Enums\AutoStatusEnums;
|
||||||
|
use App\Service\DepositService;
|
||||||
use Carbon\CarbonPeriod;
|
use Carbon\CarbonPeriod;
|
||||||
use Exception;
|
use Exception;
|
||||||
use Illuminate\Http\JsonResponse;
|
use Illuminate\Http\JsonResponse;
|
||||||
|
|
@ -110,6 +111,8 @@ class MobileApiController extends Controller
|
||||||
} elseif (!isset($data['user_id'])) {
|
} elseif (!isset($data['user_id'])) {
|
||||||
$response['message'] = 'Заявка создана, с вами свяжется наш оператор';
|
$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([
|
UniModel::model('pipi_applications')->create([
|
||||||
'rent_day' => $data['rent_day'],
|
'rent_day' => $data['rent_day'],
|
||||||
|
|
@ -121,6 +124,9 @@ class MobileApiController extends Controller
|
||||||
'user_name' => $data['name'] ?? null,
|
'user_name' => $data['name'] ?? null,
|
||||||
'user_surname' => $data['surname'] ?? null,
|
'user_surname' => $data['surname'] ?? null,
|
||||||
'user_email' => $data['email'] ?? null,
|
'user_email' => $data['email'] ?? null,
|
||||||
|
'address_end' => $address_end,
|
||||||
|
'address_start' => $address_start,
|
||||||
|
'deposit' => $data['deposit'] ?? null,
|
||||||
'status' => ApplicationStatus::pending->value
|
'status' => ApplicationStatus::pending->value
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
|
@ -226,8 +232,6 @@ class MobileApiController extends Controller
|
||||||
return $availableCars->isNotEmpty();
|
return $availableCars->isNotEmpty();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public function getAvailableMarksList(Request $request): JsonResponse
|
public function getAvailableMarksList(Request $request): JsonResponse
|
||||||
{
|
{
|
||||||
$started_at = $request->query('started_at');
|
$started_at = $request->query('started_at');
|
||||||
|
|
@ -371,20 +375,26 @@ class MobileApiController extends Controller
|
||||||
|
|
||||||
$discountRate = null;
|
$discountRate = null;
|
||||||
$basePrice = null;
|
$basePrice = null;
|
||||||
|
$deposit = null;
|
||||||
|
|
||||||
foreach ($tariffs as $range) {
|
foreach ($tariffs as $range) {
|
||||||
if ($range->day_range_start == 1 && $range->day_range_end == 2) {
|
if ($range->day_range_start == 1 && $range->day_range_end == 2) {
|
||||||
$basePrice = $range->base_rate;
|
$basePrice = $range->base_rate;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (isset($range->deposit)) {
|
||||||
|
$deposit = $range->deposit;
|
||||||
|
}
|
||||||
if ($days >= $range->day_range_start && $days <= $range->day_range_end) {
|
if ($days >= $range->day_range_start && $days <= $range->day_range_end) {
|
||||||
$discountRate = $range->base_rate;
|
$discountRate = $range->base_rate;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$deposit_without = new DepositService();
|
||||||
|
|
||||||
// Если не нашли подходящий тариф, но дней больше 30 — применяем скидку
|
// Если не нашли подходящий тариф, но дней больше 30 — применяем скидку
|
||||||
if (is_null($discountRate) && $days > 30 && count($tariffs) > 0) {
|
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,
|
'discount_price_per_day' => $discountRate,
|
||||||
'base_sum' => $baseSum,
|
'base_sum' => $baseSum,
|
||||||
'discounted_sum' => $discountedSum,
|
'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);
|
$folder2 = substr($storage_file_name, 2, 3);
|
||||||
return $folder1 . '/' . $folder2 . '/' . $storage_file_name . '.' . $ext;
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,29 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Service;
|
||||||
|
|
||||||
|
class DepositService
|
||||||
|
{
|
||||||
|
public function calcWithoutDeposit($deposit, $days): float {
|
||||||
|
$percentRates = [
|
||||||
|
3.00, 3.00, 3.00, 4.05, 5.10, 6.15, 7.20, 8.25, 9.30,
|
||||||
|
10.35, 11.40, 12.45, 13.00, 13.00, 13.00, 13.00, 13.00, 13.00, 13.00,
|
||||||
|
13.00, 13.00, 13.00, 13.00, 13.00, 13.00, 13.00, 13.00, 13.00, 13.00, 13.00,
|
||||||
|
13.44, 13.88, 14.32, 14.76, 15.20
|
||||||
|
];
|
||||||
|
|
||||||
|
$lastKnownRate = 15.20;
|
||||||
|
$ndsRate = 0.12;
|
||||||
|
$total = 0;
|
||||||
|
|
||||||
|
for ($i = 0; $i < $days; $i++) {
|
||||||
|
$percent = $percentRates[$i] ?? $lastKnownRate;
|
||||||
|
if ($percent !== null) {
|
||||||
|
$sumForDay = $deposit * ($percent / 100) * (1 + $ndsRate);
|
||||||
|
$total += $sumForDay;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return round($total, 2);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,9 @@
|
||||||
|
{
|
||||||
|
"admin": [
|
||||||
|
"default",
|
||||||
|
"add",
|
||||||
|
"show",
|
||||||
|
"edit",
|
||||||
|
"delete"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,104 @@
|
||||||
|
{
|
||||||
|
"module": "pipicar",
|
||||||
|
"name": "pipicar.address",
|
||||||
|
"type": "crud",
|
||||||
|
"title": "Адреса",
|
||||||
|
"withHeader": false,
|
||||||
|
"data": {
|
||||||
|
"table": "pipi_address",
|
||||||
|
"pk": "id",
|
||||||
|
"limit": 25,
|
||||||
|
"segment": true,
|
||||||
|
"timestamp": false,
|
||||||
|
"fields": {
|
||||||
|
"id": {
|
||||||
|
"type": "pk"
|
||||||
|
},
|
||||||
|
"name": {
|
||||||
|
"type": "string"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"ui": {
|
||||||
|
"grid": {
|
||||||
|
"title": "Адреса",
|
||||||
|
"component": "App.components.Grid",
|
||||||
|
"cols": [
|
||||||
|
{
|
||||||
|
"name": "name",
|
||||||
|
"caption": "Адрес"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"action": {
|
||||||
|
"head": [
|
||||||
|
"add"
|
||||||
|
],
|
||||||
|
"row": [
|
||||||
|
"edit",
|
||||||
|
"delete"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"filter": {
|
||||||
|
"template": "app.base.crud.filter",
|
||||||
|
"rows": [
|
||||||
|
{
|
||||||
|
"cols": [
|
||||||
|
{
|
||||||
|
"size": 6,
|
||||||
|
"input": {
|
||||||
|
"name": "name",
|
||||||
|
"label": "Название цвета"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"forms": {
|
||||||
|
"add": {
|
||||||
|
"title": "Адрес",
|
||||||
|
"template": "app.base.crud.form",
|
||||||
|
"component": "App.components.Show",
|
||||||
|
"form": {
|
||||||
|
"submits": "struct:crud.form.edit.submits",
|
||||||
|
"rows": [
|
||||||
|
{
|
||||||
|
"cols": [
|
||||||
|
{
|
||||||
|
"size": 6,
|
||||||
|
"input": {
|
||||||
|
"name": "name",
|
||||||
|
"label": "Название"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"edit": {
|
||||||
|
"title": "Адрес",
|
||||||
|
"template": "app.base.crud.form",
|
||||||
|
"component": "App.components.Show",
|
||||||
|
"form": {
|
||||||
|
"rows": [
|
||||||
|
{
|
||||||
|
"cols": [
|
||||||
|
{
|
||||||
|
"size": 6,
|
||||||
|
"input": {
|
||||||
|
"name": "name",
|
||||||
|
"label": "Название"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"submits": "struct:crud.form.edit.submits"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"actions": "struct:crud.actions"
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,23 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
use A7kz\Platform\Modules\Platform\Segment\Facades\Segment;
|
||||||
|
use Illuminate\Database\Migrations\Migration;
|
||||||
|
use Illuminate\Database\Schema\Blueprint;
|
||||||
|
use Illuminate\Support\Facades\Schema;
|
||||||
|
|
||||||
|
|
||||||
|
return new class extends Migration
|
||||||
|
{
|
||||||
|
public function up(): void
|
||||||
|
{
|
||||||
|
$segments = Segment::listActive();
|
||||||
|
foreach ($segments as $segment) {
|
||||||
|
Schema::connection($segment->connector)->create('pipi_address', static function (Blueprint $table) {
|
||||||
|
$table->id();
|
||||||
|
$table->string('name')->nullable()->comment('Наименование');
|
||||||
|
$table->timestamps();
|
||||||
|
$table->softDeletes();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
@ -0,0 +1,38 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
use A7kz\Platform\Models\UniModel;
|
||||||
|
use A7kz\Platform\Modules\Platform\Core\Facades\Core;
|
||||||
|
use A7kz\Platform\Modules\Platform\Segment\Facades\Segment;
|
||||||
|
use Carbon\Carbon;
|
||||||
|
use Illuminate\Database\Schema\Blueprint;
|
||||||
|
use Illuminate\Support\Facades\DB;
|
||||||
|
use Illuminate\Support\Facades\Schema;
|
||||||
|
use Illuminate\Support\Facades\Storage;
|
||||||
|
use \A7kz\Platform\Commands\InstallScript;
|
||||||
|
|
||||||
|
return new class extends \A7kz\Platform\Commands\InstallScript {
|
||||||
|
|
||||||
|
public function install($module_name, $module_version)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
public function update($module_name, $module_version): void
|
||||||
|
{
|
||||||
|
$this->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();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
@ -5,13 +5,81 @@ namespace App\Modules\applications\Logic;
|
||||||
use A7kz\Platform\Models\UniModel;
|
use A7kz\Platform\Models\UniModel;
|
||||||
use A7kz\Platform\Modules\Platform\Acl\Facades\Acl;
|
use A7kz\Platform\Modules\Platform\Acl\Facades\Acl;
|
||||||
use A7kz\Platform\Modules\Platform\Core\Services\Base\Logic;
|
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\Carbon;
|
||||||
|
use Illuminate\Support\Facades\Hash;
|
||||||
|
|
||||||
class Approve extends Logic
|
class Approve extends Logic
|
||||||
{
|
{
|
||||||
public function run()
|
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();
|
return $this->response();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -82,7 +82,6 @@
|
||||||
"add"
|
"add"
|
||||||
],
|
],
|
||||||
"row": [
|
"row": [
|
||||||
"edit",
|
|
||||||
"delete"
|
"delete"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
|
@ -233,6 +232,21 @@
|
||||||
"btn": "btn btn-success",
|
"btn": "btn btn-success",
|
||||||
"condition": "status,==,pending"
|
"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.save",
|
||||||
"struct:crud.form.submit.close"
|
"struct:crud.form.submit.close"
|
||||||
]
|
]
|
||||||
|
|
|
||||||
|
|
@ -48,6 +48,12 @@ return new class extends \A7kz\Platform\Commands\InstallScript {
|
||||||
$table->json('photos')->nullable();
|
$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();
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -26,6 +26,7 @@ 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::get('getAddress', [MobileApiController::class, 'getAddress']);
|
||||||
Route::get('getAvailableMarksList', [MobileApiController::class, 'getAvailableMarksList']);
|
Route::get('getAvailableMarksList', [MobileApiController::class, 'getAvailableMarksList']);
|
||||||
Route::post('checkAvailableCar', [MobileApiController::class, 'checkAvailableCar']);
|
Route::post('checkAvailableCar', [MobileApiController::class, 'checkAvailableCar']);
|
||||||
Route::post('sendApplication', [MobileApiController::class, 'sendApplication']);
|
Route::post('sendApplication', [MobileApiController::class, 'sendApplication']);
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue