nim_filter

pull/9/head
nimtaurel 2025-04-24 13:34:25 +05:00
commit 8e7ed8f785
6 changed files with 322 additions and 21 deletions

View File

@ -3,12 +3,22 @@
namespace App\Http\Controllers;
use A7kz\Platform\Models\UniModel;
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 Carbon\CarbonPeriod;
use Exception;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
use Illuminate\Support\Carbon;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Log;
use Illuminate\Support\Facades\Notification;
use Illuminate\Support\Facades\Storage;
use Mpdf\Tag\Mark;
use function PHPUnit\Framework\isEmpty;
class MobileApiController extends Controller
{
@ -78,12 +88,12 @@ class MobileApiController extends Controller
'message' => 'Заявка создана',
];
$car = $this->getAvailableCar($data['started_at'], $data['ended_at'], $data['mark_id'], $data['color_code']);
if (!isset($car)) {
return response()->json('Нет свободных машин');
}
$data['car_id'] = $car->id;
if ($data['user_id']) {
$car = $this->getAvailableCar($data['started_at'], $data['ended_at'], $data['mark_id'], $data['color_code']);
if (!isset($car)) {
return response()->json('Нет свободных машин');
}
$data['car_id'] = $car->id;
$period = CarbonPeriod::create($data['started_at'], $data['ended_at']);
$dates = array_map(fn($date) => $date->toDateString(), iterator_to_array($period));
@ -119,7 +129,49 @@ class MobileApiController extends Controller
public function getApplications(): JsonResponse
{
return response()->json(UniModel::model('pipi_applications')->get());
$request = request();
if ($request->header('Authorization')) {
$user = auth()->guard('api')->user();
} else {
return response()->json([
'status' => false,
'message' => __('Вы не авторизованы')
]);
}
$applications = [];
$application = UniModel::model('pipi_applications')->where('user_id', $user->id)->get();
foreach ($application as $app) {
$car = UniModel::model('pipi_auto')->find($app->car_id);
$model = UniModel::model('pipi_brand_models')->find($car->model_id);
$photo = UniModel::model('core_files')->find($model->photo_id);
$photo = url('api/files/file/' . ltrim($photo?->path, '/'));
$class_id = UniModel::model('pipi_auto_classes')->where('id', $model->class_id)->first();
$bodywork_id = UniModel::model('pipi_auto_bodywork')->where('id', $model->bodywork_id)->first();
$applications[] = [
'id' => $app->id,
'rent_day' => $app->rent_day,
'started_at' => $app->started_at,
'ended_at' => $app->ended_at,
'car' => [
'name' => $model->name,
'year' => $model->year,
'people' => $model?->people ?? '5',
'actuator' => $model?->actuator ?? 'Передний',
'fuel_type' => $model?->fuel_type ?? 'АКПП',
'hp' => $model?->hp ?? '1.6',
'engine_capacity' => $model?->engine_capacity ?? '1591',
'fuel_tank' => $model?->fuel_tank ?? '50',
'class' => $class_id->name ?? 'Эконом',
'bodywork' => $bodywork_id->name ?? 'Седан',
'photo' => $photo ?? '',
]
];
}
if (empty($applications)) {
$applications = (object) $applications;
}
return response()->json($applications);
}
public function login(Request $request)
@ -347,5 +399,60 @@ class MobileApiController extends Controller
]);
}
public function closeOrder(Request $request): JsonResponse
{
$order_id = $request->input('order_id');
$application = UniModel::model('pipi_applications')->find($order_id);
if (!isset($application)) {
return response()->json([
'success' => false,
'message' => __('Такой заявки не существует')
]);
}
if (count($request->file('photos')) != 5) {
return response()->json([
'success' => false,
'message' => __('Неверное количество фотографий')
]);
}
foreach ($request->file('photos') as $photo) {
$files[] = $this->uploadFile($photo);
}
$application->photos = $files;
$application->save();
return response()->json([
'success' => true,
'message' => __('Фото получены ожидайте закрытия заявки после проверки оператором'),
]);
}
private function uploadFile($file)
{
$ufile = UniModel::model(config('platform.file_manager.tables.files'));
$ufile->filename = $file->getClientOriginalName();
$ufile->path = $this->_gen_storage_file_name($file->getClientOriginalExtension());
$ufile->ext = $file->getClientOriginalExtension();
$ufile->size = $file->getSize();
$ufile->mime = $file->getClientMimeType();
$ufile->public = 1;
$ufile->user_file = 1;
$ufile->company_file = 1;
Storage::disk('file')->put($ufile->path, file_get_contents($file->getRealPath()));
$ufile->save();
return ['status' => 1, 'file_id' => $ufile->id, 'name' => 'photos', 'file_name' => $ufile->filename];
}
private function _gen_storage_file_name($ext): string
{
$storage_file_name = md5(time());
$folder1 = substr($storage_file_name, 0, 2);
$folder2 = substr($storage_file_name, 2, 3);
return $folder1 . '/' . $folder2 . '/' . $storage_file_name . '.' . $ext;
}
}

