service = $service; } public function index(Request $request): JsonResponse { try { $query = $this->service->searchQuery($request->all()); // 分页 $page = $request->input('page', 1); $perPage = $request->input('per_page', 10); $total = $query->count(); $items = $query->latest()->forPage($page, $perPage)->select()->get() ->each(function ($item) { return $this->service->getItem($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 illustration(Request $request): JsonResponse { try { $data = []; $query = $this->service->searchQuery($request->all()); $list = $query->select()->get()->toArray(); $tempData = []; foreach ($list as $item) { $date_type = $item['date_type']; $format = 'H:i'; if ($date_type == 2) { $format = 'm/d'; } $key = date($format, strtotime($item['end_time'])); $tempData[$key][] = $item['rate']; } foreach ($tempData as $date => $value) { $count = count($value); $sum = 0; foreach ($value as $val) { $sum += $val; } $rate = 0; if ($sum > 0) { $rate = round($sum / $count, 2); } $data[] = [ 'time' => $date, 'rate' => $rate ]; } return $this->responseService->success($data); } catch (Exception $e) { $m_prefix = __('exception.exception_handler.resource'); return $this->responseService->systemError( $m_prefix . ':' . $e->getMessage() ); } } public function search(): JsonResponse { try { $data = [ 'floor_list' => AdminFloor::getData(), 'space_type_list' => ParkingSpaceType::getData() ]; return $this->responseService->success($data); } catch (Exception $e) { $m_prefix = __('exception.exception_handler.resource'); return $this->responseService->systemError( $m_prefix . ':' . $e->getMessage() ); } } /** * @param Request $request * @return BinaryFileResponse */ public function export(Request $request): BinaryFileResponse { return Excel::download( new UtilizationRateExport($request->all()), set_space_underline(__('exports.access_record.list')) . get_datetime('date_') . '.xlsx' ); } }