102 lines
3.0 KiB
PHP
102 lines
3.0 KiB
PHP
|
|
<?php
|
|||
|
|
// length-input 입력 시 서버에서 값을 가져오는 API
|
|||
|
|
error_reporting(E_ALL);
|
|||
|
|
ini_set('display_errors', 1);
|
|||
|
|
|
|||
|
|
// CORS 헤더 설정
|
|||
|
|
header('Access-Control-Allow-Origin: *');
|
|||
|
|
header('Access-Control-Allow-Methods: POST, GET, OPTIONS');
|
|||
|
|
header('Access-Control-Allow-Headers: Content-Type');
|
|||
|
|
header('Content-Type: application/json; charset=utf-8');
|
|||
|
|
|
|||
|
|
// 디버그 로그 파일 설정
|
|||
|
|
$debug_log_file = __DIR__ . '/debug_length_data.log';
|
|||
|
|
|
|||
|
|
// 로그 함수
|
|||
|
|
function writeLog($message) {
|
|||
|
|
global $debug_log_file;
|
|||
|
|
$timestamp = date('Y-m-d H:i:s');
|
|||
|
|
$log_message = "[$timestamp] $message\n";
|
|||
|
|
file_put_contents($debug_log_file, $log_message, FILE_APPEND | LOCK_EX);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
writeLog("=== 새로운 요청 시작 ===");
|
|||
|
|
|
|||
|
|
// POST 데이터 받기
|
|||
|
|
$input = json_decode(file_get_contents('php://input'), true);
|
|||
|
|
if (!$input) {
|
|||
|
|
$input = $_POST;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
writeLog("받은 데이터: " . json_encode($input));
|
|||
|
|
|
|||
|
|
$length = isset($input['length']) ? floatval($input['length']) : 0;
|
|||
|
|
$rowIndex = isset($input['rowIndex']) ? intval($input['rowIndex']) : 0;
|
|||
|
|
$inputType = isset($input['inputType']) ? $input['inputType'] : 'area_length';
|
|||
|
|
|
|||
|
|
writeLog("파싱된 데이터 - length: $length, rowIndex: $rowIndex, inputType: $inputType");
|
|||
|
|
|
|||
|
|
// 기본 응답 구조
|
|||
|
|
$response = [
|
|||
|
|
'success' => false,
|
|||
|
|
'message' => '',
|
|||
|
|
'data' => [
|
|||
|
|
'areaPrice' => 0,
|
|||
|
|
'unitPrice' => 0,
|
|||
|
|
'totalPrice' => 0
|
|||
|
|
]
|
|||
|
|
];
|
|||
|
|
|
|||
|
|
try {
|
|||
|
|
// 길이가 유효한지 확인
|
|||
|
|
if ($length <= 0) {
|
|||
|
|
throw new Exception("유효하지 않은 길이 값: $length");
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
// 과거 로직에 따른 계산
|
|||
|
|
// 면적 단가 계산 (예시: 1㎡당 30,000원)
|
|||
|
|
$areaPrice = $length * 30000; // 실제로는 데이터베이스에서 가져와야 함
|
|||
|
|
|
|||
|
|
// 단가 계산 (면적 길이 × 면적 단가)
|
|||
|
|
$unitPrice = round($length * 30000);
|
|||
|
|
|
|||
|
|
// 기본 수량 (실제로는 입력값에서 가져와야 함)
|
|||
|
|
$su = 1;
|
|||
|
|
|
|||
|
|
// 합계 계산 (수량 × 단가)
|
|||
|
|
$totalPrice = round($su * $unitPrice);
|
|||
|
|
|
|||
|
|
writeLog("계산 결과 - areaPrice: $areaPrice, unitPrice: $unitPrice, totalPrice: $totalPrice");
|
|||
|
|
|
|||
|
|
// 응답 데이터 설정
|
|||
|
|
$response['success'] = true;
|
|||
|
|
$response['message'] = '계산 완료';
|
|||
|
|
$response['data'] = [
|
|||
|
|
'areaPrice' => $areaPrice,
|
|||
|
|
'unitPrice' => $unitPrice,
|
|||
|
|
'totalPrice' => $totalPrice
|
|||
|
|
];
|
|||
|
|
|
|||
|
|
// 추가 디버그 정보
|
|||
|
|
$response['debug'] = [
|
|||
|
|
'inputLength' => $length,
|
|||
|
|
'rowIndex' => $rowIndex,
|
|||
|
|
'inputType' => $inputType,
|
|||
|
|
'calculationMethod' => 'area_length * 30000',
|
|||
|
|
'timestamp' => date('Y-m-d H:i:s')
|
|||
|
|
];
|
|||
|
|
|
|||
|
|
} catch (Exception $e) {
|
|||
|
|
writeLog("오류 발생: " . $e->getMessage());
|
|||
|
|
$response['success'] = false;
|
|||
|
|
$response['message'] = '계산 중 오류가 발생했습니다: ' . $e->getMessage();
|
|||
|
|
$response['error'] = $e->getMessage();
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
// JSON 응답 전송
|
|||
|
|
$json_response = json_encode($response, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
|
|||
|
|
|
|||
|
|
writeLog("응답 전송: " . $json_response);
|
|||
|
|
|
|||
|
|
echo $json_response;
|
|||
|
|
?>
|