새로운 api

This commit is contained in:
2026-02-03 20:47:56 +09:00
parent cbcd66d5c7
commit 8bb7700a00
10 changed files with 1625 additions and 591 deletions

View File

@@ -0,0 +1,89 @@
<?php
namespace App\Services\Handlers;
use CodeIgniter\CLI\CLI;
use App\Services\ParameterMapper\TypeSParameterMapper;
use App\Models\Entities\ReceiptModel;
use App\Models\Entities\ResultModel;
use App\Models\Entities\NaverRawStagingModel;
use Exception;
/**
* Type S 핸들러
* 현장확인 매물 (A01) 데이터 처리
*/
class TypeSHandler
{
private $receiptModel;
private $resultModel;
private $stagingModel;
private $db;
private $parameterMapper;
private $naverClient;
public function __construct()
{
$this->db = \Config\Database::connect();
$this->receiptModel = new ReceiptModel();
$this->resultModel = new ResultModel();
$this->stagingModel = new NaverRawStagingModel();
$this->parameterMapper = new TypeSParameterMapper();
$this->naverClient = new \App\Libraries\NaverApiClient();
helper('log');
}
/**
* Type S 메인 처리 로직
*/
public function handle(string $articleNumber, array $rawData, array $payload): int
{
CLI::write(CLI::color('🟢 Type S 처리 시작 :: ' . $articleNumber, 'green'));
$this->db->transBegin();
try {
// 1. Receipt 데이터 저장
$receiptData = $this->parameterMapper->mapReceipt($articleNumber, $rawData, $payload);
if (!$this->receiptModel->insert($receiptData)) {
throw new Exception("Receipt Insert 실패: " . json_encode($this->receiptModel->errors()));
}
$rcptSq = $this->receiptModel->getInsertID();
CLI::write(CLI::color("✅ Receipt 저장 성공 (ID: $rcptSq)", 'blue'));
// 2. Result 데이터 저장
$resultData = $this->parameterMapper->mapResult($rcptSq, $rawData);
if (!$this->resultModel->insert($resultData)) {
throw new Exception("Result Insert 실패");
}
CLI::write(CLI::color('✅ Result 저장 성공', 'blue'));
// 3. 트랜잭션 커밋
$this->db->transComplete();
if ($this->db->transStatus() === false) {
write_custom_log("Type S DB 트랜잭션 최종 실패", 'ERROR', 'service');
throw new Exception("Type S DB 트랜잭션 최종 실패");
}
// 4. 로그 기록
write_custom_log("Type S 처리 성공 | Atcl: $articleNumber | Rcpt_sq: $rcptSq", 'INFO', 'service');
write_custom_log("Receipt Insert SQL: " . (string)$this->receiptModel->getLastQuery(), 'INFO', 'service');
write_custom_log("Result Insert SQL: " . (string)$this->resultModel->getLastQuery(), 'INFO', 'service');
// 5. 네이버 예약 정보 동기화 (비동기)
try {
$syncResult = $this->naverClient->submitSyncResult($rawData['reserveNo'] ?? '');
write_custom_log("Naver Sync Result Response: " . json_encode($syncResult), 'INFO', 'service');
} catch (Exception $e) {
write_custom_log("Naver Sync 실패 (계속 진행): " . $e->getMessage(), 'WARN', 'service');
}
return $rcptSq;
} catch (Exception $e) {
$this->db->transRollback();
write_custom_log("Type S 처리 실패: " . $e->getMessage(), 'ERROR', 'service');
throw $e;
}
}
}

View File

