Files
sam-kd/estimate/get_estimate_amount.php
hskwon aca1767eb9 초기 커밋: 5130 레거시 시스템
- URL 하드코딩 → .env APP_URL 기반 동적 URL로 변경
- DB 연결 하드코딩 → .env 기반으로 변경
- MySQL strict mode DATE 오류 수정
2025-12-10 20:14:31 +09:00

87 lines
3.1 KiB
PHP

<?php
declare(strict_types=1);
$DB = 'chandj';
// — 에러 로깅 설정 —
error_reporting(E_ALL);
// 사용자 화면에는 에러를 노출시키지 않고
ini_set('display_errors', '0');
// 로그에는 남기기
ini_set('log_errors', '1');
ini_set('error_log', $_SERVER['DOCUMENT_ROOT'].'/php_errors.log');
// — JSON 응답 헤더 —
header('Content-Type: application/json; charset=utf-8');
// — 필수 유틸 로드 —
// DB 연결
require_once($_SERVER['DOCUMENT_ROOT'] . "/lib/mydb.php");
$pdo = db_connect();
error_log("===== get_estimate_amount START =====");
error_log("POST DATA: " . print_r($_POST, true));
error_log("DB: " . print_r($DB, true));
try {
$type = $_POST['type'] ?? '';
$estimateList = $_POST['estimateList'] ?? '';
$estimateSlatList = $_POST['estimateSlatList'] ?? '';
$num = $_POST['num'] ?? '';
$inspectionFee = $_POST['inspectionFee'] ?? '';
// checkbox 5개 상태를 배열로 구성
$checkboxOptions = [
'steel' => $_POST['steel'] ?? '0',
'motor' => $_POST['motor'] ?? '0',
'warranty' => $_POST['warranty'] ?? '',
'slatcheck' => $_POST['slatcheck'] ?? '0',
'partscheck' => $_POST['partscheck'] ?? '0'
];
if ($type === '스크린') {
// 스크린 계산 로직
require_once $_SERVER['DOCUMENT_ROOT'].'/estimate/get_screen_amount.php';
if (empty($estimateList)) {
throw new Exception('스크린 견적 데이터(estimateList)가 없습니다.');
}
$details = json_decode((string)$estimateList, true);
if (!is_array($details)) {
throw new Exception('스크린 JSON 파싱 오류: ' . json_last_error_msg());
}
$result = calculateScreenAmount($details, $inspectionFee, $pdo, $checkboxOptions);
} elseif ($type === '철재') {
// 슬랫 계산 로직
require_once $_SERVER['DOCUMENT_ROOT'].'/estimate/get_slat_amount.php';
if (empty($estimateSlatList)) {
throw new Exception('철재 견적 데이터(estimateSlatList)가 없습니다.');
}
$details = json_decode((string)$estimateSlatList, true);
if (!is_array($details)) {
throw new Exception('철재 JSON 파싱 오류: ' . json_last_error_msg());
}
$result = calculateSlatAmount($details, $inspectionFee, $pdo, $checkboxOptions);
} else {
throw new Exception("알 수 없는 type 값: {$type}");
}
// error_log("계산 결과: " . print_r($result, true));
// JSON 응답 전송 전에 출력 버퍼 정리
if (ob_get_length()) ob_clean();
echo json_encode([
'success' => true,
'data' => $result,
], JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES);
} catch (Exception $e) {
error_log("get_estimate_amount ERROR: " . $e->getMessage());
// JSON 응답 전송 전에 출력 버퍼 정리
if (ob_get_length()) ob_clean();
echo json_encode([
'success' => false,
'error' => $e->getMessage(),
], JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES);
}