You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
73 lines
1.8 KiB
73 lines
1.8 KiB
<?php
|
|
|
|
namespace App\Services;
|
|
|
|
use App\Models\ParkingReservation;
|
|
use App\Models\ParkingSpace;
|
|
|
|
class ParkingReservationService extends BaseService
|
|
{
|
|
/**
|
|
* @var string[]
|
|
*/
|
|
public array $statusArr = ['undetermined', 'confirmed', 'canceled'];
|
|
|
|
public array $isDriver = ['no', 'yes'];
|
|
|
|
/**
|
|
* 返回翻译后的状态
|
|
* @param $status
|
|
* @return string
|
|
*/
|
|
public function getStatusStr($status): string
|
|
{
|
|
$value = $this->statusArr[$status] ?? '';
|
|
if ($value) {
|
|
return __('service.reservation.' . $value);
|
|
}
|
|
return $value;
|
|
}
|
|
|
|
public function getStatusArr(): array
|
|
{
|
|
$arr = [];
|
|
foreach ($this->statusArr as $key => $value) {
|
|
$arr[$key] = __('service.reservation.' . $value);
|
|
}
|
|
return $arr;
|
|
}
|
|
|
|
public function getIsDriver($is_driver): string
|
|
{
|
|
$value = $this->isDriver[$is_driver] ?? '';
|
|
if ($value) {
|
|
return __('service.reservation.' . $value);
|
|
}
|
|
return $value;
|
|
}
|
|
|
|
/**
|
|
* @param string $start
|
|
* @param string $end
|
|
* @return int
|
|
*/
|
|
public function getCount(string $start, string $end): int
|
|
{
|
|
return ParkingReservation::query()->whereBetween(
|
|
'confirm_at',
|
|
[$start, $end]
|
|
)->where('status', 1)->count();
|
|
}
|
|
|
|
public function getBePresentCount(string $start, string $end): int
|
|
{
|
|
$license_plate_id_arr = ParkingReservation::query()->whereBetween(
|
|
'confirm_at',
|
|
[$start, $end]
|
|
)->where('status', 1)->pluck('license_plate_id');
|
|
return ParkingSpace::query()->whereIn(
|
|
'license_plate_id',
|
|
$license_plate_id_arr
|
|
)->count();
|
|
}
|
|
}
|
|
|