'personal' and o.od_id = p.ip_oid left join {$g5['g5_shop_personalpay_table']} pp on p.ip_order_type = 'personal' and pp.pp_id = p.ip_oid left join {$g5['g5_shop_inicis_log_table']} il on il.oid = p.ip_oid where (p.ip_tid <> '' or (il.P_TID <> '' and il.P_STATUS = '00')) and $anomaly_sql order by p.ip_updated_at asc limit 5 "); while ($row = sql_fetch_array($result)) $targets[] = $row; } else { $oid_raw = isset($_POST['oid']) && !is_array($_POST['oid']) ? trim($_POST['oid']) : ''; $oid = inicis_pro_clean_oid($oid_raw); if ($oid === '' || $oid !== $oid_raw) alert('결제 주문번호가 올바르지 않습니다.', './inicisloglist.php'); $row = sql_fetch(" select * from `{$tables['summary']}` where ip_oid = '".sql_escape_string($oid)."' "); if (empty($row['ip_id'])) alert('결제 처리 이력을 찾을 수 없습니다.', './inicisloglist.php'); $targets[] = $row; } if (!count($targets)) alert('KG이니시스에서 조회할 확인 필요 거래가 없습니다.', './inicisloglist.php'); $success_count = 0; $failed_count = 0; $last_oid = ''; foreach ($targets as $target) { $last_oid = $target['ip_oid']; $target_tid = !empty($target['ip_tid']) ? $target['ip_tid'] : inicis_pro_recover_approved_tid($target['ip_oid'], 'admin'); if ($target_tid === '') { if ($mode !== 'batch') alert('승인 TID가 없어 KG이니시스 거래조회를 실행할 수 없습니다. 인증 전 미완료 결제이거나 승인 TID가 복구되지 않은 거래입니다.', './inicislogview.php?oid='.urlencode($target['ip_oid'])); $failed_count++; continue; } $inquiry = inicis_pro_inquiry($target_tid, $target['ip_oid'], $target); if (inicis_pro_save_inquiry($target['ip_oid'], $inquiry, 'admin') && !empty($inquiry['success'])) $success_count++; else $failed_count++; } $message = 'KG이니시스 거래조회가 완료되었습니다. 성공 '.$success_count.'건, 실패 '.$failed_count.'건'; if ($mode !== 'batch' && $last_oid !== '') alert($message, './inicislogview.php?oid='.urlencode($last_oid)); alert($message, './inicisloglist.php?risk=anomaly');