'error', 'message' => '로그인이 필요합니다.']); exit; } if (empty($_SESSION['mypage_verified'])) { http_response_code(403); echo json_encode(['status' => 'error', 'message' => '마이페이지 인증이 필요합니다.']); exit; } $userId = $_SESSION['login']['user_id']; /* ========================= 페이징 파라미터 ========================= */ $page = max(1, intval($_GET['page'] ?? 1)); $pageSize = 5; $offset = ($page - 1) * $pageSize; try { /* ========================= 1. 내 정보 ========================= */ $stmt = $pdo->prepare("SELECT * FROM kngil.sp_users_my_r(:user_id)"); $stmt->execute([':user_id' => $userId]); $user = $stmt->fetch(PDO::FETCH_ASSOC); if (!$user) { echo json_encode(['status' => 'error', 'message' => '사용자 정보 없음']); exit; } /* ========================= 2. 전체 건수 ========================= */ $cntStmt = $pdo->prepare(" SELECT COUNT(*) FROM kngil.use_history WHERE user_id = :user_id "); $cntStmt->execute([':user_id' => $userId]); $totalCount = (int)$cntStmt->fetchColumn(); $totalPages = (int)ceil($totalCount / $pageSize); /* ========================= 3. 현재 페이지 데이터 ========================= */ $histStmt = $pdo->prepare(" SELECT * FROM kngil.sp_users_my_history(:user_id) OFFSET :offset LIMIT :limit "); $histStmt->bindValue(':user_id', $userId, PDO::PARAM_STR); $histStmt->bindValue(':offset', $offset, PDO::PARAM_INT); $histStmt->bindValue(':limit', $pageSize, PDO::PARAM_INT); $histStmt->execute(); $history = $histStmt->fetchAll(PDO::FETCH_ASSOC); echo json_encode([ 'status' => 'success', 'user' => $user, 'history' => $history, 'pagination' => [ 'page' => $page, 'pageSize' => $pageSize, 'totalCount' => $totalCount, 'totalPages' => $totalPages ] ]); } catch (Exception $e) { http_response_code(500); echo json_encode([ 'status' => 'error', 'message' => '서버 오류', 'detail' => $e->getMessage() ]); }