master
parent
52d41a1346
commit
5ca3b2655f
|
|
@ -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])
|
||||||
|
|
|
||||||
|
|
@ -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,70 +18,89 @@ class Approve extends Logic
|
||||||
{
|
{
|
||||||
$user = new User();
|
$user = new User();
|
||||||
|
|
||||||
$checkUser = UniModel::model('core_users')->where('email', $this->row->user_email)->first();
|
if (!isset($this->row->user_id)) {
|
||||||
if (isset($checkUser)) {
|
$checkUser = UniModel::model('core_users')->where('email', $this->row->user_email)->first();
|
||||||
$this->row->user_id = $checkUser->id;
|
if (isset($checkUser)) {
|
||||||
$this->row->status = ApplicationStatus::approved;
|
$this->row->user_id = $checkUser->id;
|
||||||
$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,
|
'email' => $this->row->user_email,
|
||||||
'email' => $this->row->user_email,
|
'phone' => $this->row->user_phone,
|
||||||
'phone' => $this->row->user_phone,
|
'password' => Hash::make('password'),
|
||||||
'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
|
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
$user->save();
|
||||||
|
|
||||||
|
$this->row->user_id = $user->id;
|
||||||
|
$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,
|
||||||
|
]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
UniModel::model(config('platform.company.tables.company_user'))
|
$this->fillCalendar($this->row);
|
||||||
->firstOrCreate([
|
|
||||||
'company_id' => $company->id,
|
$this->row->status = ApplicationStatus::approved->value;
|
||||||
'user_id' => $user->id,
|
$this->row->save();
|
||||||
'default' => true,
|
|
||||||
]);
|
|
||||||
|
|
||||||
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
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -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();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -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();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -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"
|
||||||
|
|
|
||||||
|
|
@ -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": "Постоянный клиент"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -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();
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue