worker 수정
This commit is contained in:
19
app/Models/Entities/NaverRawStagingModel.php
Normal file
19
app/Models/Entities/NaverRawStagingModel.php
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
<?php
|
||||||
|
namespace App\Models\Entities;
|
||||||
|
use CodeIgniter\Model;
|
||||||
|
|
||||||
|
class NaverRawStagingModel extends Model {
|
||||||
|
protected $table = 'naver_raw_staging';
|
||||||
|
protected $allowedFields = ['atcl_no', 'verification_type', 'request_type', 'raw_json'];
|
||||||
|
|
||||||
|
// 데이터를 넣기 전 자동으로 json_encode 실행
|
||||||
|
protected $beforeInsert = ['encodeJson'];
|
||||||
|
protected $beforeUpdate = ['encodeJson'];
|
||||||
|
|
||||||
|
protected function encodeJson(array $data) {
|
||||||
|
if (isset($data['data']['raw_json']) && is_array($data['data']['raw_json'])) {
|
||||||
|
$data['data']['raw_json'] = json_encode($data['data']['raw_json'], JSON_UNESCAPED_UNICODE);
|
||||||
|
}
|
||||||
|
return $data;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -9,6 +9,16 @@ class ReceiptModel extends Model
|
|||||||
protected $table = 'receipt';
|
protected $table = 'receipt';
|
||||||
protected $primaryKey = 'rcpt_sq';
|
protected $primaryKey = 'rcpt_sq';
|
||||||
|
|
||||||
|
// insert를 위해 이 줄을 추가해 주세요. (제공해주신 스키마 기반 주요 필드)
|
||||||
|
protected $allowedFields = [
|
||||||
|
'comp_sq', 'rcpt_rating', 'rcpt_key', 'rcpt_atclno', 'rcpt_type',
|
||||||
|
'rcpt_product', 'rcpt_product_nm', 'rcpt_product_info1', 'rcpt_product_info2',
|
||||||
|
'rcpt_product_info3', 'rcpt_office', 'rcpt_agent', 'rcpt_sido', 'rcpt_hscp_nm',
|
||||||
|
'rcpt_dtl_addr', 'rcpt_etc_addr', 'rcpt_floor', 'rcpt_floor2', 'rcpt_tm',
|
||||||
|
'rcpt_stat', 'rcpt_x', 'rcpt_y', 'agent_nm', 'agent_head_tel', 'rsrv_date',
|
||||||
|
'insert_tm', 'rcpt_cpid', 'room_cnt', 'isSiteVRVerification'
|
||||||
|
];
|
||||||
|
|
||||||
public function getReceiptList($params, $pageNum = 1, $pageSize = 20, $total = false)
|
public function getReceiptList($params, $pageNum = 1, $pageSize = 20, $total = false)
|
||||||
{
|
{
|
||||||
$builder = $this->db->table('receipt a');
|
$builder = $this->db->table('receipt a');
|
||||||
|
|||||||
43
app/Models/Entities/ResultModel.php
Normal file
43
app/Models/Entities/ResultModel.php
Normal file
@@ -0,0 +1,43 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Models\Entities;
|
||||||
|
|
||||||
|
use CodeIgniter\Model;
|
||||||
|
|
||||||
|
class ResultModel extends Model
|
||||||
|
{
|
||||||
|
protected $table = 'result';
|
||||||
|
protected $primaryKey = 'rsrv_sq';
|
||||||
|
protected $useAutoIncrement = true;
|
||||||
|
protected $returnType = 'array';
|
||||||
|
protected $useSoftDeletes = false; // 스키마에 삭제 플래그가 없으므로 false
|
||||||
|
|
||||||
|
// insert/update 시 허용할 컬럼 목록
|
||||||
|
protected $allowedFields = [
|
||||||
|
'rcpt_sq', 'use_yn', 'dept_sq', 'usr_sq', 'cust_nm',
|
||||||
|
'cust_zip', 'cust_addr1', 'cust_addr2', 'cust_tel1', 'cust_tel2',
|
||||||
|
'rsrv_date', 'rsrv_tm_ap', 'rsrv_tm_hour', 'rsrv_tm_min', 'remark',
|
||||||
|
'req_rec_yn', 'rec_yn', 'rec_tel', 'rec_nm', 'result_cd1',
|
||||||
|
'result_cd2', 'result_cd3', 'rsrv_save_dt', 'assign_save_dt',
|
||||||
|
'photo_save_dt', 'result_save_dt', 'insert_tm', 'insert_usr',
|
||||||
|
'update_tm', 'update_usr', 'result_msg', 'check_cplt_dt',
|
||||||
|
'check_dt', 'record_cplt_dt', 'request_msg', 'rsrv_cplt_dt',
|
||||||
|
'rsrv_delay_dt', 'cancel_dt', 'check_delay_dt', 'check_fail_dt',
|
||||||
|
'resYn', 'dbUsageAgrYn', 'vr_check_cplt_dt'
|
||||||
|
];
|
||||||
|
|
||||||
|
// 날짜 자동 설정 기능 (선택 사항)
|
||||||
|
// 직접 로직에서 date('Y-m-d H:i:s')를 넣으신다면 false로 두셔도 됩니다.
|
||||||
|
protected $useTimestamps = false;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 특정 접수 번호로 결과 정보 조회 (Join 예시)
|
||||||
|
*/
|
||||||
|
public function getResultWithReceipt($rcpt_sq)
|
||||||
|
{
|
||||||
|
return $this->select('result.*, receipt.rcpt_atclno, receipt.rcpt_product_nm')
|
||||||
|
->join('receipt', 'receipt.rcpt_sq = result.rcpt_sq')
|
||||||
|
->where('result.rcpt_sq', $rcpt_sq)
|
||||||
|
->first();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -6,19 +6,30 @@ use CodeIgniter\CLI\CLI;
|
|||||||
use App\Libraries\NaverApiClient;
|
use App\Libraries\NaverApiClient;
|
||||||
use App\Models\Entities\VrfcReqModel;
|
use App\Models\Entities\VrfcReqModel;
|
||||||
use App\Models\Entities\V2stdailyModel;
|
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\StatusService; // 추가
|
||||||
use Exception;
|
use Exception;
|
||||||
|
|
||||||
class NaverService
|
class NaverService
|
||||||
{
|
{
|
||||||
protected $naverClient, $VrfcReqModel, $V2stdailyModel, $statusService;
|
protected $db;
|
||||||
|
protected $naverClient, $VrfcReqModel, $V2stdailyModel, $statusService, $rawStagingModel, $receiptModel, $resultModel;
|
||||||
|
|
||||||
public function __construct()
|
public function __construct()
|
||||||
{
|
{
|
||||||
|
$this->db = \Config\Database::connect();
|
||||||
|
|
||||||
$this->naverClient = new NaverApiClient();
|
$this->naverClient = new NaverApiClient();
|
||||||
$this->VrfcReqModel = model(VrfcReqModel::class);
|
$this->VrfcReqModel = model(VrfcReqModel::class);
|
||||||
$this->V2stdailyModel = model(V2stdailyModel::class);
|
$this->V2stdailyModel = model(V2stdailyModel::class);
|
||||||
|
$this->rawStagingModel = model(NaverRawStagingModel::class);
|
||||||
|
|
||||||
|
$this->receiptModel = model(ReceiptModel::class);
|
||||||
|
$this->resultModel = model(ResultModel::class);
|
||||||
$this->statusService = new StatusService(); // 인스턴스 생성
|
$this->statusService = new StatusService(); // 인스턴스 생성
|
||||||
|
|
||||||
helper('log');
|
helper('log');
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -36,37 +47,161 @@ class NaverService
|
|||||||
throw new \Exception("네이버 API 응답 에러: $articleNumber");
|
throw new \Exception("네이버 API 응답 에러: $articleNumber");
|
||||||
}
|
}
|
||||||
|
|
||||||
$vrfcParams = $this->mapToDatabaseParams($response['data'], $payload);
|
$rawData = $response['data'];
|
||||||
write_custom_log("PROCESS_START | Type: $requestType | Atcl: $articleNumber", 'INFO', 'service');
|
$vType = $rawData['verificationTypeCode'] ?? '';
|
||||||
|
|
||||||
switch ($requestType) {
|
// 2. [Staging] 원본 DB 저장 (JSON 타입 컬럼 활용)
|
||||||
case 'REG': // 신규 등록
|
$this->rawStagingModel->insert([
|
||||||
$vr_sq = $this->insertVrfcReq($articleNumber, $vrfcParams);
|
'atcl_no' => $articleNumber,
|
||||||
if ($vr_sq) $this->V2stdailyModel->set_v2_st_daily(null, $vrfcParams['cpid'], $vrfcParams['vrfc_type'] . '0103', '1', 'add');
|
'verification_type' => $vType,
|
||||||
break;
|
'request_type' => $requestType,
|
||||||
|
'raw_json' => $rawData // 모델에서 json_encode 처리됨
|
||||||
|
]);
|
||||||
|
|
||||||
case 'MOD': // 수정
|
// 3. 타입별 분기 처리
|
||||||
$vr_sq = $this->updateVrfcReq($articleNumber, $vrfcParams);
|
if ($vType === 'S') {
|
||||||
if ($vr_sq) $this->V2stdailyModel->set_v2_st_daily(null, $vrfcParams['cpid'], $vrfcParams['vrfc_type'] . '0102', '1', 'add');
|
// [Type S] 현장확인 응답 처리 (A01 등)
|
||||||
break;
|
return $this->processTypeS($articleNumber, $rawData, $payload);
|
||||||
|
} else {
|
||||||
|
// [Type D/기타] 서류확인/비공동 처리 (D04, F01 등)
|
||||||
|
return $this->processTypeV2($articleNumber, $rawData, $payload);
|
||||||
|
}
|
||||||
|
|
||||||
case 'CNC': // 취소
|
// $vrfcParams = $this->mapToDatabaseParams($response['data'], $payload);
|
||||||
$vr_sq = $this->deleteVrfcReq($articleNumber, $vrfcParams);
|
// write_custom_log("PROCESS_START | Type: $requestType | Atcl: $articleNumber", 'INFO', 'service');
|
||||||
if ($vr_sq) $this->V2stdailyModel->set_v2_st_daily(null, $vrfcParams['cpid'], 'A0101', '1', 'add');
|
|
||||||
break;
|
|
||||||
|
|
||||||
// case 'FIN': // 완료
|
// switch ($requestType) {
|
||||||
// $vr_sq = $this->finVrfcReq($articleNumber, $vrfcParams);
|
// 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');
|
// if ($vr_sq) $this->V2stdailyModel->set_v2_st_daily(null, $vrfcParams['cpid'], 'A0101', '1', 'add');
|
||||||
// break;
|
// break;
|
||||||
|
|
||||||
default:
|
// // case 'FIN': // 완료
|
||||||
throw new \Exception("알 수 없는 requestType: $requestType");
|
// // $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];
|
||||||
}
|
}
|
||||||
|
|
||||||
return ['vr_sq' => $vr_sq, 'articleNumber' => $articleNumber];
|
|
||||||
|
/**
|
||||||
|
* [Type S] 현장확인 응답 처리 (A01 등)
|
||||||
|
*/
|
||||||
|
private function processTypeS($articleNumber, $rawData, $payload)
|
||||||
|
{
|
||||||
|
$now = date('Y-m-d H:i:s');
|
||||||
|
|
||||||
|
// 시작 전 트랜잭션
|
||||||
|
$this->db->transStart();
|
||||||
|
|
||||||
|
try {
|
||||||
|
// 1. receipt 데이터 준비
|
||||||
|
$receiptData = [
|
||||||
|
'comp_sq' => '2',
|
||||||
|
'rcpt_rating' => '3',
|
||||||
|
'rcpt_key' => $rawData['cpArticleNumber'] ?? '',
|
||||||
|
'rcpt_atclno' => $articleNumber,
|
||||||
|
'rcpt_type' => 'C',
|
||||||
|
'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_info3'=> $rawData['price']['leaseAmount'] ?? '0',
|
||||||
|
'rcpt_living_yn' => ($rawData['site']['isRegistration'] ?? false) ? 'Y' : 'N',
|
||||||
|
'rcpt_office' => $rawData['realtor']['realtorName'] ?? null,
|
||||||
|
'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_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_tm' => $now,
|
||||||
|
'rcpt_stat' => '100000',
|
||||||
|
'rcpt_x' => $rawData['address']['longitude'] ?? null,
|
||||||
|
'rcpt_y' => $rawData['address']['latitude'] ?? null,
|
||||||
|
'agent_id' => $rawData['realtor']['realtorName'] ?? null,
|
||||||
|
'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'
|
||||||
|
];
|
||||||
|
|
||||||
|
if (!$this->receiptModel->insert($receiptData)) {
|
||||||
|
throw new \Exception("Receipt Insert 실패: " . json_encode($this->receiptModel->errors()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$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['verificationResult']['isSuccessful'] ?? false) ? 'Y' : 'N',
|
||||||
|
];
|
||||||
|
|
||||||
|
if (!$this->resultModel->insert($resultData)) {
|
||||||
|
throw new \Exception("Result Insert 실패");
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->db->transComplete();
|
||||||
|
|
||||||
|
// transComplete 이후에 transStatus를 확인하는 것이 CI4의 표준입니다.
|
||||||
|
if ($this->db->transStatus() === false) {
|
||||||
|
// transComplete가 실패하면 자동으로 롤백되지만, 명시적 예외 처리가 안전합니다.
|
||||||
|
throw new \Exception("Type S DB 트랜잭션 최종 실패");
|
||||||
|
}
|
||||||
|
|
||||||
|
return $rcpt_sq;
|
||||||
|
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
// 이미 transComplete 내부에서 실패 시 롤백되지만, 예외 발생 시 수동 롤백 보장
|
||||||
|
if ($this->db->transEnabled()) {
|
||||||
|
$this->db->transRollback();
|
||||||
|
}
|
||||||
|
throw $e;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* [REG] 신규 등록
|
* [REG] 신규 등록
|
||||||
*/
|
*/
|
||||||
|
|||||||
Reference in New Issue
Block a user