master
Rustem 2025-06-08 01:50:32 +05:00
parent 52d41a1346
commit 5ca3b2655f
7 changed files with 237 additions and 84 deletions

View File

@ -129,11 +129,11 @@ class MobileApiController extends Controller
'started_at' => $data['started_at'], 'started_at' => $data['started_at'],
'ended_at' => $data['ended_at'], 'ended_at' => $data['ended_at'],
'user_id' => $data['user_id'], 'user_id' => $data['user_id'],
'phone' => $data['phone'] ?? '' , 'phone' => $user?->phone ?? $data['phone'] ?? '' ,
'car_id' => $data['car_id'], 'car_id' => $data['car_id'],
'user_name' => $data['name'] ?? null, 'user_name' => $user?->name ?? $data['name'] ?? null,
'user_surname' => $data['surname'] ?? null, 'user_surname' => $user?->name ?? $data['surname'] ?? null,
'user_email' => $data['email'] ?? null, 'user_email' => $user?->email ?? $data['email'] ?? null,
'address_end' => $address_end?->id, 'address_end' => $address_end?->id,
'address_start' => $address_start?->id, 'address_start' => $address_start?->id,
'deposit' => $data['deposit'] ?? null, 'deposit' => $data['deposit'] ?? null,
@ -370,6 +370,7 @@ class MobileApiController extends Controller
$cars = UniModel::model('pipi_auto') $cars = UniModel::model('pipi_auto')
->where('color_id', $color) ->where('color_id', $color)
->where('model_id', $modelId) ->where('model_id', $modelId)
->whereNull('regular_user')
->get(); ->get();
$busyCars = UniModel::model('pipi_auto_calendar') $busyCars = UniModel::model('pipi_auto_calendar')
->whereBetween('date', [$started_at, $ended_at]) ->whereBetween('date', [$started_at, $ended_at])

View File

@ -7,6 +7,8 @@ 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\Models\User;
use App\Modules\applications\Enum\ApplicationStatus; use App\Modules\applications\Enum\ApplicationStatus;
use App\Modules\auto\Enums\AutoStatusEnums;
use Carbon\CarbonPeriod;
use Illuminate\Support\Carbon; use Illuminate\Support\Carbon;
use Illuminate\Support\Facades\Hash; use Illuminate\Support\Facades\Hash;
@ -16,13 +18,12 @@ class Approve extends Logic
{ {
$user = new User(); $user = new User();
if (!isset($this->row->user_id)) {
$checkUser = UniModel::model('core_users')->where('email', $this->row->user_email)->first(); $checkUser = UniModel::model('core_users')->where('email', $this->row->user_email)->first();
if (isset($checkUser)) { if (isset($checkUser)) {
$this->row->user_id = $checkUser->id; $this->row->user_id = $checkUser->id;
$this->row->status = ApplicationStatus::approved;
$this->row->save(); $this->row->save();
return $this->response(); } else {
}
$user->forceFill([ $user->forceFill([
'name' => $this->row->user_name . ' ' . $this->row->surname_name, 'name' => $this->row->user_name . ' ' . $this->row->surname_name,
'username' => $this->row->user_email, 'username' => $this->row->user_email,
@ -34,7 +35,6 @@ class Approve extends Logic
$user->save(); $user->save();
$this->row->user_id = $user->id; $this->row->user_id = $user->id;
$this->row->status = ApplicationStatus::approved;
$this->row->save(); $this->row->save();
$userRole = UniModel::model('core_roles') $userRole = UniModel::model('core_roles')
->where('alias', 'user') ->where('alias', 'user')
@ -79,7 +79,28 @@ class Approve extends Logic
'user_id' => $user->id, 'user_id' => $user->id,
'default' => true, 'default' => true,
]); ]);
}
}
$this->fillCalendar($this->row);
$this->row->status = ApplicationStatus::approved->value;
$this->row->save();
return $this->response(); return $this->response();
} }
private function fillCalendar($row): void
{
$period = CarbonPeriod::create($row->started_at, $row->ended_at);
$dates = array_map(fn($date) => $date->toDateString(), iterator_to_array($period));
foreach ($dates as $date) {
UniModel::model('pipi_auto_calendar')->create([
'auto_id' => $row->car_id,
'date' => $date,
'status' => AutoStatusEnums::Rent->name
]);
}
}
} }

View File