View File

@ -52,20 +52,24 @@ class Sync1cApiController extends Controller
if ($value['ПометкаУдаления'] == 'Да' or $value['НеИспользовать'] == 'Да') {
$class_id = UniModel::model('pipi_auto_classes', $segment->connector)
->first(['name' => $value['Класс']])?->id;
->where('name', $value['Класс'])->first()?->id;
$type_id = UniModel::model('pipi_auto_types', $segment->connector)
->first(['name' => $value['Тип']]);
->where('name', $value['Тип'])->first();
$brand_id = UniModel::model('pipi_auto_brands', $segment->connector)
->first(['name' => $value['Марка']]);
->where('name', $value['Марка'])->first();
$color_id = UniModel::model('pipi_auto_colors', $segment->connector)
->first(['name' => $value['Цвет']]);
->where('name', $value['Цвет'])->first();
$model = UniModel::model('pipi_brand_models', $segment->connector)
->first([
'name' => $value['Модель'],
'brand_id' => $brand_id?->id,
'year' => $this->formatDate($value['ГодПроизводства'])?->format('Y'),
]);
} else {
->where('name', $value['Модель'])
->where('brand_id', $brand_id?->id)
->where('year', $this->formatDate($value['ГодПроизводства'])?->format('Y'))
->first();
}
else {
$class_id = UniModel::model('pipi_auto_classes', $segment->connector)
->firstOrCreate(['name' => $value['Класс']])->id;
$type_id = UniModel::model('pipi_auto_types', $segment->connector)

View File

@ -24,6 +24,7 @@ class Seed
Nav::add(new NavItem('tariffs', '/app/pipicar.auto_tariffs', 1, 'Тарифы', ["admin"], 'car-front'), 'pipicar-nav-auto');
Nav::add(new NavItem('types', '/app/pipicar.auto_types', 1, 'Типы', ["admin"], 'car-front'), 'pipicar-nav-auto');
Nav::add(new NavItem('models', '/app/pipicar.brand_models', 1, 'Модели', ["admin"], 'car-front'), 'pipicar-nav-auto');
Nav::add(new NavItem('models', '/app/pipicar.auto_orders', 1, 'Заявки', ["admin"], 'car-front'), 'pipicar-nav-auto');
}
private static function nav(): void
{}

View File

