Доработка апи
parent
ee0f52a4c7
commit
33ddc91e79
|
|
@ -268,6 +268,7 @@ class MobileApiController extends Controller
|
|||
'fuel_tank' => $mark?->fuel_tank ?? '50',
|
||||
'class' => $class->name ?? 'Эконом',
|
||||
'bodywork' => $bodywork->name ?? 'Седан',
|
||||
'deposit' => $tariffs_new[0]['deposit'] ?? '30000',
|
||||
'conditioner' => $mark?->conditioner,
|
||||
'photo' => $colorPath,
|
||||
'tariffs' => $tariffs_new,
|
||||
|
|
@ -303,4 +304,55 @@ class MobileApiController extends Controller
|
|||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public function getSum(Request $request)
|
||||
{
|
||||
$started_at = $request->input('started_at');
|
||||
$ended_at = $request->input('ended_at');
|
||||
$mark_id = $request->input('mark_id');
|
||||
|
||||
$start = Carbon::createFromFormat('d-m-Y H:i', $started_at);
|
||||
$end = Carbon::createFromFormat('d-m-Y H:i', $ended_at);
|
||||
$days = $start->diffInDays($end);
|
||||
|
||||
// Получаем тарифы
|
||||
$tariffs = UniModel::model('pipi_auto_tariffs')
|
||||
->where('model_id', $mark_id)
|
||||
->get();
|
||||
if (!isset($tariffs)) {
|
||||
return response()->json(__('Отсутсвуют данные по машине'));
|
||||
}
|
||||
|
||||
$discountRate = null;
|
||||
$basePrice = null;
|
||||
|
||||
foreach ($tariffs as $range) {
|
||||
if ($range->day_range_start == 1 && $range->day_range_end == 2) {
|
||||
$basePrice = $range->base_rate;
|
||||
}
|
||||
|
||||
if ($days >= $range->day_range_start && $days <= $range->day_range_end) {
|
||||
$discountRate = $range->base_rate;
|
||||
}
|
||||
}
|
||||
|
||||
// Если не нашли подходящий тариф, но дней больше 30 — применяем скидку
|
||||
if (is_null($discountRate) && $days > 30 && count($tariffs) > 0) {
|
||||
$discountRate = round($tariffs[0]->base_rate * 0.6);
|
||||
}
|
||||
|
||||
// Считаем суммы
|
||||
$baseSum = $basePrice ? $basePrice * $days : null;
|
||||
$discountedSum = $discountRate ? $discountRate * $days : null;
|
||||
|
||||
return response()->json([
|
||||
'days' => $days,
|
||||
'base_price_per_day' => $basePrice,
|
||||
'discount_price_per_day' => $discountRate,
|
||||
'base_sum' => $baseSum,
|
||||
'discounted_sum' => $discountedSum,
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -30,6 +30,7 @@ Route::prefix('mobile')->group(function () {
|
|||
Route::post('checkAvailableCar', [MobileApiController::class, 'checkAvailableCar']);
|
||||
Route::post('sendApplication', [MobileApiController::class, 'sendApplication']);
|
||||
Route::post('getApplications', [MobileApiController::class, 'getApplications']);
|
||||
Route::post('getSum', [MobileApiController::class, 'getSum']);
|
||||
Route::post('login', [MobileApiController::class, 'login']);
|
||||
});
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue