停车场管理系统
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.
 
 

183 lines
5.0 KiB

<?php
namespace App\Services;
use App\Models\AdminFloor;
use App\Models\Parking;
use App\Models\ParkingAbnormal;
use App\Models\ParkingLicensePlate;
use App\Models\ParkingReservation;
use App\Models\ParkingSpace;
use App\Models\ParkingSpaceAttributes;
use App\Models\ParkingSpaceType;
use Exception;
use Illuminate\Support\Facades\DB;
class ParkingAbnormalService extends BaseService
{
public array $typeArr
= [
1 => 'occupancy',
];
public array $statusArr
= [
'unprocessed',
'processed'
];
public array $operationTypeArr
= [
1 => 'handle',
2 => 'ignore'
];
public array $reasonArr
= [
1 => 'reason1',
2 => 'reason2',
3 => 'reason3',
4 => 'reason4'
];
public array $dateArr
= [
1 => 'today',
2 => 'days3',
3 => 'week',
4 => 'month',
5 => 'month3'
];
protected string $menuTitle = 'abnormal_resource_usage';
/**
* @return array|string[]
*/
public function getDateArr(): array
{
$dateArr = $this->dateArr;
foreach ($dateArr as $key => $value) {
$dateArr[$key] = __service($this->menuTitle . '.' . $value);
}
return $dateArr;
}
public function getItem($item)
{
$item['parking'] = Parking::getName($item['parking_id']);
$ParkingSpace = ParkingSpace::query()->find($item['space_id']);
$item['floor'] = '';
$item['parking_space_number'] = '';
$item['parking_space_type'] = '';
$item['parking_space_attr'] = '';
if ($ParkingSpace) {
$item['floor'] = AdminFloor::getName($ParkingSpace['floor_id']);
$item['parking_space_number'] = $ParkingSpace['number'];
$item['parking_space_type'] = ParkingSpaceType::getName(
$ParkingSpace['space_type_id']
);
$item['parking_space_attr'] = ParkingSpaceAttributes::getAttr(
$ParkingSpace['space_attr_id']
);
}
$item['license_plate'] = ParkingLicensePlate::getNumber(
$item['license_plate_id']
);
$item['duration'] = get_time_difference_str($item['enter_at']);
$typeArr = $this->getType();
$item['type'] = $typeArr[$item['type']];
$statusArr = $this->getStatus();
$item['status'] = $statusArr[$item['status']];
$operationTypeArr = $this->getOperationType();
$item['operation_type'] = $operationTypeArr[$item['operation_type']] ??
'';
$reasonArr = $this->getReason();
$item['reason'] = $reasonArr[$item['reason']] ?? '';
$item['reservation_id'] = ParkingReservation::getReserveId(
$item['reservation_id']
);
unset(
$item['parking_id'],
$item['space_id'],
$item['license_plate_id']
);
return $item;
}
/**
* @return array|string[]
*/
public function getType(): array
{
$typeArr = $this->typeArr;
foreach ($typeArr as $key => $value) {
$typeArr[$key] = __service($this->menuTitle . '.' . $value);
}
return $typeArr;
}
/**
* @return array|string[]
*/
public function getStatus(): array
{
$typeArr = $this->statusArr;
foreach ($typeArr as $key => $value) {
$typeArr[$key] = __service($this->menuTitle . '.' . $value);
}
return $typeArr;
}
/**
* @return array|string[]
*/
public function getOperationType(): array
{
$operationTypeArr = $this->operationTypeArr;
foreach ($operationTypeArr as $key => $value) {
$operationTypeArr[$key] = __service(
$this->menuTitle . '.' . $value
);
}
return $operationTypeArr;
}
/**
* @return array|string[]
*/
public function getReason(): array
{
$reasonArr = $this->reasonArr;
foreach ($reasonArr as $key => $value) {
$reasonArr[$key] = __service($this->menuTitle . '.' . $value);
}
return $reasonArr;
}
public function updateOperationType($id, $reason, $operation_type = 1)
{
try {
DB::beginTransaction();
$model = ParkingAbnormal::query()->findOrFail($id);
$oldValue = $model->toArray();
$model->update([
'operation_type' => $operation_type,
'handle_reason' => $reason,
'operation_at' => get_datetime(),
'updated_at' => get_datetime()
]);
$this->logService->logUpdated(
$model,
$oldValue,
$this->menuTitle . '.operation'
);
DB::commit();
return $model;
} catch (Exception $e) {
DB::rollBack();
throw $e;
}
}
}