prepare(" SELECT * FROM kngil.fn_base_cd(:main_cd) "); $stmt->execute([ ':main_cd' => $main_cd ]); $rows = $stmt->fetchAll(PDO::FETCH_ASSOC); echo json_encode([ 'status' => 'success', 'items' => $rows // [{id, text}] ]); break; /* ========================= 1. 사용자 목록 조회 ========================= */ case 'list': $schType = $_GET['sch_type'] ?? ''; $schKeyword = $_GET['sch_keyword'] ?? ''; $schUseYn = $_GET['sch_use_yn'] ?? ''; // 기본값 $sch_id = ''; $sch_nm = ''; $sch_dept = ''; if ($schKeyword !== '') { switch ($schType) { case 'id': $sch_id = $schKeyword; break; case 'name': $sch_nm = $schKeyword; break; case 'dept': $sch_dept = $schKeyword; break; default: // 전체 $sch_id = $schKeyword; $sch_nm = $schKeyword; $sch_dept = $schKeyword; } } $sql = " SELECT * FROM kngil.sp_users_r( :member_id, :user_nm, :dept_nm, :use_yn ); "; $stmt = $pdo->prepare($sql); $stmt->execute([ ':member_id' => $member_id, ':user_nm' => $_GET['user_nm'] ?? '', ':dept_nm' => $_GET['dept_nm'] ?? '', ':use_yn' => $_GET['use_yn'] ?? '' ]); $rows = $stmt->fetchAll(PDO::FETCH_ASSOC); $i = 1; foreach ($rows as &$r) { $r['recid'] = $i++; } echo json_encode([ 'status' => 'success', 'member_id' => $member_id, 'records' => $rows ]); break; /* ========================= 2. 사용자 저장 ========================= */ case 'save': $inserts = $input['inserts'] ?? []; $updates = $input['updates'] ?? []; if (!$inserts && !$updates) { throw new Exception('저장할 데이터가 없습니다.'); } $pdo->beginTransaction(); // INSERT if ($inserts) { $stmtI = $pdo->prepare(" SELECT kngil.sp_users_i( :member_id,:user_id,:user_pw,:user_nm,:dept_nm, :posit_nm,:tel_no,:email,:auth_bc,:use_yn,:rmks,:cid ) "); foreach ($inserts as $r) { $stmtI->execute([ ':member_id' => $member_id, ':user_id' => $r['user_id'], ':user_pw' => $r['user_pw'] ?? '0000', ':user_nm' => $r['user_nm'], ':dept_nm' => $r['dept_nm'], ':posit_nm' => $r['posit_nm'] ?? '', ':tel_no' => $r['tel_no'], ':email' => $r['email'], ':auth_bc' => $r['auth_bc'], ':use_yn' => $r['use_yn'], ':rmks' => $r['rmks'] ?? '', ':cid' => $r['cid'] ?? 'SYSTEM' ]); } } // UPDATE if ($updates) { $stmtU = $pdo->prepare(" SELECT kngil.sp_users_u( :member_id,:user_id,:user_pw,:user_nm,:dept_nm, :posit_nm,:tel_no,:email,:auth_bc,:use_yn,:rmks,:mid ) "); foreach ($updates as $r) { $stmtU->execute([ ':member_id' => $member_id, ':user_id' => $r['user_id'], ':user_pw' => null, ':user_nm' => $r['user_nm'], ':dept_nm' => $r['dept_nm'], ':posit_nm' => $r['posit_nm'] ?? '', ':tel_no' => $r['tel_no'], ':email' => $r['email'], ':auth_bc' => $r['auth_bc'], ':use_yn' => $r['use_yn'], ':rmks' => $r['rmks'] ?? '', ':mid' => $r['mid'] ?? 'SYSTEM' ]); } } $pdo->commit(); echo json_encode(['status'=>'success']); break; /* ========================= 3. 사용자 삭제 (비활성) ========================= */ case 'delete': $ids = $input['ids'] ?? []; if (!$ids) throw new Exception('삭제 대상이 없습니다.'); $sql = "SELECT kngil.sp_users_d(:member_id, :user_id)"; $stmt = $pdo->prepare($sql); foreach ($ids as $uid) { $stmt->execute([ ':member_id' => $member_id, ':user_id' => $uid ]); } echo json_encode(['status'=>'success']); break; /* ========================= 4. 회원 총 구매 면적 조회 ========================= */ case 'total_area': $sql = " SELECT COALESCE(SUM(sum_area), 0) AS total_area FROM kngil.sp_buy_item_history_r(:member_id, '', NULL, NULL) "; $stmt = $pdo->prepare($sql); $stmt->execute([ ':member_id' => $member_id ]); $row = $stmt->fetch(PDO::FETCH_ASSOC); echo json_encode([ 'status' => 'success', 'member_id' => $member_id, 'total_area' => (int)$row['total_area'] ]); break; default: throw new Exception('잘못된 요청'); } } catch (Exception $e) { if ($pdo->inTransaction()) { $pdo->rollBack(); } http_response_code(500); echo json_encode([ 'status' => 'error', 'message' => $e->getMessage() ]); }