@ -0,0 +1,37 @@
<?php
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 Cancel extends Logic
{
public function run()
{
if (Carbon::now() > $this->row->ended_at) {
$this->message = 'Вы не можете завершить заявку после даты окончания аренды';
return $this->response();
}
$car = $this->row->car_id;
if (isset($car)) {
UniModel::model('pipi_auto_calendar')
->where('date', '>=', Carbon::now()->toDateString())
->where('date', '<=', $this->row->ended_at)
->where('auto_id', $car)->delete();
}
$this->row->status = ApplicationStatus::rejected->value;
$this->row->ended_at = Carbon::now();
$this->row->save();
return $this->response();
}
}

View File

@ -0,0 +1,21 @@
<?php
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 Complete extends Logic
{
public function run()
{
$this->row->status = ApplicationStatus::completed->value;
$this->row->save();
return $this->response();
}
}

View File

@ -44,6 +44,12 @@
"user_email": { "user_email": {
"type": "string" "type": "string"
}, },
"sum": {
"type": "int"
},
"deposit": {
"type": "int"
},
"started_at": { "started_at": {
"type": "date", "type": "date",
"validation": "required|date" "validation": "required|date"
@ -55,6 +61,25 @@
"photos": { "photos": {
"type": "json", "type": "json",
"validation": "nullable" "validation": "nullable"
},
"address_start": {
"type": "foreign",
"table": "pipi_address",
"foreign": "id",
"display": [
"name"
],
"validation": "required|integer"
},
"address_end": {
"type": "foreign",
"table": "pipi_address",
"alias": "address_end",
"foreign": "id",
"display": [
"name"
],
"validation": "required|integer"
} }
} }
}, },
@ -71,7 +96,7 @@
{ "name": "user_surname", "caption": "Фамилия" }, { "name": "user_surname", "caption": "Фамилия" },
{ "name": "user_email", "caption": "Email" }, { "name": "user_email", "caption": "Email" },
{ "name": "started_at", "caption": "Начало" }, { "name": "started_at", "caption": "Начало" },
{ "name": "ended_at", "caption": "Окончание" } { "name": "ended_at", "caption": "Дата окончания" }
], ],
"action": { "action": {
"head": [ "head": [
@ -131,7 +156,15 @@
}, },
{ {
"cols": [ "cols": [
{ "size": 6, "input": { "name": "ended_at", "label": "Окончание" } }, { "size": 3, "input": { "name": "address_start", "label": "Адрес получения" } },
{ "size": 3, "input": { "name": "address_end", "label": "Конечный адрес" } },
{ "size": 3, "input": { "name": "sum", "label": "Сумма" } },
{ "size": 3, "input": { "name": "deposit", "label": "Депозит" } }
]
},
{
"cols": [
{ "size": 6, "input": { "name": "ended_at", "label": "Дата окончания" } },
{ "size": 6, "input": { "name": "photos", "label": "Фотографии", "type": "files"} } { "size": 6, "input": { "name": "photos", "label": "Фотографии", "type": "files"} }
] ]
} }
@ -161,7 +194,15 @@
"cols": [ "cols": [
{ "size": 4, "input": { "name": "user_email", "label": "Email" } }, { "size": 4, "input": { "name": "user_email", "label": "Email" } },
{ "size": 4, "input": { "name": "started_at", "label": "Начало" } }, { "size": 4, "input": { "name": "started_at", "label": "Начало" } },
{ "size": 4, "input": { "name": "ended_at", "label": "Окончание" } } { "size": 4, "input": { "name": "ended_at", "label": "Дата окончания" } }
]
},
{
"cols": [
{ "size": 3, "input": { "name": "address_start", "label": "Адрес получения" } },
{ "size": 3, "input": { "name": "address_end", "label": "Конечный адрес" } },
{ "size": 3, "input": { "name": "sum", "label": "Сумма" } },
{ "size": 3, "input": { "name": "deposit", "label": "Депозит" } }
] ]
}, },
{ {
@ -199,7 +240,15 @@
"cols": [ "cols": [
{ "size": 4, "input": { "name": "user_email", "label": "Email" } }, { "size": 4, "input": { "name": "user_email", "label": "Email" } },
{ "size": 4, "input": { "name": "started_at", "label": "Начало" } }, { "size": 4, "input": { "name": "started_at", "label": "Начало" } },
{ "size": 4, "input": { "name": "ended_at", "label": "Окончание" } } { "size": 4, "input": { "name": "ended_at", "label": "Дата окончания" } }
]
},
{
"cols": [
{ "size": 3, "input": { "name": "address_start", "label": "Адрес получения" } },
{ "size": 3, "input": { "name": "address_end", "label": "Конечный адрес" } },
{ "size": 3, "input": { "name": "sum", "label": "Сумма" } },
{ "size": 3, "input": { "name": "deposit", "label": "Депозит" } }
] ]
}, },
{ {
@ -220,13 +269,15 @@
"type": "logic", "type": "logic",
"name": "App.Modules.applications.Logic.Cancel", "name": "App.Modules.applications.Logic.Cancel",
"label": "Отменить заявку", "label": "Отменить заявку",
"btn": "btn btn-danger" "btn": "btn btn-danger",
"condition": "status,==,approved"
}, },
{ {
"type": "logic", "type": "logic",
"name": "App.Modules.applications.Logic.Extend", "name": "App.Modules.applications.Logic.Complete",
"label": "Продлить аренду", "label": "Завершить заявку",
"btn": "btn btn-success" "btn": "btn btn-success",
"condition": "status,==,review"
}, },
"struct:crud.form.submit.save", "struct:crud.form.submit.save",
"struct:crud.form.submit.close" "struct:crud.form.submit.close"

