httpd 코드 수정 202-> 200

This commit is contained in:
2026-01-02 14:50:27 +09:00
parent 094fa7c640
commit 8338df57c9
6 changed files with 306 additions and 27 deletions

View File

@@ -3,8 +3,9 @@
namespace App\Services;
use App\Libraries\NaverApiClient;
use App\Models\V2ArticleModel;
use App\Models\VrfcReqModel;
use App\Models\Entities\V2ArticleModel;
use App\Models\Entities\VrfcReqModel;
use App\Models\Entities\NaverWorkerLogModel; // 새로 만든 테이블용 모델
class NaverService
{
@@ -20,11 +21,19 @@ class NaverService
/**
* 매물 정보를 처리하고 DB에 저장하는 메인 함수
* @param array $payload 큐에서 꺼낸 원본 데이터
* requestType
* REG:수동검증요청
* MOD:매물정보수정-매물제공업체의 매물정보수정으로 재검증요청1차실패 후재검증요청
* CNC:사용자취소
* FIN 서비스-서비스 노출/대기검수완료상태,필요한상태인지확인필요
*/
public function processArticle(array $payload)
{
$articleNumber = $payload['articleNumber'];
$requestDatetime = date('Y-m-d H:i:s', strtotime($payload['requestDatetime'] ?? 'now'));
$requestType = $payload['requestType'] ?? ''; // REG:등록 ,
// 1. 네이버 API 호출
$response = $this->naverClient->getArticleInfo($articleNumber);
@@ -35,16 +44,41 @@ class NaverService
}
$articleInfo = $response['data'];
// 로그 기록
write_custom_log("ARTICLE_INFO | ArticleNumber: $articleNumber", 'INFO', 'service');
// 2. 가공 로직 (insertVrfc에 있던 긴 배열 생성 로직)
$vrfcParams = $this->mapToDatabaseParams($articleInfo, $payload);
//
write_custom_log("VRFC_PARAMS | " . json_encode($vrfcParams, JSON_UNESCAPED_UNICODE), 'INFO', 'service');
switch ($requestType) {
case 'REG':
$vrfcParams['req_type'] = '10';
return $this->handleRegistration($articleNumber, $vrfcParams);
break;
case 'MOD':
$vrfcParams['req_type'] = '20';
return $this->handleModification($articleNumber, $vrfcParams);
break;
case 'CNC':
$vrfcParams['req_type'] = '30';
return $this->handleStatusChange($articleNumber, $vrfcParams);
break;
case 'FIN':
$vrfcParams['req_type'] = '40';
return $this->handleStatusChange($articleNumber, $vrfcParams);
break;
default:
throw new \Exception("알 수 없는 requestType: " . $requestType);
}
// 중복 체크
$existing = $this->VrfcReqModel->where('atcl_no', $articleNumber)
->first();
if ($existing) {
throw new \Exception("중복 요청: " . $articleNumber . " / " . $vrfcParams['req_type']);
}
// 3. DB 저장
if (!$this->VrfcReqModel->insert($vrfcParams)) {
$errorMessages = implode(', ', $this->VrfcReqModel->errors());
@@ -113,4 +147,62 @@ class NaverService
return $vrfc_params;
}
/**
* [REG] 신규 등록 처리
*/
private function handleRegistration($articleNumber, $params)
{
$existing = $this->VrfcReqModel->where('atcl_no', $articleNumber)->first();
if ($existing) {
// 이미 존재한다면 업데이트로 돌리거나 예외 처리
return $this->handleModification($articleNumber, $params);
}
if (!$this->VrfcReqModel->insert($params)) {
throw new \Exception("등록 실패: " . implode(', ', $this->VrfcReqModel->errors()));
}
return $this->VrfcReqModel->getInsertID();
}
/**
* [MOD] 수정 처리
*/
private function handleModification($articleNumber, $params)
{
// 기존 기록이 있는지 확인
$existing = $this->VrfcReqModel->where('atcl_no', $articleNumber)->first();
if (!$existing) {
// 수정 요청인데 데이터가 없으면 새로 등록
return $this->handleRegistration($articleNumber, $params);
}
// 기존 데이터 업데이트 (PK인 reqSeq 기준으로 업데이트)
if (!$this->VrfcReqModel->update($existing['reqSeq'], $params)) {
throw new \Exception("수정 실패: " . implode(', ', $this->VrfcReqModel->errors()));
}
return $existing['reqSeq'];
}
/**
* [CNC / FIN] 상태값 변경 처리
*/
private function handleStatusChange($articleNumber, $statusCode, $memo)
{
$existing = $this->VrfcReqModel->where('atcl_no', $articleNumber)->first();
if (!$existing) {
throw new \Exception("상태 변경 실패: 해당 매물 없음 ($articleNumber)");
}
$updateData = [
'stat_cd' => $statusCode,
'memo' => $existing['memo'] . " | " . $memo . "(" . date('Y-m-d H:i:s') . ")"
];
if (!$this->VrfcReqModel->update($existing['reqSeq'], $updateData)) {
throw new \Exception("상태 업데이트 실패: " . $articleNumber);
}
return $existing['reqSeq'];
}
}