81 lines
3.2 KiB
PHP
81 lines
3.2 KiB
PHP
<?php
|
||
|
||
namespace App\Http\Controllers;
|
||
|
||
use A7kz\Platform\Models\UniModel;
|
||
use A7kz\Platform\Modules\Platform\Segment\Facades\Segment;
|
||
use App\Modules\applications\Enum\ApplicationStatus;
|
||
use Exception;
|
||
use Illuminate\Http\JsonResponse;
|
||
use Illuminate\Http\Request;
|
||
use Illuminate\Support\Carbon;
|
||
use Illuminate\Support\Facades\DB;
|
||
use Illuminate\Support\Facades\Log;
|
||
use Illuminate\Support\Facades\Notification;
|
||
use Illuminate\Support\Facades\Storage;
|
||
use Mpdf\Tag\Mark;
|
||
|
||
class MobileApiController extends Controller
|
||
{
|
||
public function getMarks(): JsonResponse {
|
||
$data = [];
|
||
$marks = UniModel::model('pipi_brand_models')->get();
|
||
if (!isset($marks)) {
|
||
return response()->json();
|
||
}
|
||
foreach ($marks as $mark) {
|
||
$brand = UniModel::model('pipi_auto_brands')->find($mark->brand_id);
|
||
$tariffs = UniModel::model('pipi_auto_tariffs')->where('model_id', $mark->id)->get();
|
||
if ($mark->name != 'Ввод остатков') {
|
||
foreach ($tariffs as $tariff) {
|
||
$tariffs_new[$tariff?->day_range_start . '-' . $tariff->day_range_end] = [
|
||
'name' => $tariff?->name,
|
||
'price' => $tariff?->base_rate,
|
||
'min' => $tariff?->day_range_start,
|
||
'max' => $tariff?->day_range_end,
|
||
];
|
||
}
|
||
$data[$mark->name . '-' . $mark->year] = [
|
||
'id' => $mark->id,
|
||
'brand' => $brand->name,
|
||
'mark' => $mark->name,
|
||
'year' => $mark->year,
|
||
'tariffs' => $tariffs_new
|
||
];
|
||
}
|
||
}
|
||
return response()->json($data);
|
||
}
|
||
|
||
public function sendApplication(Request $request): JsonResponse {
|
||
$data = $request->all();
|
||
$data['started_at'] = Carbon::parse($data['started_at'])?->format('Y-m-d H:i:s');
|
||
$data['ended_at'] = Carbon::parse($data['ended_at'])?->format('Y-m-d H:i:s');
|
||
$data['user_id'] = UniModel::model('core_users')
|
||
->where('email',$data['email'])->first()?->id;
|
||
$data['car_id'] = null;
|
||
UniModel::model('pipi_applications')->create([
|
||
'rent_day' => $data['rent_day'],
|
||
'started_at' => $data['started_at'],
|
||
'ended_at' => $data['ended_at'],
|
||
'user_id' => $data['user_id'],
|
||
'phone' => $data['phone'],
|
||
'car_id' => $data['car_id'],
|
||
'user_name' => $data['name'] ?? null,
|
||
'user_surname' => $data['surname'] ?? null,
|
||
'user_email' => $data['email'] ?? null,
|
||
'status' => ApplicationStatus::pending->value
|
||
]);
|
||
|
||
if (!isset($data['user_id'])) {
|
||
return response()->json(['status' => 'OK', 'message' => 'Заявка создана, с вами свяжется наш оператор']);
|
||
}
|
||
return response()->json(['status' => 'OK', 'message' => 'Заявка создана']);
|
||
}
|
||
|
||
public function getApplications(): JsonResponse
|
||
{
|
||
return response()->json(UniModel::model('pipi_applications')->get());
|
||
}
|
||
}
|