service = $service; } /** * @param Request $request * @return JsonResponse */ public function index(Request $request): JsonResponse { try { $query = ParkingProhibitedPassage::query(); if ($request->has('license_plate')) { $license_plate = $request->input('license_plate'); if ($license_plate) { $license_plate_id = ParkingLicensePlate::getValueId( $license_plate ); if ($license_plate_id) { $query->where('license_plate_id', $license_plate_id); } else { $query->where('id', 0); } } } if ($request->has('parking_id')) { $parking_id = $request->input('parking_id'); if ($parking_id) { $query->where('parking_id', $parking_id); } } if ($request->has('start_date')) { $start_date = $request->input('start_date'); if ($start_date) { $query->where( 'identify_at', '>=', $start_date . ' 00:00:00' ); } } if ($request->has('end_date')) { $end_date = $request->input('end_date'); if ($end_date) { $query->where('identify_at', '<=', $end_date . ' 23:59:59'); } } $typeArr = $this->service->getType(); $remarkArr = $this->service->getRemark(); // 分页 $page = $request->input('page', 1); $perPage = $request->input('per_page', 10); $total = $query->count(); $items = $query->latest()->forPage($page, $perPage)->get()->each( function ($item) use ($typeArr, $remarkArr) { $item['license_plate'] = ParkingLicensePlate::getNumber( $item['license_plate_id'] ); $item['parking'] = Parking::getName($item['parking_id']); $item['type_str'] = $typeArr[$item['type']]; $item['remark'] = $remarkArr[$item['remark']]; $item['snapshot_img'] = get_image_url($item['snapshot_img']); unset($item['parking_id'], $item['license_plate_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() ); } } }