<?php
include_once('./_common.php');
header('Content-Type: application/json; charset=UTF-8');
header('Cache-Control: no-store, no-cache, must-revalidate, max-age=0');
if (!$is_member) { echo json_encode(['result'=>'fail','message'=>'로그인이 필요합니다.']); exit; }

$od_id = isset($_GET['od_id']) ? trim((string)$_GET['od_id']) : '';
if (!$od_id) { echo json_encode(['result'=>'fail','message'=>'주문번호가 필요합니다.']); exit; }

$safe_mb = sql_escape_string($member['mb_id']);
$safe_od = sql_escape_string($od_id);

$order = sql_fetch(
    "SELECT od_id FROM g5_shoppoint_order WHERE od_id='{$safe_od}' AND mb_id='{$safe_mb}' LIMIT 1",
    false
);
if (!$order) { echo json_encode(['result'=>'fail','message'=>'주문을 찾을 수 없습니다.']); exit; }

$res = sql_query(
    "SELECT wn_created_at, wn_message, wn_status, wn_admin_memo
     FROM g5_withdraw_notify
     WHERE od_id='{$safe_od}' AND mb_id='{$safe_mb}'
     ORDER BY wn_id DESC",
    false
);
$list = [];
while ($r = sql_fetch_array($res)) {
    $list[] = [
        'created_at' => $r['wn_created_at'],
        'message'    => (string)($r['wn_message'] ?? ''),
        'status'     => $r['wn_status'],
        'admin_memo' => (string)($r['wn_admin_memo'] ?? ''),
    ];
}
echo json_encode(['result'=>'success','list'=>$list], JSON_UNESCAPED_UNICODE|JSON_UNESCAPED_SLASHES);