@@ -0,0 +1,309 @@
<?php
namespace App\Services\Handlers;
use CodeIgniter\CLI\CLI;
use App\Services\ParameterMapper\TypeV2ParameterMapper;
use App\Models\Entities\VrfcReqModel;
use App\Models\Entities\V2articleinfoModel;
use App\Models\Entities\V2articleinfoetcModel;
use App\Models\Entities\V2modifyinfoModel;
use App\Models\Entities\V2urlimgsaveModel;
use App\Services\StatusService;
use Exception;
/**
* Type V2 핸들러
* 일반/서류/비공동 매물 (D04, F01 등) 데이터 처리
*/
class TypeV2Handler
{
private $vrfcReqModel;
private $articleInfoModel;
private $articleInfoEtcModel;
private $modifyInfoModel;
private $urlImgSaveModel;
private $statusService;
private $db;
private $parameterMapper;
public function __construct()
{
$this->db = \Config\Database::connect();
$this->vrfcReqModel = new VrfcReqModel();
$this->articleInfoModel = new V2articleinfoModel();
$this->articleInfoEtcModel = new V2articleinfoetcModel();
$this->modifyInfoModel = new V2modifyinfoModel();
$this->urlImgSaveModel = new V2urlimgsaveModel();
$this->statusService = new StatusService();
$this->parameterMapper = new TypeV2ParameterMapper();
helper('log');
}
/**
* Type V2 메인 처리 로직
*/
public function handle(string $articleNumber, array $rawData, array $payload): int
{
CLI::write(CLI::color('🟢 Type V2 처리 시작 :: ' . $articleNumber, 'green'));
try {
$requestType = $payload['requestType'] ?? 'REG';
switch ($requestType) {
case 'REG':
return $this->handleRegister($articleNumber, $rawData, $payload);
case 'MOD':
return $this->handleModify($articleNumber, $rawData, $payload);
case 'CNC':
return $this->handleCancel($articleNumber, $rawData, $payload);
default:
throw new Exception("알 수 없는 requestType: $requestType");
}
} catch (Exception $e) {
write_custom_log("Type V2 처리 실패: " . $e->getMessage(), 'ERROR', 'service');
throw $e;
}
}
/**
* 신규 등록 처리
*/
private function handleRegister(string $articleNumber, array $rawData, array $payload): int
{
CLI::write(CLI::color('🔵 V2 신규 등록 시작', 'cyan'));
// 파라미터 준비
$vrfcReqParam = $this->parameterMapper->mapVrfcReq($articleNumber, $rawData, $payload);
$articleInfoParam = $this->parameterMapper->mapArticleInfo($articleNumber, $rawData, $payload);
$articleInfoEtcParam = $this->parameterMapper->mapArticleInfoEtc($articleNumber, $rawData);
$modifyInfoParam = $this->parameterMapper->mapModifyInfo($articleNumber, $rawData, $payload);
// 검증 요청 저장 또는 업데이트
$vrSq = $this->insertOrUpdateVrfcReq($vrfcReqParam);
// 기사 정보 저장
$articleInfoParam['vr_sq'] = $vrSq;
if (!$this->articleInfoModel->replace($articleInfoParam)) {
throw new Exception("ArticleInfo Insert 실패: " . json_encode($this->db->error()));
}
CLI::write(CLI::color('✅ ArticleInfo 저장 성공', 'blue'));
// 기사 정보 추가 저장
$articleInfoEtcParam['vr_sq'] = $vrSq;
if (!$this->articleInfoEtcModel->replace($articleInfoEtcParam)) {
throw new Exception("ArticleInfoEtc Insert 실패: " . json_encode($this->db->error()));
}
CLI::write(CLI::color('✅ ArticleInfoEtc 저장 성공', 'blue'));
// 수정 정보 입력 (있으면 update, 없으면 insert)
if (!$this->modifyInfoModel->saveModifyInfo($vrSq, $modifyInfoParam)) {
throw new Exception("ModifyInfo 저장 실패: " . json_encode($this->db->error()));
}
CLI::write(CLI::color('✅ ModifyInfo 저장 성공', 'blue'));
// URL 이미지 저장 (v2_url_img_save 테이블)
$files = $rawData['files'] ?? [];
if (!empty($files)) {
$fileExtracted = $this->parameterMapper->extractFilesByType($files);
$this->saveUrlImagesToDb($fileExtracted, $articleNumber, $vrSq);
}
// 상태 기록
$this->statusService->recordStatusAndHistory($vrSq, '10', 'C9', "NEW 신규접수 : 10");
write_custom_log("V2 신규 등록 성공 | Atcl: $articleNumber | VR_SQ: $vrSq", 'INFO', 'service');
return $vrSq;
}
/**
* 수정 처리
*/
private function handleModify(string $articleNumber, array $rawData, array $payload): int
{
CLI::write(CLI::color('🔵 V2 수정 시작', 'cyan'));
// 기존 검증 요청 확인
$existing = $this->vrfcReqModel->where('atcl_no', $articleNumber)->first();
if (!$existing) {
throw new Exception("수정할 기존 데이터가 없습니다. Atcl: $articleNumber");
}
$vrSq = $existing['vr_sq'];
$stat_cd = $existing['stat_cd'];
// 파라미터 준비 (MOD 타입)
$vrfcReqParam = $this->parameterMapper->mapVrfcReq($articleNumber, $rawData, $payload);
$articleInfoParam = $this->parameterMapper->mapArticleInfo($articleNumber, $rawData, $payload);
$articleInfoEtcParam = $this->parameterMapper->mapArticleInfoEtc($articleNumber, $rawData);
$modifyInfoParam = $this->parameterMapper->mapModifyInfo($articleNumber, $rawData, $payload);
$vrfcReqParam['stat_cd'] = '30';
$vrfcReqParam['insert_tm'] = date('Y-m-d H:i:s');
$vrfcReqParam['sync_yn'] = 'Y';
// 데이터 업데이트
if (!$this->vrfcReqModel->update($vrSq, $vrfcReqParam)) {
throw new Exception("VrfcReq Update 실패");
}
// 기사 정보 저장
$articleInfoParam['vr_sq'] = $vrSq;
if (!$this->articleInfoModel->replace($articleInfoParam)) {
throw new Exception("ArticleInfo Insert 실패: " . json_encode($this->db->error()));
}
CLI::write(CLI::color('✅ ArticleInfo 저장 성공', 'blue'));
// 기사 정보 추가 저장
$articleInfoEtcParam['vr_sq'] = $vrSq;
if (!$this->articleInfoEtcModel->replace($articleInfoEtcParam)) {
throw new Exception("ArticleInfoEtc Insert 실패: " . json_encode($this->db->error()));
}
CLI::write(CLI::color('✅ ArticleInfoEtc 저장 성공', 'blue'));
// 수정 정보 입력 (있으면 update, 없으면 insert)
if (!$this->modifyInfoModel->saveModifyInfo($vrSq, $modifyInfoParam)) {
throw new Exception("ModifyInfo 저장 실패: " . json_encode($this->db->error()));
}
CLI::write(CLI::color('✅ ModifyInfo 저장 성공', 'blue'));
// URL 이미지 저장 (v2_url_img_save 테이블)
$files = $rawData['files'] ?? [];
if (!empty($files)) {
$fileExtracted = $this->parameterMapper->extractFilesByType($files);
$this->saveUrlImagesToDb($fileExtracted, $articleNumber, $vrSq);
}
$this->statusService->recordStatusAndHistory($vrSq, '30', 'C9', "재접수 상태변경 : {$stat_cd} => 30");
CLI::write(CLI::color('✅ VrfcReq 수정 성공', 'blue'));
return $vrSq;
}
/**
* 취소 처리
*/
private function handleCancel(string $articleNumber, array $rawData, array $payload): int
{
CLI::write(CLI::color('🔵 V2 취소 시작', 'cyan'));
// 기존 검증 요청 확인
$existing = $this->vrfcReqModel->where('atcl_no', $articleNumber)->first();
if (!$existing) {
throw new Exception("취소할 기존 데이터가 없습니다. Atcl: $articleNumber");
}
$vrSq = $existing['vr_sq'];
$stat_cd = $existing['stat_cd'];
// 파라미터 준비 (MOD 타입)
$vrfcReqParam = $this->parameterMapper->mapVrfcReq($articleNumber, $rawData, $payload);
$vrfcReqParam['stat_cd'] = '19';
$vrfcReqParam['insert_tm'] = date('Y-m-d H:i:s');
$vrfcReqParam['req_type'] = 'D';
// 상태를 취소로 업데이트
if (!$this->vrfcReqModel->update($vrSq, $vrfcReqParam)) {
throw new Exception("VrfcReq Cancel 실패");
}
$this->statusService->recordStatusAndHistory($vrSq, '19', 'C9', "재접수 상태변경 : {$stat_cd} => 19");
CLI::write(CLI::color('✅ 취소 처리 완료', 'blue'));
write_custom_log("V2 취소 성공 | Atcl: $articleNumber | VR_SQ: $vrSq", 'INFO', 'service');
return $vrSq;
}
/**
* 검증 요청 저장 또는 업데이트
*/
private function insertOrUpdateVrfcReq(array $vrfcReqParam): int
{
$articleNumber = $vrfcReqParam['atcl_no'];
$existing = $this->vrfcReqModel->where('atcl_no', $articleNumber)->first();
if ($existing) {
// 업데이트
$vrSq = $existing['vr_sq'] ?? $existing['id'];
CLI::write(CLI::color("🟡 기존 데이터 발견 (atcl_no: $articleNumber) -> 업데이트", 'yellow'));
if (!$this->vrfcReqModel->update($vrSq, $vrfcReqParam)) {
$this->logAndThrowError($vrfcReqParam, "VrfcReq Update 실패 :: $articleNumber");
}
CLI::write(CLI::color("✅ Update 성공 (vr_sq: $vrSq)", 'blue'));
return $vrSq;
} else {
// 신규 등록
if (!$this->vrfcReqModel->insert($vrfcReqParam)) {
$this->logAndThrowError($vrfcReqParam, "VrfcReq Insert 실패 :: $articleNumber");
}
$vrSq = $this->vrfcReqModel->getInsertID();
CLI::write(CLI::color("✅ Insert 성공 (vr_sq: $vrSq, atcl_no: $articleNumber)", 'blue'));
return $vrSq;
}
}
/**
* 에러 로깅 및 예외 발생
*/
private function logAndThrowError(array $data, string $message): void
{
$dbError = $this->db->error();
CLI::write(CLI::color('❌ SQL ERROR', 'red', 'bold'));
CLI::write(CLI::color('메시지: ', 'white') . $dbError['message']);
CLI::write(CLI::color('쿼리: ', 'white') . (string)$this->vrfcReqModel->getLastQuery());
throw new Exception($message . ": " . $dbError['message']);
}
/**
* URL 이미지를 v2_url_img_save 테이블에 저장
*
* @param array $fileExtracted extractFilesByType로 추출된 파일 배열
* @param string $atclNo 기사번호
* @param int $vrSq 검증요청ID
*/
private function saveUrlImagesToDb(array $fileExtracted, string $atclNo, int $vrSq): void
{
$fileTypes = [
'certRegister' => '2', // 등기부등본
'confirmDocImgUrl' => '2', // 확인서이미지
'referenceFileUrl' => '1' // 홍보자료
];
$saveCount = 0;
foreach ($fileTypes as $key => $type) {
if (!empty($fileExtracted[$key]) && is_array($fileExtracted[$key])) {
foreach ($fileExtracted[$key] as $url) {
if (!empty($url)) {
$insertData = [
'url' => $url,
'type' => $type,
'atcl_no' => $atclNo,
'vr_sq' => $vrSq,
'status' => 'save',
'try_cnt' => 0
];
if ($this->urlImgSaveModel->insert($insertData)) {
$saveCount++;
} else {
CLI::write(CLI::color("⚠️ URL 저장 실패: $url", 'yellow'));
}
}
}
}
}
if ($saveCount > 0) {
CLI::write(CLI::color("✅ URL 이미지 저장 완료: $saveCount개", 'blue'));
write_custom_log("URL 이미지 저장 | Atcl: $atclNo | VR_SQ: $vrSq | Count: $saveCount", 'INFO', 'service');
}
}
}

View File

