처리가능 수량관리 수정
This commit is contained in:
@@ -7,210 +7,242 @@ use App\Models\article\ProcessibleModel;
|
||||
class Processible extends BaseController
|
||||
{
|
||||
|
||||
private $model;
|
||||
private $model;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->model = new ProcessibleModel();
|
||||
}
|
||||
public function __construct()
|
||||
{
|
||||
$this->model = new ProcessibleModel();
|
||||
}
|
||||
|
||||
public function datecount(): string
|
||||
{
|
||||
public function datecount(): string
|
||||
{
|
||||
|
||||
$sido = $this->model->getAreaList(); // 지역조회
|
||||
$sido = $this->model->getAreaList(); // 지역조회
|
||||
|
||||
$this->data['sido'] = $sido;
|
||||
$this->data['sido'] = $sido;
|
||||
|
||||
return view("pages/article/processible/datecount", $this->data);
|
||||
}
|
||||
return view("pages/article/processible/datecount", $this->data);
|
||||
}
|
||||
|
||||
public function getList1()
|
||||
{
|
||||
$start = (int) $this->request->getGet('start') ?: 0;
|
||||
$end = (int) $this->request->getGet('length') ?: 10;
|
||||
public function getList1()
|
||||
{
|
||||
$start = (int) $this->request->getGet('start') ?: 0;
|
||||
$end = (int) $this->request->getGet('length') ?: 10;
|
||||
|
||||
$data = [
|
||||
'sdate' => $this->request->getGet('sdate'), // 시작일
|
||||
'edate' => $this->request->getGet('edate'), // 종료일
|
||||
];
|
||||
$data = [
|
||||
'sdate' => $this->request->getGet('sdate'), // 시작일
|
||||
'edate' => $this->request->getGet('edate'), // 종료일
|
||||
];
|
||||
|
||||
$totalCount = $this->model->getTotal1($data);
|
||||
$totalCount = $this->model->getTotal1($data);
|
||||
|
||||
$datas = $this->model->getList1($start, $end, $data);
|
||||
$datas = $this->model->getList1($start, $end, $data);
|
||||
|
||||
return $this->response->setJSON(body: [
|
||||
'recordsTotal' => $totalCount,
|
||||
'recordsFiltered' => $totalCount,
|
||||
'data' => $datas,
|
||||
]);
|
||||
}
|
||||
return $this->response->setJSON(body: [
|
||||
'recordsTotal' => $totalCount,
|
||||
'recordsFiltered' => $totalCount,
|
||||
'data' => $datas,
|
||||
]);
|
||||
}
|
||||
|
||||
public function getList2()
|
||||
{
|
||||
// $start = (int) $this->request->getGet('start') ?: 0;
|
||||
// $end = (int) $this->request->getGet('length') ?: 10;
|
||||
public function getList2()
|
||||
{
|
||||
// $start = (int) $this->request->getGet('start') ?: 0;
|
||||
// $end = (int) $this->request->getGet('length') ?: 10;
|
||||
|
||||
$data = [
|
||||
'sdate' => $this->request->getGet('sdate'), // 시작일
|
||||
'region' => $this->request->getGet('region'), // 종료일
|
||||
];
|
||||
$data = [
|
||||
'sdate' => $this->request->getGet('sdate'), // 시작일
|
||||
'region' => $this->request->getGet('region'), // 종료일
|
||||
];
|
||||
|
||||
$totalCount = $this->model->getTotal2($data);
|
||||
$totalCount = $this->model->getTotal2($data);
|
||||
|
||||
$datas = $this->model->getList2($data);
|
||||
$datas = $this->model->getList2($data);
|
||||
|
||||
return $this->response->setJSON(body: [
|
||||
'recordsTotal' => $totalCount,
|
||||
'recordsFiltered' => $totalCount,
|
||||
'data' => $datas,
|
||||
]);
|
||||
}
|
||||
return $this->response->setJSON(body: [
|
||||
'recordsTotal' => $totalCount,
|
||||
'recordsFiltered' => $totalCount,
|
||||
'data' => $datas,
|
||||
]);
|
||||
}
|
||||
|
||||
public function getList3()
|
||||
{
|
||||
public function getList3()
|
||||
{
|
||||
|
||||
$data = [
|
||||
'region' => $this->request->getGet('region'), // 종료일
|
||||
];
|
||||
$data = [
|
||||
'region' => $this->request->getGet('region'), // 종료일
|
||||
];
|
||||
|
||||
$totalCount = $this->model->getTotal3($data);
|
||||
$totalCount = $this->model->getTotal3($data);
|
||||
|
||||
$datas = $this->model->getList3($data);
|
||||
$datas = $this->model->getList3($data);
|
||||
|
||||
return $this->response->setJSON(body: [
|
||||
'recordsTotal' => $totalCount,
|
||||
'recordsFiltered' => $totalCount,
|
||||
'data' => $datas,
|
||||
]);
|
||||
}
|
||||
return $this->response->setJSON(body: [
|
||||
'recordsTotal' => $totalCount,
|
||||
'recordsFiltered' => $totalCount,
|
||||
'data' => $datas,
|
||||
]);
|
||||
}
|
||||
|
||||
// 엑셀다운로드
|
||||
public function excel()
|
||||
{
|
||||
try {
|
||||
public function excel()
|
||||
{
|
||||
try {
|
||||
|
||||
$data = [
|
||||
'sdate' => $this->request->getGet('sdate'),
|
||||
'edate' => $this->request->getGet('edate'),
|
||||
];
|
||||
$data = [
|
||||
'sdate' => $this->request->getGet('sdate'),
|
||||
'edate' => $this->request->getGet('edate'),
|
||||
];
|
||||
|
||||
$datas = $this->model->getExcelList($data);
|
||||
$datas = $this->model->getExcelList($data);
|
||||
|
||||
return $this->response->setJSON(body: [
|
||||
'data' => $datas,
|
||||
]);
|
||||
return $this->response->setJSON(body: [
|
||||
'data' => $datas,
|
||||
]);
|
||||
|
||||
} catch (\Exception $e) {
|
||||
$e->getPrevious()->getTraceAsString();
|
||||
} catch (\Exception $e) {
|
||||
$e->getPrevious()->getTraceAsString();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// 지역별 수량 저장
|
||||
public function saveArea()
|
||||
{
|
||||
log_message('info', '[Processible::saveArea] 진입');
|
||||
|
||||
try {
|
||||
$rows = $this->request->getPost('rows');
|
||||
$rows = json_decode($rows, true);
|
||||
|
||||
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 {
|
||||
if (empty($rows)) {
|
||||
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' => $e->getMessage(),
|
||||
]);
|
||||
}
|
||||
}
|
||||
public function saveCount()
|
||||
{
|
||||
try {
|
||||
|
||||
$rows = $this->request->getPost('rows');
|
||||
$rows = json_decode($rows, true);
|
||||
|
||||
if (count($rows) > 0) {
|
||||
// API 형식으로 변환 및 DB 저장
|
||||
$syncSlotData = [];
|
||||
foreach ($rows as $row) {
|
||||
// DB 저장 (API 실패와 무관하게 저장됨)
|
||||
$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
|
||||
]
|
||||
]
|
||||
];
|
||||
}
|
||||
|
||||
$results = [];
|
||||
log_message('info', '[Processible::saveArea] DB 저장 완료 | Count: ' . count($rows));
|
||||
|
||||
// 네이버 API 슬롯 동기화 시도
|
||||
log_message('info', '[Processible::saveArea] 슬롯 동기화 시작 | Count: ' . count($syncSlotData));
|
||||
$naverClient = new \App\Libraries\NaverApiClient();
|
||||
$apiResponse = $naverClient->syncSiteSlot($syncSlotData);
|
||||
|
||||
// API 응답 에러 체크
|
||||
$hasError = false;
|
||||
$errorMessage = '';
|
||||
|
||||
foreach ($rows as $row):
|
||||
$result = $this->model->saveCount($row);
|
||||
$results[] = $result;
|
||||
|
||||
if (!$result['success']) {
|
||||
if ($apiResponse === null) {
|
||||
$hasError = true;
|
||||
}
|
||||
endforeach;
|
||||
|
||||
$errorMessage = 'API 응답 없음 (null)';
|
||||
} elseif (!empty($apiResponse['error'])) {
|
||||
$hasError = true;
|
||||
$errorType = $apiResponse['error_type'] ?? 'UNKNOWN';
|
||||
$httpCode = $apiResponse['http_code'] ?? 'N/A';
|
||||
$errorMessage = "API Error: {$errorType} (HTTP {$httpCode})";
|
||||
} elseif (isset($apiResponse['http_code']) && $apiResponse['http_code'] >= 400) {
|
||||
$hasError = true;
|
||||
$errorMessage = "HTTP Error: {$apiResponse['http_code']}";
|
||||
}
|
||||
|
||||
// API 에러 발생 시 (DB는 이미 저장됨)
|
||||
if ($hasError) {
|
||||
log_message('error', "[Processible::saveArea] {$errorMessage} | Response: " . json_encode($apiResponse, JSON_UNESCAPED_UNICODE));
|
||||
|
||||
return $this->response->setJSON([
|
||||
'code' => '1',
|
||||
'msg' => 'DB 저장은 완료되었으나 네이버 슬롯 동기화에 실패했습니다. 관리자에게 문의하세요.',
|
||||
'error' => $errorMessage,
|
||||
'dbSaved' => true,
|
||||
'syncData' => $syncSlotData,
|
||||
'apiResponse' => $apiResponse
|
||||
]);
|
||||
}
|
||||
|
||||
// 성공
|
||||
log_message('info', '[Processible::saveArea] Naver API 슬롯 동기화 성공 | Response: ' . json_encode($apiResponse, JSON_UNESCAPED_UNICODE));
|
||||
|
||||
return $this->response->setJSON([
|
||||
'code' => $hasError ? '9' : '0',
|
||||
'msg' => $hasError ? '일부 저장 실패' : 'success',
|
||||
'debug' => $results // 디버깅 정보 포함
|
||||
'code' => '0',
|
||||
'msg' => 'success',
|
||||
'dbSaved' => true,
|
||||
'syncData' => $syncSlotData,
|
||||
'apiResponse' => $apiResponse
|
||||
]);
|
||||
|
||||
} else {
|
||||
|
||||
} catch (\Exception $e) {
|
||||
log_message('error', '[Processible::saveArea] 예외 발생: ' . $e->getMessage());
|
||||
return $this->response->setJSON([
|
||||
'code' => '9',
|
||||
'msg' => '저장가능한 데이터가 없습니다.'
|
||||
'code' => '9',
|
||||
'msg' => '처리 중 오류가 발생했습니다: ' . $e->getMessage(),
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
} catch (\Exception $e) {
|
||||
return $this->response->setJSON([
|
||||
'code' => '9',
|
||||
'msg' => $e->getMessage(),
|
||||
]);
|
||||
}
|
||||
}
|
||||
public function saveCount()
|
||||
{
|
||||
try {
|
||||
|
||||
$rows = $this->request->getPost('rows');
|
||||
$rows = json_decode($rows, true);
|
||||
|
||||
if (count($rows) > 0) {
|
||||
|
||||
$results = [];
|
||||
$hasError = false;
|
||||
|
||||
foreach ($rows as $row):
|
||||
$result = $this->model->saveCount($row);
|
||||
$results[] = $result;
|
||||
|
||||
if (!$result['success']) {
|
||||
$hasError = true;
|
||||
}
|
||||
endforeach;
|
||||
|
||||
return $this->response->setJSON([
|
||||
'code' => $hasError ? '9' : '0',
|
||||
'msg' => $hasError ? '일부 저장 실패' : 'success',
|
||||
'debug' => $results // 디버깅 정보 포함
|
||||
]);
|
||||
|
||||
} else {
|
||||
return $this->response->setJSON([
|
||||
'code' => '9',
|
||||
'msg' => '저장가능한 데이터가 없습니다.'
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
} catch (\Exception $e) {
|
||||
return $this->response->setJSON([
|
||||
'code' => '9',
|
||||
'msg' => $e->getMessage(),
|
||||
]);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user