현장 확인 > 처리 가능 수량 관리 api 및 수정
This commit is contained in:
@@ -107,44 +107,70 @@ class Processible extends BaseController
|
||||
|
||||
|
||||
// 지역별 수량 저장
|
||||
public function saveArea()
|
||||
{
|
||||
try {
|
||||
public function saveArea()
|
||||
{
|
||||
log_message('info', '[Processible::saveArea] 진입');
|
||||
try {
|
||||
$rows = $this->request->getPost('rows');
|
||||
$rows = json_decode($rows, true);
|
||||
|
||||
$rows = $this->request->getPost('rows');
|
||||
$rows = json_decode($rows, true);
|
||||
|
||||
// dd($rows);
|
||||
// exit;
|
||||
|
||||
if (count($rows) > 0) {
|
||||
|
||||
foreach ($rows as $row):
|
||||
$this->model->saveArea($row);
|
||||
endforeach;
|
||||
|
||||
return $this->response->setJSON([
|
||||
'code' => '0',
|
||||
'msg' => 'success'
|
||||
]);
|
||||
|
||||
} else {
|
||||
if (count($rows) > 0) {
|
||||
// API 형식으로 변환 및 DB 저장을 한 번에 처리
|
||||
$syncSlotData = [];
|
||||
foreach ($rows as $row) {
|
||||
// DB 저장
|
||||
$this->model->saveArea($row);
|
||||
// 동시에 API 데이터 구성
|
||||
$syncSlotData[] = [
|
||||
'baseDate' => $row['sc_date'],
|
||||
'legalDivisionNumber' => $row['region_cd'],
|
||||
'slots' => [
|
||||
'am' => [
|
||||
'max' => (int) $row['am_cnt'],
|
||||
'reserved' => 0
|
||||
],
|
||||
'pm' => [
|
||||
'max' => (int) $row['pm_cnt'],
|
||||
'reserved' => 0
|
||||
]
|
||||
]
|
||||
];
|
||||
}
|
||||
log_message('info', '[Processible::saveArea] 슬롯 동기화 시작 | Count: ' . count($syncSlotData));
|
||||
$naverClient = new \App\Libraries\NaverApiClient();
|
||||
$apiResponse = $naverClient->syncSiteSlot($syncSlotData);
|
||||
// API 응답 처리
|
||||
if ($apiResponse === null) {
|
||||
log_message('error', '[Processible::saveArea] Naver API 슬롯 동기화 실패 | Data: ' . json_encode($syncSlotData, JSON_UNESCAPED_UNICODE));
|
||||
return $this->response->setJSON([
|
||||
'code' => '1',
|
||||
'msg' => '저장은 완료되었으나 네이버 슬롯 동기화에 실패했습니다. 로그를 확인하세요.',
|
||||
'syncData' => $syncSlotData,
|
||||
'hint' => '로그 위치: writable/logs/ 에서 ERROR 확인'
|
||||
]);
|
||||
}
|
||||
log_message('info', '[Processible::saveArea] Naver API 슬롯 동기화 성공 | Response: ' . json_encode($apiResponse, JSON_UNESCAPED_UNICODE));
|
||||
return $this->response->setJSON([
|
||||
'code' => '0',
|
||||
'msg' => 'success',
|
||||
'syncData' => $syncSlotData,
|
||||
'apiResponse' => $apiResponse
|
||||
]);
|
||||
} else {
|
||||
log_message('info', '[Processible::saveArea] 저장가능한 데이터가 없습니다.');
|
||||
return $this->response->setJSON([
|
||||
'code' => '9',
|
||||
'msg' => '저장가능한 데이터가 없습니다.'
|
||||
]);
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
log_message('error', '[Processible::saveArea] 예외: ' . $e->getMessage());
|
||||
return $this->response->setJSON([
|
||||
'code' => '9',
|
||||
'msg' => '저장가능한 데이터가 없습니다.'
|
||||
'msg' => $e->getMessage(),
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
} catch (\Exception $e) {
|
||||
return $this->response->setJSON([
|
||||
'code' => '9',
|
||||
'msg' => $e->getMessage(),
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
// 기본 수량 저장
|
||||
public function saveCount()
|
||||
{
|
||||
try {
|
||||
|
||||
Reference in New Issue
Block a user