@@ -4,620 +4,80 @@ namespace App\Services;
use CodeIgniter\CLI\CLI;
use App\Libraries\NaverApiClient;
use App\Models\Entities\VrfcReqModel;
use App\Models\Entities\V2articleinfoModel;
use App\Models\Entities\V2articleinfoetcModel;
use App\Models\Entities\V2stdailyModel;
use App\Models\Entities\NaverRawStagingModel;
use App\Models\Entities\ReceiptModel;
use App\Models\Entities\ResultModel;
use App\Services\StatusService; // 추가
use App\Services\Handlers\TypeSHandler;
use App\Services\Handlers\TypeV2Handler;
use Exception;
/**
* 네이버 부동산 매물 처리 서비스
*
* 네이버 API 응답을 받아서 타입별 처리 로직으로 위임하는 오케스트레이터 역할
* - Type S: 현장확인 (A01)
* - Type V2: 일반/서류/비공동 (D04, F01 등)
*/
class NaverService
{
protected $db;
protected $naverClient;
protected $VrfcReqModel;
protected $V2stdailyModel;
protected $statusService;
protected $rawStagingModel;
protected $receiptModel;
protected $resultModel;
protected $articleModel;
protected $articleEtcModel;
private $db;
private $naverClient;
private $rawStagingModel;
private $typeSHandler;
private $typeV2Handler;
public function __construct()
{
$this->db = \Config\Database::connect();
helper('log');
$this->naverClient = new NaverApiClient();
$this->rawStagingModel = new NaverRawStagingModel();
$this->typeSHandler = new TypeSHandler();
$this->typeV2Handler = new TypeV2Handler();
helper('log');
}
/**
* 모델/서비스 지연 로딩 (Null 에러 방지 핵심)
* 메인 프로세스: 네이버 API 호출 및 타입별 처리
*
* @param array $payload 요청 페이로드 (articleNumber, requestType 등)
* @return int 처리된 ID (rcpt_sq 또는 vr_sq)
* @throws Exception
*/
private function getStatusService() {
return $this->statusService ??= new StatusService();
}
private function getModel($property, $class) {
return $this->$property ??= new $class();
}
/**
* NaverApiClient 지연 로딩
*/
private function getNaverClient()
{
if ($this->naverClient === null) {
$this->naverClient = new \App\Libraries\NaverApiClient();
}
return $this->naverClient;
}
/**
* 메인 프로세스: 요청 타입에 따른 분기 처리
*/
public function processArticle(array $payload)
public function processArticle(array $payload): int
{
$articleNumber = $payload['articleNumber'];
$requestType = $payload['requestType'] ?? '';
CLI::write(CLI::color('🟢 getArticleInfo Start :: ' . $articleNumber , 'green'));
// 1. 네이버 API 호출
$response = $this->getNaverClient()->getArticleInfo($articleNumber);
if (!$response || $response['code'] !== 'success') {
throw new \Exception("네이버 API 응답 에러: $articleNumber");
}
$rawData = $response['data'];
$vType = $rawData['verificationTypeCode'] ?? '';
// [Staging] 원본 저장
$this->getModel('rawStagingModel', NaverRawStagingModel::class)->insert([
'atcl_no' => $articleNumber,
'verification_type' => $vType,
'request_type' => $requestType,
'raw_json' => $rawData
]);
CLI::write(CLI::color('🟢 임시테이블 :: ' . $this->rawStagingModel->getLastQuery() , 'green'));
// 3. 타입별 분기 처리
if ($vType === 'S') {
// [Type S] 현장확인 응답 처리 (A01 등)
return $this->processTypeS($articleNumber, $rawData, $payload);
} else {
// [Type D/기타] 서류확인/비공동 처리 (D04, F01 등)
return $this->processTypeV2($articleNumber, $rawData, $payload);
}
// $vrfcParams = $this->mapToDatabaseParams($response['data'], $payload);
// write_custom_log("PROCESS_START | Type: $requestType | Atcl: $articleNumber", 'INFO', 'service');
// switch ($requestType) {
// case 'REG': // 신규 등록
// $vr_sq = $this->insertVrfcReq($articleNumber, $vrfcParams);
// if ($vr_sq) $this->V2stdailyModel->set_v2_st_daily(null, $vrfcParams['cpid'], $vrfcParams['vrfc_type'] . '0103', '1', 'add');
// break;
// case 'MOD': // 수정
// $vr_sq = $this->updateVrfcReq($articleNumber, $vrfcParams);
// if ($vr_sq) $this->V2stdailyModel->set_v2_st_daily(null, $vrfcParams['cpid'], $vrfcParams['vrfc_type'] . '0102', '1', 'add');
// break;
// case 'CNC': // 취소
// $vr_sq = $this->deleteVrfcReq($articleNumber, $vrfcParams);
// if ($vr_sq) $this->V2stdailyModel->set_v2_st_daily(null, $vrfcParams['cpid'], 'A0101', '1', 'add');
// break;
// // case 'FIN': // 완료
// // $vr_sq = $this->finVrfcReq($articleNumber, $vrfcParams);
// // if ($vr_sq) $this->V2stdailyModel->set_v2_st_daily(null, $vrfcParams['cpid'], 'A0101', '1', 'add');
// // break;
// default:
// throw new \Exception("알 수 없는 requestType: $requestType");
// }
// return ['vr_sq' => $vr_sq, 'articleNumber' => $articleNumber];
}
/**
* [Type S] 현장확인 응답 처리 (A01 등)
*/
private function processTypeS($articleNumber, $rawData, $payload)
{
$now = db_now();
CLI::write(CLI::color('🟢 getArticleInfo Start :: ' . $articleNumber, 'green'));
// 시작 전 트랜잭션
$this->db->transStart();
try {
// 1. 네이버 API 호출
$response = $this->naverClient->getArticleInfo($articleNumber);
if (!$response || $response['code'] !== 'success') {
throw new Exception("네이버 API 응답 에러: $articleNumber");
}
switch ( trim($rawData['tradeType']) ) {
case '매매': $trade_type = 'A1'; break;
case '전세': $trade_type = 'B1'; break;
case '월세': $trade_type = 'B2'; break;
case '단기임대': $trade_type = 'B3'; break;
}
/* 좌표와 전용면적을 기준으로 */
if( in_array($rawData['realEstateTypeCode'], array('C01', 'C02'))){
$ground_plan = 'N';
$rawData = $response['data'];
$vType = $rawData['verificationTypeCode'] ?? '';
// 2. 원본 데이터 Staging 저장
$this->rawStagingModel->insert([
'atcl_no' => $articleNumber,
'verification_type' => $vType,
'request_type' => $requestType,
'raw_json' => $rawData
]);
CLI::write(CLI::color('🟢 임시테이블 저장 완료', 'green'));
// 3. 타입별 분기 처리
if ($vType === 'S') {
return $this->typeSHandler->handle($articleNumber, $rawData, $payload);
} else {
$ground_plan = 'Y';
}
try {
// 1. receipt 데이터 준비
$receiptData = [
'comp_sq' => '2',
'rcpt_rating' => '3',
'rcpt_key' => $articleNumber,
'rcpt_atclno' => $articleNumber,
'rcpt_product' => $rawData['realEstateTypeCode'] ?? null,
'rcpt_product_nm' => $rawData['realEstateType'] ?? null,
'rcpt_product_info1'=> $rawData['tradeType'] ?? null,
'rcpt_product_info2'=> $rawData['price']['dealAmount'] ?? '0',
'rcpt_product_info4'=> $rawData['price']['preSaleAmount'] ?? '0',
'rcpt_product_info5'=> $rawData['price']['premiumAmount'] ?? '0',
'rcpt_living_yn' => ($rawData['site']['isRegistration'] ?? false) ? 'Y' : 'N',
'rcpt_agent' => $rawData['realtor']['realtorName'] ?? null,
'rcpt_sido' => mb_substr($rawData['address']['legalDivision']['cityNumber'] ?? '', 0, 5),
'rcpt_gugun' => mb_substr($rawData['address']['legalDivision']['divisionNumber'] ?? '', 0, 10),
'rcpt_dong' => $rawData['address']['legalDivision']['sectorNumber'] ?? null,
'rcpt_hscp_nm' => $rawData['address']['complexName'] ?? null,
'rcpt_hscp_no' => $rawData['address']['complexNumber'] ?? null,
'rcpt_ptp_nm' => null,
'rcpt_ptp_no' => $rawData['address']['pyeongTypeNumber'] ?? null,
'rcpt_dtl_addr' => trim(($rawData['address']['legalDivision']['legalDivisionAddress'] ?? '') . $rawData['address']['buildingName'] . '동 ' . ($rawData['address']['hoName'] ?? '') . '호'),
'rcpt_etc_addr' => $rawData['address']['hoName'] ?? null,
'rcpt_floor' => $rawData['floor']['correspondenceFloorCount'] ?? null,
'rcpt_floor2' => $rawData['floor']['totalFloorCount'] ?? null,
'rcpt_exps_type' => '',
'rcpt_exp_photo_yn' => 'Y',
'rcpt_deal_type' => $rawData['tradeTypeCode'] ?? null,
'rcpt_product_nm' => $rawData['tradeType'] ?? null,
'trade_type' => $trade_type ?? null,
'ground_plan' => $ground_plan,
'excls_spce' => $rawData['space']['exclusiveSpace'] ?? null,
'sply_spc' => $rawData['space']['supplySpace'] ?? null,
'tot_spc' => $rawData['space']['totalSpace'] ?? null,
'grnd_spc' => $rawData['space']['groundSpace'] ?? null,
'bldg_spc' => $rawData['space']['buildingSpace'] ?? null,
'share_spc' => $rawData['space']['supplySpace']-$rawData['space']['exclusiveSpace'] ?? null,
'room_cnt' => $rawData['facilities']['roomCount'] ?? null,
'cupnNo' => $rawData['couponNumber'] ?? null,
'roomSiteAtclRgstCnt' => $rawData['site']['monthlyRegisterCount'] ?? null,
'roomSiteAtclExpsCnt' => $rawData['site']['monthlyExposureCount'] ?? null,
'direct_trad_yn' => ($rawData['seller']['isDirectTrade'] ?? false) ? 'Y' : 'N',
'sellr_nm' => $rawData['seller']['sellerName'] ?? null,
'sellr_tel_no' => $rawData['seller']['sellerTelephoneNumber'] ?? null,
'rcpt_ref_addr' => $rawData['address']['etcAddress'] ?? null,
'rcpt_tm' => $now,
'rcpt_stat' => '100000',
'rcpt_x' => $rawData['address']['longitude'] ?? null,
'rcpt_y' => $rawData['address']['latitude'] ?? null,
'agent_id' => '',
'agent_nm' => $rawData['realtor']['realtorName'] ?? null,
'agent_head_tel' => $rawData['realtor']['representativeCellphoneNumber'] ?? null,
'rsrv_date' => $rawData['site']['visitReserveDate'] ?? null,
'rsrv_tm_ap' => '00', // 컬럼명이 rsrv_tm_ap 인지 확인 필요 (제공해주신 스키마 기준)
'insert_tm' => $now,
'rcpt_cpid' => $rawData['cpId'] ?? 'naver',
'room_cnt' => $rawData['facilities']['roomCount'] ?? null,
'isSiteVRVerification' => ($rawData['site']['isVrVerification'] ?? false) ? 'Y' : 'N',
'isPromotionApply' => ($rawData['site']['isVrRepresentativeApply'] ?? false) ? 'Y' : 'N',
];
if (!$this->receiptModel->insert($receiptData)) {
throw new \Exception("Receipt Insert 실패: " . json_encode($this->receiptModel->errors()));
return $this->typeV2Handler->handle($articleNumber, $rawData, $payload);
}
$rcpt_sq = $this->receiptModel->getInsertID();
if ( $receiptData['isVrVerification'] == "Y") {
$dept_sq = '29';
$usr_sq = '1993';
}
// 2. result 데이터 준비
$resultData = [
'rcpt_sq' => $rcpt_sq,
'use_yn' => 'Y',
'cust_nm' => '',
'rsrv_date' => $rawData['site']['visitReserveDate'] ?? null,
'rsrv_tm_ap' => '00', // 컬럼명이 rsrv_tm_ap 인지 확인 필요 (제공해주신 스키마 기준)
'result_cd1' => '10',
'result_cd2' => '1000',
'result_cd3' => '100000',
'insert_tm' => $now,
'insert_usr' => 0,
'update_tm' => $now,
'update_usr' => 0,
'dept_sq' => $dept_sq, // 필요 시 매핑 로직 추가
'usr_sq' => $usr_sq, // 필요 시 매핑 로직 추가
'resYn' => ($rawData['site']['isRegistration'] ?? false) ? 'Y' : 'N',
];
if (!$this->resultModel->insert($resultData)) {
throw new \Exception("Result Insert 실패");
}
$this->db->transComplete();
// 성공 로그 생성 쿼리 포함
write_custom_log("Type S 처리 성공 | Atcl: $articleNumber | Rcpt_sq: $rcpt_sq", 'INFO', 'service');
write_custom_log("Receipt Insert SQL: " . (string)$this->receiptModel->getLastQuery(), 'INFO', 'service');
write_custom_log("Result Insert SQL: " . (string)$this->resultModel->getLastQuery(), 'INFO', 'service');
// 예약 정보 동기화 전송
$return = $this->naverClient->submitSyncResult($rawData['reserveNo']);
write_custom_log("Naver Sync Result Response: " . json_encode($return), 'INFO', 'service');
// transComplete 이후에 transStatus를 확인하는 것이 CI4의 표준입니다.
if ($this->db->transStatus() === false) {
// transComplete가 실패하면 자동으로 롤백되지만, 명시적 예외 처리가 안전합니다.
// 로그 남기기
write_custom_log("Type S DB 트랜잭션 최종 실패", 'ERROR', 'service');
throw new \Exception("Type S DB 트랜잭션 최종 실패");
}
return $rcpt_sq;
} catch (\Exception $e) {
// 이미 transComplete 내부에서 실패 시 롤백되지만, 예외 발생 시 수동 롤백 보장
// if ($this->db->transEnabled()) {
$this->db->transRollback();
// }
} catch (Exception $e) {
write_custom_log("processArticle 실패: " . $e->getMessage(), 'ERROR', 'service');
throw $e;
}
}
/**
* [Type V2] 일반/서류/비공동주택 처리 로직
*/
private function processTypeV2($articleNumber, $rawData, $payload)
{
CLI::write(CLI::color('🟢 V2_VRFC_REQ :: START ' , 'green'));
$vrfcParam = $this->v2Parameter($articleNumber, $rawData, $payload);
$articleInfoParam = $this->articleInfoParameter($articleNumber, $rawData, $payload);
$articleInfoEtcParam = $this->articleInfoEtcParameter($articleNumber, $rawData, $payload);
try {
switch ($payload['requestType']){
case "REG":
$vr_sq = $this->insertVrfcReq($vrfcParam);
$articleInfoParam['vr_sq'] = $vr_sq;
write_custom_log("articleInfoParam :: " . json_encode($articleInfoParam, JSON_UNESCAPED_UNICODE) , "INFO", "SERVICE");
if (!$this->getModel('articleModel', V2articleinfoModel::class)->insert($articleInfoParam)) {
throw new \Exception("ArticleInfo Insert 실패: " . json_encode($this->db->error()));
}
$articleInfoEtcParam['vr_sq'] = $vr_sq;
if (!$this->getModel('articleEtcModel', V2articleinfoetcModel::class)->insert($articleInfoEtcParam)) {
throw new \Exception("ArticleInfoEtc Insert 실패");
}
break;
case "MOD":
break;
case "CNC":
break;
}
} catch (\Exception $e) {
write_custom_log("CRITICAL_ERROR :: " . $e->getMessage(), "ERROR", "SERVICE");
throw $e;
}
}
/**
* [REG] 신규 등록
*/
private function insertVrfcReq($vrfcParam)
{
CLI::write(CLI::color('🟢 매물 정보 시작', 'green'));
$model = $this->getModel('VrfcReqModel', VrfcReqModel::class);
$existing = $model->where('atcl_no', $vrfcParam['atcl_no'])->first();
if ($existing) throw new \Exception("중복 등록 시도: " . $vrfcParam['atcl_no']);
if (!$model->insert($vrfcParam)) {
$dbError = $this->db->error();
$lastQuery = (string)$model->getLastQuery();
// 🚨 에러 발생 시 상세 정보 출력
CLI::write(CLI::color('❌ SQL INSERT ERROR', 'red', 'bold'));
CLI::write(CLI::color('메시지: ', 'white') . $dbError['message']);
CLI::write(CLI::color('쿼리 실행: ', 'white') . (string)$model->getLastQuery());
// 입력하려던 데이터 덤프 (디버깅용)
CLI::write(CLI::color('입력 데이터:', 'yellow'));
print_r($vrfcParam);
throw new \Exception("신규 등록 실패: " . $dbError['message']);
}
$vr_sq = $model->getInsertID();
CLI::write(CLI::color("✅ Insert 성공 (vr_sq: $vr_sq)", 'blue'));
// 🟢 여기서 Null 에러 방지 (getStatusService 사용)
$this->getStatusService()->recordStatusAndHistory($vr_sq, '10', 'C9', "NEW 신규접수 : 10");
return $vr_sq;
}
private function v2Parameter($articleNumber, $rawData , $payload){
$now = db_now();
$step = isset($rawData['step']) ? $rawData['step'] : '00';
$rdate = $payload['requestDate'] ?? db_now('YmdHis');
$insert_user = 0;
$stat_cd = '10';
$sync_yn = 'N';
$insert_tm = $now;
$reg_type = function($payload) {
switch ($payload['requestType'] ?? '') {
case 'REG': return 'C';
case 'MOD': return 'U';
case 'CNC': return 'D';
default: return '0';
}
};($payload);
$files = $rawData['files'] ?? [];
$certRegister = [];
$confirm_doc_img_url = [];
$referenceFileUrl = [];
foreach ($files as $file) {
$fileTypeCode = $file['fileTypeCode'];
if ($fileTypeCode == 'RCDOC') {
$certRegister[] = $file['originalFileUrl'];
} elseif ($fileTypeCode == 'ADDOC') {
$confirm_doc_img_url[] = $file['originalFileUrl'];
} elseif ($fileTypeCode == 'REFER') {
$referenceFileUrl[] = $file['originalFileUrl'];
}
}
// 1. v2_vrfc_req (검증요청) 데이터 준비
$vrfcReqData = [
'reqSeq' => '', // 네이버 요청 고유 ID
'atcl_no' => $articleNumber,
'step' => $step, // 기본 단계 설정
'cpid' => $rawData['cpId'] ?? 'naver',
'cp_atcl_id' => $rawData['cpArticleNumber'] ?? '',
'trade_type' => $rawData['tradeTypeCode'] ?? '',
'realtor_nm' => $rawData['realtor']['realtorName'] ?? null,
'realtor_tel_no' => $rawData['realtor']['representativeCellphoneNumber'] ?? null,
'seller_tel_no' => $rawData['seller']['cellphoneNumber'] ?? null,
'vrfc_type' => $rawData['verificationTypeCode'] ?? 'D', // D, T, P 등
'rgbk_confirm' => null,
'req_type' => $reg_type($payload), // 등록:C, 수정:U, 취소:D
'rdate' => $rdate,
'cpTelNo' => null,
'stat_cd' => $stat_cd, // 초기 대기 상태
'insert_user' => $insert_user,
'insert_tm' => $insert_tm,
'sync_yn' => $sync_yn,
'rgbk_confirm_owner_nm' => null,
'direct_trad_yn' => ($rawData['seller']['isDirectTrade'] ?? false) ? 'Y' : 'N',
'confirm_doc_img_url' => json_encode($confirm_doc_img_url),
'confirm_doc_owner_check_yn' => null,
'certRegister' => json_encode($certRegister),
'referenceFileUrl' => json_encode($referenceFileUrl),
];
return $vrfcReqData;
}
private function articleInfoParameter($articleNumber, $rawData , $payload){
// JSON 객체 안전하게 로드
$address = $rawData['address'] ?? [];
$space = $rawData['space'] ?? [];
$price = $rawData['price'] ?? [];
$floor = $rawData['floor'] ?? [];
$seller = $rawData['seller'] ?? [];
$realtor = $rawData['realtor'] ?? [];
$files = $rawData['realtor']['file'] ?? [];
$certRegister = [];
$confirm_doc_img_url = [];
$referenceFileUrl = [];
foreach ($files as $file) {
$fileTypeCode = $file['fileTypeCode'];
if ($fileTypeCode == 'RCDOC') {
$certRegister[] = $file['originalFileUrl'];
} elseif ($fileTypeCode == 'ADDOC') {
$confirm_doc_img_url[] = $file['originalFileUrl'];
} elseif ($fileTypeCode == 'REFER') {
$referenceFileUrl[] = $file['originalFileUrl'];
}
}
$ownerTypeCodeRaw = $rawData['ownerTypeCode'] ?? null;
$ownerTypeCode = match($ownerTypeCodeRaw) {
"INDIV" => 0,
"CORP" => 1,
"FRGNR" => 2,
"DELEG" => 3,
default => null,
};
$ownerCheckYn = ($seller['isOwnerCertificationAgree'] ?? false) ? 'Y' : 'N';
return [
// 'vr_sq' => $vr_sq,
'atcl_no' => $articleNumber,
'cpid' => $rawData['cpId'] ?? null,
'cp_atcl_id' => $rawData['cpArticleNumber'] ?? null,
'rlet_type_cd' => $rawData['realEstateTypeCode'] ?? null,
'trade_type' => $rawData['tradeTypeCode'] ?? null,
'address_code' => $address['legalDivision']['sectorNumber'] ?? null,
'address1' => $address['complexName'] ?? null,
'address2' => trim(($address['buildingName'] ?? '') . ' ' . ($address['hoName'] ?? '')),
'address3' => $address['legalDivision']['legalDivisionAddress'] ?? null,
// 면적 및 가격 (데이터 없으면 null)
'sply_spc' => $space['supplySpace'] ?? null,
'excls_spc' => $space['exclusiveSpace'] ?? null,
'tot_spc' => $space['totalSpace'] ?? null,
'grnd_spc' => $space['groundSpace'] ?? null,
'bldg_spc' => $space['buildingSpace'] ?? null,
'deal_amt' => $price['dealAmount'] ?? 0,
'wrrnt_amt' => $price['warrantyAmount'] ?? 0,
'lease_amt' => $price['leaseAmount'] ?? 0,
'isale_amt' => $price['preSaleAmount'] ?? 0,
'prem_amt' => $price['premiumAmount'] ?? 0,
'sise' => null,
// 층 및 일정
'floor' => $floor['correspondenceFloorCount'] ?? null,
'floor2' => $floor['totalFloorCount'] ?? null,
'rdate' => date("Y-m-d H:i:s" , strtotime( $payload['requestDatetime'] )),
// 셀러
'seller_tel_no' => $seller['sellerTelephoneNumber'] ?? null, // JSON seller 객체에 연락처 필드 부재
'seller_nm' => $seller['sellerName'] ?? null,
// 중개업소
'realtor_nm' => $realtor['realtorName'] ?? null,
'realtor_tel_no' => $realtor['representativeTelephoneNumber'] ?? null,
// 단지 정보
'hscp_no' => $address['complexNumber'] ?? null,
'hscp_nm' => $address['complexName'] ?? null,
'ptp_no' => $address['pyeongTypeNumber'] ?? null,
'ptp_nm' => $address['pyeongTypeNumber'] ?? null,
// 담당자
'charger' => null, // 담당자
'reg_price_yn' => 'N', // 가격수정요청여부
'reg_charger' => null, // 등기부등본 담당자
'dept1_sq' => null, // 부서(본부)
'dept2_sq' => null, // 부서(팀)
'reg_dept2_sq' => null, // 부서(팀)
'reg_dept1_sq' => null, // 부서(본부)
// 상태 및 기타
'dong_ho_chk' => ($address['isDongHoCheck'] ?? false) ? 'Y' : 'N',
'hscplqry_lv' => $address['inquiryLevel'] ?? null,
// 소유자
'ownerNm' => $seller['ownerName'] ?? null,
'ownerTelNo' => $seller['ownerName'] ?? null,
//
'chg_trade_type' => null,
'chg_address2' => null,
'chg_address3' => null,
'chg_seller_tel' => null,
'chg_amt' => null,
'reg_status' => null,
'cupnNo' => null,
'roomSiteAtclRgstCnt' => null,
'rootSiteAtclExpsCnt' => null,
'redvlp_area_nm' => $address['redevelopAreaName'] ?? null,
'biz_stp_desc' => $address['bizStepDescription'] ?? null,
// file
'cert_register' => json_encode($certRegister, JSON_UNESCAPED_UNICODE),
'direct_trad_yn' => ($seller['isDirectTrade'] ?? false) ? 'Y' : 'N',
'confirm_doc_img_url' => json_encode( $confirm_doc_img_url , JSON_UNESCAPED_UNICODE),
'confirm_doc_owner_check_yn' => $ownerCheckYn,
'owner_birth' => null,
'vrfc_type_sub' => ($rawData['verificationTypeCode'] === 'D') ? ($ownerCheckYn === 'Y' ? 'D2' : 'D1') : ($rawData['verificationTypeCode'] === 'N' ? 'N2' : $rawData['verificationTypeCode'] . '1'),
'cert_register_save_yn' => 'N',
'confirm_doc_img_url_save_yn' => 'N',
'address4' => $address['etcAddress'] ?? null,
'reference_file_url' => !empty($referenceFileUrl) ? implode('|', $referenceFileUrl) : '',
'reference_file_url_save_yn' => !empty($referenceFileUrl) ? 'Y' : 'N',
'registerBookUniqueNo' => $rawData['verificationReference'] ?? null,
'relationSellerAndOwner' => null,
'ownerTypeCode' => $ownerTypeCode,
'registerBookUniqueNumber' => null
];
}
private function articleInfoEtcParameter($articleNumber, $rawData , $payload){
// JSON 객체 안전하게 로드
$address = $rawData['address'] ?? [];
$space = $rawData['space'] ?? [];
$price = $rawData['price'] ?? [];
$floor = $rawData['floor'] ?? [];
$seller = $rawData['seller'] ?? [];
$realtor = $rawData['realtor'] ?? [];
$files = $rawData['realtor']['file'] ?? [];
// 공동 : 동 정보, 비공동 : 지번주소
if ( $rawData['realEstateTypeCode'] == "A01"){
$address2b = $address['buildingName'];
} else {
$address2b = $address['jibunAddress'] ?? null;
}
$ownerTypeCode = null;
$ownerTypeCodeResponse = isset($rawData['ownerTypeCode']) ?? null;
if ($ownerTypeCodeResponse !== null ){
switch ($ownerTypeCodeResponse) {
case "INDIV":
$ownerTypeCode = 0;
break;
case "CORP":
$ownerTypeCode = 1;
break;
case "FRGNR":
$ownerTypeCode = 2;
break;
case "DELEG":
$ownerTypeCode = 3;
break;
}
}
return [
'atcl_no' => $articleNumber,
'vir_addr_yn' => ($address['isVirtualAddress'] ?? null) === true ? 'Y' : (($address['isVirtualAddress'] ?? null) === false ? 'N' : null),
'bild_no' => null,
'vrfcMthdTpcd' => null,
'cert_uncnfrm_status' => null,
'expsStartYmdt' => $rawData['exposureStartDateTime'] ?? null,
'vrfcAutoPassYn' => ($rawData['isAutoVerificationRequested'] ?? false) === true ? "Y" : "N",
'address2a' => $address['liAddress'] ?? null,
'address2b' => $address2b,
'registerBookUniqueNo' => null,
'ownerTypeCode' => $ownerTypeCode,
'orgRepCphNo' => null,
'orgRepTelNo' => null,
'orgRltrNm' => null,
'orgRepNm' => null,
'smsSendTime' => null,
'document_cert_method' => null,
'noRgbkVrfcReqYn' => ($address['isUnregisteredVerificationRequested'] ?? null) === true ? 'Y' : (($address['isUnregisteredVerificationRequested'] ?? null) === false ? 'N' : null),
'areaByBdbkVrfcReqYn' => ($address['isBuildingRegisterAreaCheckRequested'] ?? null) === true ? 'Y' : (($address['isBuildingRegisterAreaCheckRequested'] ?? null) === false ? 'N' : null),
'orgAtclNo' => null,
'atclStatCd' => null,
'repNm' => $realtor['realtorName'] ?? null,
'cpName' => $rawData['cpId'],
'document_not_received' => null,
'final_failure' => null,
];
}
}

View File

@@ -0,0 +1,139 @@
<?php
namespace App\Services\ParameterMapper;
/**
* 파라미터 매퍼 기본 추상 클래스
* 네이버 API 응답을 데이터베이스 파라미터로 변환하는 로직을 정의
*/
abstract class BaseParameterMapper
{
protected $db;
public function __construct()
{
$this->db = \Config\Database::connect();
helper('log');
}
/**
* 추상 메서드: 매핑 로직 구현
*/
abstract public function map(string $articleNumber, array $rawData, array $payload): array;
/**
* 소유자 타입 코드 변환
*/
protected function mapOwnerTypeCode(?string $ownerTypeCodeRaw): ?int
{
return match($ownerTypeCodeRaw) {
"INDIV" => 0,
"CORP" => 1,
"FRGNR" => 2,
"DELEG" => 3,
default => null,
};
}
/**
* 거래 유형 변환
*/
protected function mapTradeType(?string $tradeType): ?string
{
return match(trim($tradeType ?? '')) {
'매매' => 'A1',
'전세' => 'B1',
'월세' => 'B2',
'단기임대' => 'B3',
default => null,
};
}
/**
* 파일 배열 추출 (save_yn 플래그 포함)
*/
public function extractFilesByType(array $files): array
{
$certRegister = [];
$confirmDocImgUrl = [];
$referenceFileUrl = [];
foreach ($files as $file) {
$fileTypeCode = $file['fileTypeCode'] ?? '';
$fileUrl = $file['originalFileUrl'] ?? '';
switch ($fileTypeCode) {
case 'RCDOC':
$certRegister[] = $fileUrl;
break;
case 'ADDOC':
$confirmDocImgUrl[] = $fileUrl;
break;
case 'REFER':
$referenceFileUrl[] = $fileUrl;
break;
}
}
return [
'certRegister' => $certRegister,
'confirmDocImgUrl' => $confirmDocImgUrl,
'referenceFileUrl' => $referenceFileUrl,
'cert_register_save_yn' => !empty($certRegister) ? 'Y' : 'N',
'confirm_doc_img_url_save_yn' => !empty($confirmDocImgUrl) ? 'Y' : 'N',
'reference_file_url_save_yn' => !empty($referenceFileUrl) ? 'Y' : 'N',
];
}
/**
* 파일 URL을 v2_url_img_save 테이블에 저장
* @param array $files 파일 배열
* @param string $atclNo 매물번호
* @param int $vrSq 검증요청순번
*/
protected function saveUrlImagesToDb(array $files, string $atclNo, int $vrSq): bool
{
if (empty($files)) {
return true;
}
$urlImgModel = new \App\Models\Entities\V2urlimgsaveModel();
foreach ($files as $file) {
$fileTypeCode = $file['fileTypeCode'] ?? '';
$fileUrl = $file['originalFileUrl'] ?? '';
if (empty($fileUrl)) {
continue;
}
// type 매핑: RCDOC, ADDOC = 2(등기), REFER = 1(홍보)
$type = in_array($fileTypeCode, ['RCDOC', 'ADDOC']) ? '2' : '1';
$data = [
'url' => $fileUrl,
'type' => $type,
'atcl_no' => $atclNo,
'vr_sq' => $vrSq,
'status' => 'save',
'try_cnt' => 0,
'server_nm' => gethostname(),
];
if (!$urlImgModel->insert($data)) {
write_custom_log("URL 이미지 저장 실패: " . json_encode($data), 'ERROR', 'service');
return false;
}
}
return true;
}
/**
* 필수 필드 안전하게 로드
*/
protected function getSafeData(array $data, string $key, $default = null)
{
return $data[$key] ?? $default;
}
}

View File

@@ -0,0 +1,131 @@
<?php
namespace App\Services\ParameterMapper;
/**
* Type S 파라미터 매퍼
* 현장확인 매물 (A01 등) 데이터를 Receipt 테이블용 파라미터로 변환
*/
class TypeSParameterMapper extends BaseParameterMapper
{
/**
* Receipt 테이블용 파라미터 생성
*/
public function mapReceipt(string $articleNumber, array $rawData, array $payload): array
{
$now = db_now();
$address = $rawData['address'] ?? [];
$space = $rawData['space'] ?? [];
$price = $rawData['price'] ?? [];
$floor = $rawData['floor'] ?? [];
$seller = $rawData['seller'] ?? [];
$realtor = $rawData['realtor'] ?? [];
// 평면도 여부 결정
$groundPlan = in_array($rawData['realEstateTypeCode'] ?? '', ['C01', 'C02']) ? 'N' : 'Y';
// 거래 유형 매핑
$tradeType = $this->mapTradeType($rawData['tradeType'] ?? null);
return [
'comp_sq' => '2',
'rcpt_rating' => '3',
'rcpt_key' => $articleNumber,
'rcpt_atclno' => $articleNumber,
'rcpt_product' => $rawData['realEstateTypeCode'] ?? null,
'rcpt_product_nm' => $rawData['realEstateType'] ?? null,
'rcpt_product_info1' => $rawData['tradeType'] ?? null,
'rcpt_product_info2' => $price['dealAmount'] ?? '0',
'rcpt_product_info4' => $price['preSaleAmount'] ?? '0',
'rcpt_product_info5' => $price['premiumAmount'] ?? '0',
'rcpt_living_yn' => ($rawData['site']['isRegistration'] ?? false) ? 'Y' : 'N',
'rcpt_agent' => $realtor['realtorName'] ?? null,
'rcpt_sido' => mb_substr($address['legalDivision']['cityNumber'] ?? '', 0, 5),
'rcpt_gugun' => mb_substr($address['legalDivision']['divisionNumber'] ?? '', 0, 10),
'rcpt_dong' => $address['legalDivision']['sectorNumber'] ?? null,
'rcpt_hscp_nm' => $address['complexName'] ?? null,
'rcpt_hscp_no' => $address['complexNumber'] ?? null,
'rcpt_ptp_nm' => null,
'rcpt_ptp_no' => $address['pyeongTypeNumber'] ?? null,
'rcpt_dtl_addr' => trim(
($address['legalDivision']['legalDivisionAddress'] ?? '') .
($address['buildingName'] ?? '') .
'동 ' . ($address['hoName'] ?? '') . '호'
),
'rcpt_etc_addr' => $address['hoName'] ?? null,
'rcpt_floor' => $floor['correspondenceFloorCount'] ?? null,
'rcpt_floor2' => $floor['totalFloorCount'] ?? null,
'rcpt_exps_type' => '',
'rcpt_exp_photo_yn' => 'Y',
'rcpt_deal_type' => $rawData['tradeTypeCode'] ?? null,
'trade_type' => $tradeType,
'ground_plan' => $groundPlan,
'excls_spce' => $space['exclusiveSpace'] ?? null,
'sply_spc' => $space['supplySpace'] ?? null,
'tot_spc' => $space['totalSpace'] ?? null,
'grnd_spc' => $space['groundSpace'] ?? null,
'bldg_spc' => $space['buildingSpace'] ?? null,
'share_spc' => ($space['supplySpace'] ?? 0) - ($space['exclusiveSpace'] ?? 0),
'room_cnt' => $rawData['facilities']['roomCount'] ?? null,
'cupnNo' => $rawData['couponNumber'] ?? null,
'roomSiteAtclRgstCnt' => $rawData['site']['monthlyRegisterCount'] ?? null,
'roomSiteAtclExpsCnt' => $rawData['site']['monthlyExposureCount'] ?? null,
'direct_trad_yn' => ($seller['isDirectTrade'] ?? false) ? 'Y' : 'N',
'sellr_nm' => $seller['sellerName'] ?? null,
'sellr_tel_no' => $seller['sellerTelephoneNumber'] ?? null,
'rcpt_ref_addr' => $address['etcAddress'] ?? null,
'rcpt_tm' => $now,
'rcpt_stat' => '100000',
'rcpt_x' => $address['longitude'] ?? null,
'rcpt_y' => $address['latitude'] ?? null,
'agent_id' => '',
'agent_nm' => $realtor['realtorName'] ?? null,
'agent_head_tel' => $realtor['representativeCellphoneNumber'] ?? null,
'rsrv_date' => $rawData['site']['visitReserveDate'] ?? null,
'rsrv_tm_ap' => '00',
'insert_tm' => $now,
'rcpt_cpid' => $rawData['cpId'] ?? 'naver',
'isSiteVRVerification' => ($rawData['site']['isVrVerification'] ?? false) ? 'Y' : 'N',
'isPromotionApply' => ($rawData['site']['isVrRepresentativeApply'] ?? false) ? 'Y' : 'N',
];
}
/**
* Result 테이블용 파라미터 생성
*/
public function mapResult(int $rcptSq, array $rawData): array
{
$now = db_now();
// VR 검증 여부에 따른 담당자 설정
$deptSq = ($rawData['site']['isVrVerification'] ?? false) ? '29' : null;
$usrSq = ($rawData['site']['isVrVerification'] ?? false) ? '1993' : null;
return [
'rcpt_sq' => $rcptSq,
'use_yn' => 'Y',
'cust_nm' => '',
'rsrv_date' => $rawData['site']['visitReserveDate'] ?? null,
'rsrv_tm_ap' => '00',
'result_cd1' => '10',
'result_cd2' => '1000',
'result_cd3' => '100000',
'insert_tm' => $now,
'insert_usr' => 0,
'update_tm' => $now,
'update_usr' => 0,
'dept_sq' => $deptSq,
'usr_sq' => $usrSq,
'resYn' => ($rawData['site']['isRegistration'] ?? false) ? 'Y' : 'N',
];
}
/**
* 인터페이스 구현: 기본 map 메서드
* (실제로는 mapReceipt와 mapResult를 분리하여 사용)
*/
public function map(string $articleNumber, array $rawData, array $payload): array
{
return $this->mapReceipt($articleNumber, $rawData, $payload);
}
}

View File

@@ -0,0 +1,276 @@
<?php
namespace App\Services\ParameterMapper;
/**
* Type V2 파라미터 매퍼
* 일반/서류/비공동 매물 데이터를 V2 테이블용 파라미터로 변환
*/
class TypeV2ParameterMapper extends BaseParameterMapper
{
/**
* V2 검증 요청 파라미터 생성
*/
public function mapVrfcReq(string $articleNumber, array $rawData, array $payload): array
{
$now = db_now();
$step = $rawData['step'] ?? '00';
$rdate = $payload['requestDate'] ?? db_now('YmdHis');
$files = $rawData['files'] ?? [];
$fileExtracted = $this->extractFilesByType($files);
$reqType = $this->mapRequestType($payload['requestType'] ?? '');
return [
'reqSeq' => '',
'atcl_no' => $articleNumber,
'step' => $step,
'cpid' => $rawData['cpId'] ?? 'naver',
'cp_atcl_id' => $rawData['cpArticleNumber'] ?? '',
'trade_type' => $rawData['tradeTypeCode'] ?? '',
'realtor_nm' => $rawData['realtor']['realtorName'] ?? null,
'realtor_tel_no' => $rawData['realtor']['representativeCellphoneNumber'] ?? null,
'seller_tel_no' => $rawData['seller']['cellphoneNumber'] ?? null,
'vrfc_type' => $rawData['verificationTypeCode'] ?? 'D',
'rgbk_confirm' => null,
'req_type' => $reqType,
'rdate' => $rdate,
'cpTelNo' => null,
'stat_cd' => '10',
'insert_user' => 0,
'insert_tm' => $now,
'sync_yn' => 'N',
'rgbk_confirm_owner_nm' => null,
'direct_trad_yn' => ($rawData['seller']['isDirectTrade'] ?? false) ? 'Y' : 'N',
'confirm_doc_img_url' => json_encode($fileExtracted['confirmDocImgUrl']),
'confirm_doc_owner_check_yn' => null,
'certRegister' => json_encode($fileExtracted['certRegister']),
'referenceFileUrl' => json_encode($fileExtracted['referenceFileUrl']),
];
}
/**
* 기사 정보 파라미터 생성
*/
public function mapArticleInfo(string $articleNumber, array $rawData, array $payload): array
{
$address = $rawData['address'] ?? [];
$space = $rawData['space'] ?? [];
$price = $rawData['price'] ?? [];
$floor = $rawData['floor'] ?? [];
$seller = $rawData['seller'] ?? [];
$realtor = $rawData['realtor'] ?? [];
$files = $rawData['files'] ?? [];
$fileExtracted = $this->extractFilesByType($files);
$ownerTypeCode = $this->mapOwnerTypeCode($rawData['ownerTypeCode'] ?? null);
$ownerCheckYn = ($seller['isOwnerCertificationAgree'] ?? false) ? 'Y' : 'N';
$vrfcTypeSub = $this->mapVrfcTypeSub($rawData['verificationTypeCode'] ?? '', $ownerCheckYn);
return [
'atcl_no' => $articleNumber,
'cpid' => $rawData['cpId'] ?? null,
'cp_atcl_id' => $rawData['cpArticleNumber'] ?? null,
'rlet_type_cd' => $rawData['realEstateTypeCode'] ?? null,
'trade_type' => $rawData['tradeTypeCode'] ?? null,
'address_code' => $address['legalDivision']['sectorNumber'] ?? null,
'address1' => $address['complexName'] ?? null,
'address2' => trim(($address['buildingName'] ?? '') . ' ' . ($address['hoName'] ?? '')),
'address3' => $address['legalDivision']['legalDivisionAddress'] ?? null,
'sply_spc' => $space['supplySpace'] ?? null,
'excls_spc' => $space['exclusiveSpace'] ?? null,
'tot_spc' => $space['totalSpace'] ?? null,
'grnd_spc' => $space['groundSpace'] ?? null,
'bldg_spc' => $space['buildingSpace'] ?? null,
'deal_amt' => $price['dealAmount'] ?? 0,
'wrrnt_amt' => $price['warrantyAmount'] ?? 0,
'lease_amt' => $price['leaseAmount'] ?? 0,
'isale_amt' => $price['preSaleAmount'] ?? 0,
'prem_amt' => $price['premiumAmount'] ?? 0,
'sise' => null,
'floor' => $floor['correspondenceFloorCount'] ?? null,
'floor2' => $floor['totalFloorCount'] ?? null,
'rdate' => date("Y-m-d H:i:s", strtotime($payload['requestDatetime'] ?? 'now')),
'seller_tel_no' => $seller['sellerTelephoneNumber'] ?? null,
'seller_nm' => $seller['sellerName'] ?? null,
'realtor_nm' => $realtor['realtorName'] ?? null,
'realtor_tel_no' => $realtor['representativeTelephoneNumber'] ?? null,
'hscp_no' => $address['complexNumber'] ?? null,
'hscp_nm' => $address['complexName'] ?? null,
'ptp_no' => $address['pyeongTypeNumber'] ?? null,
'ptp_nm' => $address['pyeongTypeNumber'] ?? null,
'charger' => null,
'reg_price_yn' => 'N',
'reg_charger' => null,
'dept1_sq' => null,
'dept2_sq' => null,
'reg_dept2_sq' => null,
'reg_dept1_sq' => null,
'dong_ho_chk' => ($address['isDongHoCheck'] ?? false) ? 'Y' : 'N',
'hscplqry_lv' => $address['inquiryLevel'] ?? null,
'ownerNm' => $seller['ownerName'] ?? null,
'ownerTelNo' => $seller['ownerName'] ?? null,
'chg_trade_type' => null,
'chg_address2' => null,
'chg_address3' => null,
'chg_seller_tel' => null,
'chg_amt' => null,
'reg_status' => null,
'cupnNo' => null,
'roomSiteAtclRgstCnt' => null,
'rootSiteAtclExpsCnt' => null,
'redvlp_area_nm' => $address['redevelopAreaName'] ?? null,
'biz_stp_desc' => $address['bizStepDescription'] ?? null,
'cert_register' => json_encode($fileExtracted['certRegister'], JSON_UNESCAPED_UNICODE),
'direct_trad_yn' => ($seller['isDirectTrade'] ?? false) ? 'Y' : 'N',
'confirm_doc_img_url' => json_encode($fileExtracted['confirmDocImgUrl'], JSON_UNESCAPED_UNICODE),
'confirm_doc_owner_check_yn' => $ownerCheckYn,
'owner_birth' => null,
'vrfc_type_sub' => $vrfcTypeSub,
'cert_register_save_yn' => $fileExtracted['cert_register_save_yn'] ?? 'N',
'confirm_doc_img_url_save_yn' => $fileExtracted['confirm_doc_img_url_save_yn'] ?? 'N',
'address4' => $address['etcAddress'] ?? null,
'reference_file_url' => !empty($fileExtracted['referenceFileUrl']) ? implode('|', $fileExtracted['referenceFileUrl']) : '',
'reference_file_url_save_yn' => $fileExtracted['reference_file_url_save_yn'] ?? 'N',
'registerBookUniqueNo' => $rawData['verificationReference'] ?? null,
'relationSellerAndOwner' => null,
'ownerTypeCode' => $ownerTypeCode,
'registerBookUniqueNumber' => null
];
}
/**
* 기사 정보 추가 파라미터 생성
*/
public function mapArticleInfoEtc(string $articleNumber, array $rawData): array
{
$address = $rawData['address'] ?? [];
$realtor = $rawData['realtor'] ?? [];
// 공동주택: 동 정보, 비공동: 지번주소
$address2b = ($rawData['realEstateTypeCode'] === 'A01')
? $address['buildingName']
: ($address['jibunAddress'] ?? null);
$ownerTypeCode = $this->mapOwnerTypeCode($rawData['ownerTypeCode'] ?? null);
return [
'atcl_no' => $articleNumber,
'vir_addr_yn' => $this->mapYesNo($address['isVirtualAddress'] ?? null),
'bild_no' => null,
'vrfcMthdTpcd' => null,
'cert_uncnfrm_status' => null,
'expsStartYmdt' => $rawData['exposureStartDateTime'] ?? null,
'vrfcAutoPassYn' => ($rawData['isAutoVerificationRequested'] ?? false) ? 'Y' : 'N',
'address2a' => $address['liAddress'] ?? null,
'address2b' => $address2b,
'registerBookUniqueNo' => null,
'ownerTypeCode' => $ownerTypeCode,
'orgRepCphNo' => null,
'orgRepTelNo' => null,
'orgRltrNm' => null,
'orgRepNm' => null,
'smsSendTime' => null,
'document_cert_method' => null,
'noRgbkVrfcReqYn' => $this->mapYesNo($address['isUnregisteredVerificationRequested'] ?? null),
'areaByBdbkVrfcReqYn' => $this->mapYesNo($address['isBuildingRegisterAreaCheckRequested'] ?? null),
'orgAtclNo' => null,
'atclStatCd' => null,
'repNm' => $realtor['realtorName'] ?? null,
'cpName' => $rawData['cpId'],
'document_not_received' => null,
'final_failure' => null,
];
}
/**
* modify_info 파라미터 생성
*/
public function mapModifyInfo(string $articleNumber, array $rawData, array $payload): array
{
$address = $rawData['address'] ?? [];
$space = $rawData['space'] ?? [];
$price = $rawData['price'] ?? [];
$floor = $rawData['floor'] ?? [];
// 공동주택: 동 정보, 비공동: 지번주소
$address2b = ($rawData['realEstateTypeCode'] === 'A01')
? $address['buildingName']
: ($address['jibunAddress'] ?? null);
return [
'atcl_no' => $articleNumber,
'bild_nm' => $address['buildingName'] ?? null,
'rm_no' => $address['hoName'] ?? null,
'floor' => $floor['correspondenceFloorCount'] ?? null,
'floor2' => $floor['totalFloorCount'] ?? null,
'address_code' => $address['legalDivision']['sectorNumber'] ?? null,
'address2' => trim(($address['buildingName'] ?? '') . ' ' . ($address['hoName'] ?? '')),
'address2a' => $address['liAddress'] ?? null,
'address2b' => $address2b,
'address3' => $address['legalDivision']['legalDivisionAddress'] ?? null,
'address4' => $address['etcAddress'] ?? null,
'trade_type' => $rawData['tradeTypeCode'] ?? null,
'deal_amt' => $price['dealAmount'] ?? 0,
'wrrnt_amt' => $price['warrantyAmount'] ?? 0,
'lease_amt' => $price['leaseAmount'] ?? 0,
'isale_amt' => $price['preSaleAmount'] ?? 0,
'prem_amt' => $price['premiumAmount'] ?? 0,
'sply_spc' => $space['supplySpace'] ?? null,
'excls_spc' => $space['exclusiveSpace'] ?? null,
'tot_spc' => $space['totalSpace'] ?? null,
'grnd_spc' => $space['groundSpace'] ?? null,
'bldg_spc' => $space['buildingSpace'] ?? null,
'hscp_no' => $address['complexNumber'] ?? null,
'hscp_nm' => $address['complexName'] ?? null,
'ptp_no' => $address['pyeongTypeNumber'] ?? null,
'ptp_nm' => $address['pyeongTypeNumber'] ?? null,
'modify_yn' => 'N'
];
}
/**
* 인터페이스 구현
*/
public function map(string $articleNumber, array $rawData, array $payload): array
{
return $this->mapVrfcReq($articleNumber, $rawData, $payload);
}
/**
* 요청 타입 매핑
*/
private function mapRequestType(string $requestType): string
{
return match($requestType) {
'REG' => 'C',
'MOD' => 'U',
'CNC' => 'D',
default => '0',
};
}
/**
* 검증 타입 세부 매핑
*/
private function mapVrfcTypeSub(string $vrfcType, string $ownerCheckYn): string
{
return match($vrfcType) {
'D' => $ownerCheckYn === 'Y' ? 'D2' : 'D1',
'N' => 'N2',
default => $vrfcType . '1',
};
}
/**
* boolean을 Y/N으로 변환
*/
private function mapYesNo($value): ?string
{
if ($value === true) return 'Y';
if ($value === false) return 'N';
return null;
}
}