@ -1,8 +1,190 @@
{
"module": "pipicar",
"name": "users",
"title": "Избранное",
"description": "'Учет.Главная'",
"type": "custom",
"class": "App.Modules.main.Applications.Main"
"name": "pipicar.auto_orders",
"type": "crud",
"title": "Заявки",
"withHeader": false,
"data": {
"table": "pipi_applications",
"pk": "id",
"limit": 25,
"segment": true,
"timestamp": false,
"fields": {
"id": {
"type": "pk"
},
"car_id": {
"type": "foreign",
"table": "pipi_auto",
"foreign": "id",
"display": [
"name"
],
"validation": "required|integer"
},
"user_id": {
"type": "foreign",
"table": "core_users",
"foreign": "id",
"display": [
"name"
],
"validation": "required|integer"
},
"phone": {
"type": "string"
},
"status": {
"type": "string"
},
"user_name": {
"type": "string"
},
"user_surname": {
"type": "string"
},
"user_email": {
"type": "string"
},
"started_at": {
"type": "date",
"validation": "required|date"
},
"ended_at": {
"type": "date",
"validation": "required|date"
},
"photos": {
"type": "json",
"validation": "nullable"
}
}
},
"ui": {
"grid": {
"title": "Заявки",
"component": "App.components.Grid",
"cols": [
{ "name": "id", "caption": "ID" },
{ "name": "car_id", "caption": "Машина" },
{ "name": "user_id", "caption": "Пользователь" },
{ "name": "phone", "caption": "Телефон" },
{ "name": "status", "caption": "Статус" },
{ "name": "user_name", "caption": "Имя" },
{ "name": "user_surname", "caption": "Фамилия" },
{ "name": "user_email", "caption": "Email" },
{ "name": "started_at", "caption": "Начало" },
{ "name": "ended_at", "caption": "Окончания" }
],
"action": {
"head": [
"add"
],
"row": [
"edit",
"delete"
]
},
"filter": {
"template": "app.base.crud.filter",
"rows": [
{
"cols": [
{
"size": 6,
"input": {
"name": "car_id",
"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": "car_id", "label": "Машина" } },
{ "size": 6, "input": { "name": "user_id", "label": "Пользователь" } }
]
},
{
"cols": [
{ "size": 6, "input": { "name": "phone", "label": "Телефон" } },
{ "size": 6, "input": { "name": "status", "label": "Статус" } }
]
},
{
"cols": [
{ "size": 6, "input": { "name": "user_name", "label": "Имя" } },
{ "size": 6, "input": { "name": "user_surname", "label": "Фамилия" } }
]
},
{
"cols": [
{ "size": 6, "input": { "name": "user_email", "label": "Email" } },
{ "size": 6, "input": { "name": "started_at", "label": "Начало" } }
]
},
{
"cols": [
{ "size": 6, "input": { "name": "ended_at", "label": "Окончания" } },
{ "size": 6, "input": { "name": "photos", "label": "Фотографии", "type": "files"} }
]
}
]
}
},
"edit": {
"title": "Заявки",
"template": "app.base.crud.form",
"component": "App.components.Show",
"form": {
"rows": [
{
"cols": [
{ "size": 6, "input": { "name": "car_id", "label": "Машина" } },
{ "size": 6, "input": { "name": "user_id", "label": "Пользователь" } }
]
},
{
"cols": [
{ "size": 6, "input": { "name": "phone", "label": "Телефон" } },
{ "size": 6, "input": { "name": "status", "label": "Статус" } }
]
},
{
"cols": [
{ "size": 6, "input": { "name": "user_name", "label": "Имя" } },
{ "size": 6, "input": { "name": "user_surname", "label": "Фамилия" } }
]
},
{
"cols": [
{ "size": 6, "input": { "name": "user_email", "label": "Email" } },
{ "size": 6, "input": { "name": "started_at", "label": "Начало" } }
]
},
{
"cols": [
{ "size": 6, "input": { "name": "ended_at", "label": "Окончания" } },
{ "size": 6, "input": { "name": "photos", "label": "Фотографии", "type": "files"} }
]
}
],
"submits": "struct:crud.form.edit.submits"
}
}
}
},
"actions": "struct:crud.actions"
}

View File

@ -42,6 +42,12 @@ return new class extends \A7kz\Platform\Commands\InstallScript {
$table->softDeletes();
});
}
if (!Schema::connection($segment->connector)->hasColumn('pipi_applications', 'photos')) {
Schema::connection($segment->connector)->table('pipi_applications', static function (Blueprint $table) {
$table->json('photos')->nullable();
});
}
}
}
};

View File

@ -31,6 +31,7 @@ Route::prefix('mobile')->group(function () {
Route::post('sendApplication', [MobileApiController::class, 'sendApplication']);
Route::post('getApplications', [MobileApiController::class, 'getApplications']);
Route::post('getSum', [MobileApiController::class, 'getSum']);
Route::post('closeOrder', [MobileApiController::class, 'closeOrder']);
Route::post('login', [MobileApiController::class, 'login']);
});