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

151 lines
5.1 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
require_once($_SERVER['DOCUMENT_ROOT'] . "/session.php");
header("Content-Type: application/json"); // JSON을 사용하기 위해 필요한 구문
$tablename = 'lot';
// LOT 번호 해석을 위한 품목, 종류 매핑 배열
$prod_map = [
'G' => '연기차단재',
'B' => '하단마감재(스크린)',
'T' => '하단마감재(철재)',
'L' => 'L - Bar',
'R' => '가이드레일(벽면형)',
'S' => '가이드레일(측면형)',
'C' => '케이스'
];
$spec_map = [
'I' => '화이바원단',
'S' => 'SUS(마감)',
'U' => 'SUS(마감)2',
'E' => 'EGI(마감)',
'A' => '스크린용',
'D' => 'D형',
'C' => 'C형',
'M' => '본체',
'T' => '본체(철재)',
'B' => '후면코너부',
'L' => '린텔부',
'P' => '점검구',
'F' => '전면부'
];
$slength_map = [
'53' => 'W50 × 3000',
'54' => 'W50 × 4000',
'83' => 'W80 × 3000',
'84' => 'W80 × 4000',
'12' => '1219',
'24' => '2438',
'30' => '3000',
'35' => '3500',
'40' => '4000',
'42' => '4200',
'41' => '4150',
'43' => '4300'
];
// Helper function to convert numbers
function conv_num($num) {
return (int)str_replace(',', '', $num);
}
// Helper function to replace | with ,
function pipetocomma($str) {
return str_replace('|', ',', $str);
}
// 데이터 배열 준비
isset($_REQUEST["col1"]) ? $col1=$_REQUEST["col1"] : $col1='';
isset($_REQUEST["col2"]) ? $col2=$_REQUEST["col2"] : $col2='';
isset($_REQUEST["col3"]) ? $col3=$_REQUEST["col3"] : $col3='';
isset($_REQUEST["col4"]) ? $col4=$_REQUEST["col4"] : $col4='';
isset($_REQUEST["col5"]) ? $col5=$_REQUEST["col5"] : $col5='';
isset($_REQUEST["col6"]) ? $col6=$_REQUEST["col6"] : $col6='';
$colarr1 = explode(",", $col1[0]);
$colarr2 = explode(",", $col2[0]);
$colarr3 = explode(",", $col3[0]);
$colarr4 = explode(",", $col4[0]);
$colarr5 = explode(",", $col5[0]);
$colarr6 = explode(",", $col6[0]);
$orderday = date("Y-m-d"); // 현재 날짜 2022-01-20 형태로 지정
require_once($_SERVER['DOCUMENT_ROOT'] . "/lib/mydb.php");
$pdo = db_connect();
for ($i = 0; $i < count($colarr1); $i++) {
if ($colarr1[$i] != '') {
// | -> , 로 변환함
$colarr1[$i] = pipetocomma($colarr1[$i]);
$colarr2[$i] = pipetocomma($colarr2[$i]);
$colarr3[$i] = pipetocomma($colarr3[$i]);
$colarr4[$i] = pipetocomma($colarr4[$i]);
$colarr5[$i] = pipetocomma($colarr5[$i]);
$colarr6[$i] = pipetocomma($colarr6[$i]); // 원단 로트번호
$fabric_lot = $colarr6[$i];
// DateTime 클래스를 사용하여 문자열을 파싱하고 형식을 'Y-m-d'로 변환
$date = DateTime::createFromFormat('Y년 n월 j일', $colarr2[$i]);
$formattedDate = $date->format('Y-m-d'); // '2024-06-19'로 변환
// LOT 번호에서 prod, spec, slength 추출
$lot_number = $colarr3[$i];
$prod_code = substr($lot_number, 0, 1); // LOT 번호의 첫 글자 (품목)
$spec_code = substr($lot_number, 1, 1); // LOT 번호의 두 번째 글자 (종류)
$slength_code = substr($lot_number, -2); // LOT 번호의 마지막 두 글자 (모양&길이)
$prod_value = isset($prod_map[$prod_code]) ? $prod_map[$prod_code] : '';
$spec_value = isset($spec_map[$spec_code]) ? $spec_map[$spec_code] : '';
$slength_value = isset($slength_map[$slength_code]) ? $slength_map[$slength_code] : '';
$author = '개발자';
$search_tag = $lot_number . ' ' .
$prod_value . ' ' .
$author . ' ' .
$spec_value . ' ' .
$slength_value . ' ' ;
try {
$pdo->beginTransaction();
// Prepare SQL insert statement
$sql = "INSERT INTO " . $DB . "." . $tablename . " (rawLot, reg_date, lot_number, prod, spec, slength, surang, author, search_tag, fabric_lot ) ";
$sql .= "VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
$stmh = $pdo->prepare($sql);
// Bind the values to the prepared statement
$stmh->bindValue(1, $colarr1[$i], PDO::PARAM_STR); // 등록일
$stmh->bindValue(2, $formattedDate, PDO::PARAM_STR); // 등록일
$stmh->bindValue(3, $colarr3[$i], PDO::PARAM_STR); // LOT 번호
$stmh->bindValue(4, $prod_code, PDO::PARAM_STR); // 해석된 품목명
$stmh->bindValue(5, $spec_code, PDO::PARAM_STR); // 해석된 종류
$stmh->bindValue(6, $slength_code, PDO::PARAM_STR); // 해석된 모양&길이
$stmh->bindValue(7, conv_num($colarr5[$i]), PDO::PARAM_INT); // 생산 수량
$stmh->bindValue(8, $author , PDO::PARAM_STR);
$stmh->bindValue(9, $search_tag, PDO::PARAM_STR);
$stmh->bindValue(10, $fabric_lot, PDO::PARAM_STR);
// Execute the statement
$stmh->execute();
$pdo->commit();
} catch (PDOException $Exception) {
$pdo->rollBack();
print "오류: " . $Exception->getMessage();
}
}
}
// 데이터를 배열 변수에 넣어준다.
$data = array("colarr1" => $colarr1);
// json 출력
echo json_encode($data, JSON_UNESCAPED_UNICODE);
?>