responseService = $responseService; $this->service = $service; } public function index(Request $request): JsonResponse { try { $query = ParkingReservation::query(); // 车牌号码搜索 if ($request->has('license_plate')) { $license_plate = $request->input('license_plate'); if (!empty($license_plate)) { $license_plate_id_arr = ParkingLicensePlate::query()->where( 'number', 'like', "%{$license_plate}%" )->pluck('id'); $license_plate_id_arr ? $query->whereIn( 'license_plate_id', $license_plate_id_arr ) : $query->where('id', 0); } } // 楼层 if ($request->has('floor_id')) { $floor_id = $request->input('floor_id'); if (!empty($floor_id)) { $query->where('floor_id', $floor_id); } } if ($request->has('space_number')) { $space_number = $request->input('space_number'); if (!empty($space_number)) { $license_plate_id_arr = ParkingSpace::query()->where( 'number', $space_number )->pluck('license_plate_id'); $license_plate_id_arr ? $query->whereIn( 'license_plate_id', $license_plate_id_arr ) : $query->where('id', 0); } } if ($request->has('space_type_id')) { $space_type_id = $request->input('space_type_id'); if (!empty($space_type_id)) { $query->where('space_type_id', $space_type_id); } } if ($request->has('space_attr_id')) { $space_attr_id = $request->input('space_attr_id'); if (!empty($space_attr_id)) { } } if ($request->has('status')) { $status = $request->input('status'); if (!empty($status)) { $query->where('status', $status); } } // 分页 $page = $request->input('page', 1); $perPage = $request->input('per_page', 10); $total = $query->count(); $items = $query->latest()->forPage($page, $perPage)->get()->each( function ($item) { $item['status'] = $this->service->getStatusStr( $item['status'] ); $item['space_type'] = ParkingSpaceType::getName( $item['space_type_id'] ); $item['license_plate'] = ParkingLicensePlate::getNumber( $item['license_plate_id'] ); $item['is_driver'] = $this->service->getIsDriver( $item['is_driver'] ); $item['floor'] = AdminFloor::getName($item['floor_id']); $item['floor_region'] = AdminFloorRegion::getName($item['floor_region_id']); unset( $item['space_type_id'], $item['license_plate_id'], $item['floor_id'], $item['floor_region_id'] ); return $item; } ); return $this->responseService->success([ 'items' => $items, 'total' => $total, 'page' => $page, 'per_page' => $perPage, 'last_page' => ceil($total / $perPage) ]); } catch (Exception $e) { $m_prefix = __('exception.exception_handler.resource'); return $this->responseService->systemError( $m_prefix . ':' . $e->getMessage() ); } } public function search(): JsonResponse { try { $data = [ 'floor_data' => AdminFloor::getData(), 'space_type_data' => ParkingSpaceType::getData(), 'space_attr_data' => ParkingSpaceAttributes::getData(), 'status_data' => get_select_data( $this->service->getStatusArr() ) ]; return $this->responseService->success($data); } catch (Exception $e) { $m_prefix = __('exception.exception_handler.resource'); return $this->responseService->systemError( $m_prefix . ':' . $e->getMessage() ); } } public function statistics(Request $request): JsonResponse { try { $start_at = date("Y-m-d 00:00:00"); $end_at = date("Y-m-d 23:59:59"); if ($request->has('appointment_date')) { $appointment_date = $request->input('appointment_date'); if (!empty($appointment_date)) { $start_at = date( "Y-m-d 00:00:00", strtotime($appointment_date) ); $end_at = date( "Y-m-d 23:59:59", strtotime($appointment_date) ); } } $today_count = $this->service->getCount($start_at, $end_at); $present_count = $this->service->getBePresentCount( $start_at, $end_at ); $absent_count = $today_count - $present_count; $data = [ 'today_count' => $today_count, 'present_count' => $present_count, 'absent_count' => max($absent_count, 0) ]; return $this->responseService->success($data); } catch (Exception $e) { $m_prefix = __('exception.exception_handler.resource'); return $this->responseService->systemError( $m_prefix . ':' . $e->getMessage() ); } } }