|
|
|
@ -2,6 +2,7 @@ |
|
|
|
|
|
|
|
namespace App\Services; |
|
|
|
|
|
|
|
use App\Exceptions\CustomException; |
|
|
|
use App\Models\AdminFloor; |
|
|
|
use App\Models\ParkingLicensePlate; |
|
|
|
use App\Models\ParkingSpace; |
|
|
|
@ -16,6 +17,8 @@ use Illuminate\Support\Facades\DB; |
|
|
|
class ParkingSpaceService extends BaseService |
|
|
|
{ |
|
|
|
|
|
|
|
public string $adminUserId = '0'; |
|
|
|
|
|
|
|
protected int $recognition = 80; |
|
|
|
/** |
|
|
|
* @var string[] |
|
|
|
@ -35,20 +38,6 @@ class ParkingSpaceService extends BaseService |
|
|
|
$this->logService->menuTitle = 'cat_list'; |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 返回翻译后的状态 |
|
|
|
* @param $status |
|
|
|
* @return string |
|
|
|
*/ |
|
|
|
public function getStatusStr($status): string |
|
|
|
{ |
|
|
|
$value = $this->statusArr[$status] ?? ''; |
|
|
|
if ($value) { |
|
|
|
return __('service.parking_space.' . $value); |
|
|
|
} |
|
|
|
return $value; |
|
|
|
} |
|
|
|
|
|
|
|
public function getRecognition($recognition): string |
|
|
|
{ |
|
|
|
if ($recognition) { |
|
|
|
@ -67,6 +56,7 @@ class ParkingSpaceService extends BaseService |
|
|
|
return '-'; |
|
|
|
} |
|
|
|
|
|
|
|
// 获取翻译后的状态数据列表 |
|
|
|
public function getStatusArr($is_child = false): array |
|
|
|
{ |
|
|
|
$arr = []; |
|
|
|
@ -84,9 +74,56 @@ class ParkingSpaceService extends BaseService |
|
|
|
return $arr; |
|
|
|
} |
|
|
|
|
|
|
|
// 获取状态显示值 |
|
|
|
public function getParkingSpaceStatus($status, $license_plate_id = '') |
|
|
|
{ |
|
|
|
$statusArr = $this->getStatusArr(true); |
|
|
|
// 是否有车 |
|
|
|
$yesStr = ''; |
|
|
|
$noStr = ''; |
|
|
|
if ($license_plate_id) { |
|
|
|
$yesStr = $statusArr['children'][1][3]; |
|
|
|
} else { |
|
|
|
$noStr = $statusArr['children'][1][4]; |
|
|
|
} |
|
|
|
if ($status == '1') { |
|
|
|
// 占用 是否有车 |
|
|
|
$str = $yesStr ?: $noStr; |
|
|
|
return $statusArr[1] . '/' . $str; |
|
|
|
} elseif ($status == '2') { |
|
|
|
return $statusArr[$status]; |
|
|
|
} else { |
|
|
|
$status_str = $statusArr[$status] ?? ''; |
|
|
|
if ($status_str) { |
|
|
|
// 空闲 是否有车 |
|
|
|
if ($status < 1) { |
|
|
|
return $yesStr ? $status_str . '/' . $yesStr : $status_str; |
|
|
|
} |
|
|
|
} |
|
|
|
return ''; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
// 获取查询状态条件 |
|
|
|
public function getStatusWhere($status) |
|
|
|
{ |
|
|
|
$where = [['status', '=', 1]]; |
|
|
|
if ($status == 4) { |
|
|
|
// 无车牌 |
|
|
|
$where[] = ['license_plate_id', '=', 0]; |
|
|
|
} elseif ($status == 3) { |
|
|
|
// 有车牌 |
|
|
|
$where[] = ['license_plate_id', '>=', 1]; |
|
|
|
} else { |
|
|
|
$where = [['status', '=', $status]]; |
|
|
|
} |
|
|
|
return $where; |
|
|
|
} |
|
|
|
|
|
|
|
// 获取状态的值 |
|
|
|
public function getStatusArrKey(): array |
|
|
|
{ |
|
|
|
return array_keys($this->statusArr); |
|
|
|
return [0,1,2,3,4]; |
|
|
|
} |
|
|
|
|
|
|
|
public function optionItems($item) |
|
|
|
@ -105,7 +142,7 @@ class ParkingSpaceService extends BaseService |
|
|
|
$item['recognition'] = $this->getRecognition( |
|
|
|
$item['recognition'] |
|
|
|
); |
|
|
|
$item['status'] = $this->getStatusStr( |
|
|
|
$item['status'] = $this->getParkingSpaceStatus( |
|
|
|
$item['status'] |
|
|
|
); |
|
|
|
$item['operation_type'] = $this->getOperationType( |
|
|
|
@ -124,6 +161,7 @@ class ParkingSpaceService extends BaseService |
|
|
|
* @param string $key |
|
|
|
* @return Builder |
|
|
|
* @throws Exception |
|
|
|
* @throws CustomException |
|
|
|
*/ |
|
|
|
public function updateData( |
|
|
|
array $data, |
|
|
|
@ -137,6 +175,9 @@ class ParkingSpaceService extends BaseService |
|
|
|
|
|
|
|
$model = ParkingSpace::query()->whereIn('id', $ids)->select(); |
|
|
|
$oldValues = $model->get()->toArray(); |
|
|
|
if (!$oldValues) { |
|
|
|
throw new CustomException(__service('parking_space.space_not')); |
|
|
|
} |
|
|
|
|
|
|
|
$updateData = [ |
|
|
|
$key => $data_id, |
|
|
|
@ -256,9 +297,22 @@ class ParkingSpaceService extends BaseService |
|
|
|
)->get()->toArray(); |
|
|
|
} |
|
|
|
|
|
|
|
// 更新状态和车牌 |
|
|
|
public function updateStatus($id, $status, $license_plate) |
|
|
|
{ |
|
|
|
/** |
|
|
|
* 更新状态和车牌 |
|
|
|
* @param $id // 车位id |
|
|
|
* @param $status // 车位状态 |
|
|
|
* @param $license_plate // 车牌号码 |
|
|
|
* @param $start_at // 维修开始时间 |
|
|
|
* @param $end_at // 维修结束时间 |
|
|
|
* @throws Exception |
|
|
|
*/ |
|
|
|
public function updateStatus( |
|
|
|
$id, |
|
|
|
$status, |
|
|
|
$license_plate, |
|
|
|
string $start_at = '', |
|
|
|
string $end_at = '' |
|
|
|
) { |
|
|
|
try { |
|
|
|
DB::beginTransaction(); |
|
|
|
$model = ParkingSpace::query()->findOrFail($id); |
|
|
|
@ -267,27 +321,60 @@ class ParkingSpaceService extends BaseService |
|
|
|
'status' => $status, |
|
|
|
'updated_at' => get_datetime() |
|
|
|
]; |
|
|
|
if (!empty($license_plate) && $status == 1) { |
|
|
|
$number_id = ParkingLicensePlate::getValueId($license_plate); |
|
|
|
if (!$number_id) { |
|
|
|
$licensePlateService = new ParkingLicensePlateService($this->logService); |
|
|
|
$create = [ |
|
|
|
'number' => $license_plate, |
|
|
|
'space_type_id' => $oldValues['space_type_id'] |
|
|
|
]; |
|
|
|
$licensePlateModel = $licensePlateService->createData($create); |
|
|
|
$number_id = $licensePlateModel->id; |
|
|
|
} |
|
|
|
if (!empty($license_plate) && $status == 3) { |
|
|
|
$licensePlateService = new ParkingLicensePlateService( |
|
|
|
$this->logService |
|
|
|
); |
|
|
|
$number_id = $licensePlateService->saveNumber( |
|
|
|
$license_plate, |
|
|
|
$oldValues['space_type_id'] |
|
|
|
); |
|
|
|
if ($number_id) { |
|
|
|
$update['license_plate_id'] = $number_id; |
|
|
|
$update['berthing_time'] = get_datetime(); |
|
|
|
$update['recognition'] = 'high'; |
|
|
|
$update['recognition'] = '90'; |
|
|
|
} |
|
|
|
$update['status'] = 1; |
|
|
|
} else if ($status == 4) { |
|
|
|
$update['license_plate_id'] = 0; |
|
|
|
$update['berthing_time'] = null; |
|
|
|
$update['recognition'] = ''; |
|
|
|
$update['status'] = 1; |
|
|
|
} else if (!$status) { |
|
|
|
$update['license_plate_id'] = 0; |
|
|
|
$update['berthing_time'] = null; |
|
|
|
$update['recognition'] = ''; |
|
|
|
} |
|
|
|
if ($status == 2) { |
|
|
|
// 维修 |
|
|
|
$now_times = time(); |
|
|
|
$start_times = strtotime($start_at);// 维修开始时间 |
|
|
|
$end_times = strtotime($end_at);// 维修结束时间 |
|
|
|
if (!$start_times) { |
|
|
|
throw new CustomException(__validation('parking_repair_list.s_empty')); |
|
|
|
} |
|
|
|
if (!$end_times) { |
|
|
|
throw new CustomException(__validation('parking_repair_list.e_empty')); |
|
|
|
} |
|
|
|
if ($start_times > $end_times) { |
|
|
|
throw new CustomException(__validation('parking_repair_list.date_error')); |
|
|
|
} |
|
|
|
$start_time = get_datetime('datetime', $start_times); |
|
|
|
$end_time = get_datetime('datetime', $end_times); |
|
|
|
$ParkingSpaceRepair = new ParkingSpaceRepairService( |
|
|
|
$this->logService |
|
|
|
); |
|
|
|
$ParkingSpaceRepair->createData( |
|
|
|
$id, |
|
|
|
$this->adminUserId, |
|
|
|
$start_time, |
|
|
|
$end_time |
|
|
|
); |
|
|
|
if ($start_times <= $now_times && $end_times >= $now_times) { |
|
|
|
$this->updateRepairStatus($id, 2); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
$model->update($update); |
|
|
|
$this->logService->logUpdated( |
|
|
|
$model, |
|
|
|
@ -516,4 +603,29 @@ class ParkingSpaceService extends BaseService |
|
|
|
$status == 2 |
|
|
|
); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 删除维修记录,则修改为空闲 |
|
|
|
* @param $space_id // 车位id |
|
|
|
* @param $start_at // 维修开始时间 |
|
|
|
* @param $end_at // 维修结束时间 |
|
|
|
* @return void |
|
|
|
*/ |
|
|
|
public function syncUpdateParkingSpaceStatus($space_id, $start_at, $end_at) |
|
|
|
{ |
|
|
|
// 判断是否维修记录在当前时间 |
|
|
|
$start_at_times = strtotime($start_at); |
|
|
|
$end_at_times = strtotime($end_at); |
|
|
|
$now_times = time(); |
|
|
|
$is_now = false; |
|
|
|
if ($start_at_times <= $now_times && $end_at_times >= $now_times) { |
|
|
|
$is_now = true; |
|
|
|
} |
|
|
|
// 判断车位状态是否在维修 |
|
|
|
$item = ParkingSpace::query()->find($space_id); |
|
|
|
if ($item['status'] == 2 && $is_now) { |
|
|
|
// 删除维修数据这撤销 |
|
|
|
$this->updateRepairStatus($space_id, 0); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|