get('building_floor', ''); $floorModel = AdminFloor::query(); if ($building_floor) { $floorModel->where('building_floor', $building_floor); } // 获取当前模式下的车位编号 $targetMode = EventCalendarService::targetModel(); $pattern_id = $targetMode['pattern_id']; $spaceIds = ParkingPatternSpace::getParkingSpaceIds($pattern_id); // 获取楼层 $statusArr = [0, 1]; $floorData = $floorModel->select(['id', 'name'])->get()->toArray(); foreach ($floorData as $item) { $floor_id = $item['id']; $floor_name = $item['name']; $sum_count = ParkingSpace::query()->where('floor_id', $floor_id) ->whereIn('status', $statusArr)->whereIn('id', $spaceIds) ->count(); $vacant_count = ParkingSpace::query()->where( 'floor_id', $floor_id )->where('status', 0)->whereIn('id', $spaceIds)->count(); $repair_count = ParkingSpace::query()->where( 'floor_id', $floor_id )->where('status', 2)->whereIn('id', $spaceIds) ->count(); // 获取当前模式 楼层车位类型 $typeData = []; $spaceTypeIds = ParkingSpace::query()->where( 'floor_id', $floor_id )->wherein('status', $statusArr)->whereIn('id', $spaceIds) ->pluck('space_type_id'); if ($spaceTypeIds) { $typeData = ParkingSpaceType::query()->whereIn( 'id', $spaceTypeIds )->select(['id', 'name', 'default_color_vacant'])->get()->toArray(); } $type_list = []; foreach ($typeData as $typeItem) { $spaceWhere = [ 'floor_id' => $floor_id, 'space_type_id' => $typeItem['id'] ]; $ParkingSpace = ParkingSpace::query()->where($spaceWhere) ->whereIn('status', $statusArr) ->whereIn('id', $spaceIds) ->select(['status', 'space_attr_id'])->get()->toArray(); $type_count = 0; $temp_attr_list = []; $attr_list = []; foreach ($ParkingSpace as $item) { if (!isset($temp_attr_list[$item['space_attr_id']]['count'])) { $temp_attr_list[$item['space_attr_id']]['count'] = 0; } $temp_attr_list[$item['space_attr_id']]['count'] += 1; if (!isset($temp_attr_list[$item['space_attr_id']]['vacant_count'])) { $temp_attr_list[$item['space_attr_id']]['vacant_count'] = 0; } if ($item['status'] != 1){ $temp_attr_list[$item['space_attr_id']]['vacant_count'] += 1; $type_count += 1; } } // 车位属性数据 foreach ($temp_attr_list as $space_attr_id => $attr_item) { $color = $typeItem['default_color_vacant']; $color_vacant = ParkingSpaceTypeAttr::query()->where([ 'space_type_id' => $typeItem['id'], 'space_attr_id' => $space_attr_id ])->value('color_vacant'); if ($color_vacant) { $color = $color_vacant; } $attr_list[] = [ 'attr_name' => ParkingSpaceAttributes::getAttr( $space_attr_id ), 'count' => $attr_item['count'], 'vacant_count' => $attr_item['vacant_count'], 'color' => $color ]; } $type_name = AdminTranslationService::getTranslationTypeName( $typeItem['id'], 1, $typeItem['name'] ); $type_list[] = [ 'count' => $type_count, 'attr_list' => $attr_list, 'type_count' => $typeItem['default_color_vacant'], 'name' => $type_name ]; } $data[] = [ 'floor_name' => $floor_name, 'sum_count' => $sum_count, 'vacant_count' => $vacant_count, 'parking_space_type_list' => $type_list, 'repair_count' => $repair_count ]; } return $this->responseService->success($data); } catch (Exception $e) { $m_prefix = __('exception.get_data_failed'); return $this->responseService->systemError( $m_prefix . ':' . $e->getMessage() ); } } public function parkingSpaceStatistics() { try { $targetMode = EventCalendarService::targetModel(); $pattern_id = $targetMode['pattern_id'] ?? 0; $spaceIds = ParkingPatternSpace::getParkingSpaceIds($pattern_id); $sum = 0; $use_sum = 0; if ($spaceIds) { $sum = ParkingSpace::query()->whereIn('status', [0, 1]) ->whereIn('id', $spaceIds)->count(); $use_sum = ParkingSpace::query()->where('status', 1)->whereIn( 'id', $spaceIds )->count(); } $date['proportion'] = get_ratio($sum, $use_sum); return $this->responseService->success($date); } catch (Exception $e) { $m_prefix = __('exception.get_data_failed'); return $this->responseService->systemError( $m_prefix . ':' . $e->getMessage() ); } } public function menu(): JsonResponse { try { $data = (new AdminMenuService( new OperationLogService() ))->getUserMenuTreeList( $this->adminUserId ); return $this->responseService->success($data); } catch (Exception $e) { $m_prefix = __('exception.get_data_failed'); return $this->responseService->systemError( $m_prefix . ':' . $e->getMessage() ); } } }