View File

@ -153,6 +153,14 @@
"photo_id": { "photo_id": {
"type": "int", "type": "int",
"validation": "nullable|int" "validation": "nullable|int"
},
"regular_user": {
"type": "foreign",
"table": "core_users",
"foreign": "id",
"display": ["username"],
"nullable": true,
"comment": "Постоянный клиент"
} }
} }
}, },
@ -301,8 +309,8 @@
{ {
"size": 4, "size": 4,
"input": { "input": {
"name": "owner_id", "name": "regular_user",
"label": "Владелец" "label": "Постоянный клиент"
} }
}, },
{ {
@ -330,21 +338,24 @@
"size": 4, "size": 4,
"input": { "input": {
"name": "code", "name": "code",
"label": "Код" "label": "Код",
"readonly": true
} }
}, },
{ {
"size": 4, "size": 4,
"input": { "input": {
"name": "name", "name": "name",
"label": "Наименование" "label": "Наименование",
"readonly": true
} }
}, },
{ {
"size": 4, "size": 4,
"input": { "input": {
"name": "state_number", "name": "state_number",
"label": "Госномер" "label": "Госномер",
"readonly": true
} }
} }
] ]
@ -355,21 +366,24 @@
"size": 4, "size": 4,
"input": { "input": {
"name": "brand_id", "name": "brand_id",
"label": "Марка" "label": "Марка",
"readonly": true
} }
}, },
{ {
"size": 4, "size": 4,
"input": { "input": {
"name": "model_id", "name": "model_id",
"label": "Модель" "label": "Модель",
"readonly": true
} }
}, },
{ {
"size": 4, "size": 4,
"input": { "input": {
"name": "color_id", "name": "color_id",
"label": "Цвет" "label": "Цвет",
"readonly": true
} }
} }
] ]
@ -380,21 +394,23 @@
"size": 4, "size": 4,
"input": { "input": {
"name": "manufacture_year", "name": "manufacture_year",
"label": "Год производства" "label": "Год производства",
"readonly": true
} }
}, },
{ {
"size": 4, "size": 4,
"input": { "input": {
"name": "estimated_cost", "name": "estimated_cost",
"label": "Оценочная стоимость" "label": "Оценочная стоимость",
"readonly": true
} }
}, },
{ {
"size": 4, "size": 4,
"input": { "input": {
"name": "owner_id", "name": "regular_user",
"label": "Владелец" "label": "Постоянный клиент"
} }
}, },
{ {

View File

@ -145,6 +145,12 @@ return new class extends \A7kz\Platform\Commands\InstallScript {
$table->unsignedBigInteger('photo_id')->nullable(); $table->unsignedBigInteger('photo_id')->nullable();
}); });
} }
if (!Schema::connection($segment->connector)->hasColumn('pipi_auto', 'regular_user')) {
Schema::connection($segment->connector)->table('pipi_auto', static function (Blueprint $table) {
$table->unsignedBigInteger('regular_user')->nullable();
});
}
} }
} }