새로운 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,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;
}
}