diff --git a/app/Config/Routes.php b/app/Config/Routes.php index 0361165..50d94c1 100644 --- a/app/Config/Routes.php +++ b/app/Config/Routes.php @@ -324,7 +324,8 @@ $routes->group('', ['namespace' => 'App\Controllers\V2'], static function ($rout $routes->post('m708a/saveBunyang', 'M708::saveBunyang'); // 분양권 저장 $routes->post('m708a/saveRequestMessage', 'M708::saveRequestMessage'); // 중개인 요청사항 저장 $routes->post('m708a/saveResult', 'M708::saveResult'); // 결과저장 - $routes->post('m708a/saveBunyangCnt', 'M708::saveBunyangCnt'); // 분양계약서저장 + $routes->post('m708a/saveBunyangCnt', 'M708::saveBunyangCnt'); // 분양계약서조회 + $routes->post('m708a/saveResult3', 'M708::saveResult3'); // 분양계약서저장 $routes->post('m708a/getNextFaxImgs', 'M708::getNextFaxImgs'); // 다음매물 }); diff --git a/app/Controllers/V2/M706.php b/app/Controllers/V2/M706.php index 748598a..5195060 100644 --- a/app/Controllers/V2/M706.php +++ b/app/Controllers/V2/M706.php @@ -547,7 +547,7 @@ class M706 extends BaseController //memo 저장 if (!empty($memo)) { - $this->model->updateMemo([$memo, $atcl_vr_sq]); + $this->model->saveMemo([$memo, $atcl_vr_sq]); } //API 호출 diff --git a/app/Controllers/V2/M708.php b/app/Controllers/V2/M708.php index 4e1ad57..bb2d8a2 100644 --- a/app/Controllers/V2/M708.php +++ b/app/Controllers/V2/M708.php @@ -3,8 +3,12 @@ namespace App\Controllers\V2; use App\Controllers\BaseController; use App\Libraries\Common; +use App\Libraries\NaverApiClient; use App\Models\common\CodeModel; +use App\Models\results\M415Model; use App\Models\v2\M708Model; +use App\Models\v2\M710Model; +use Exception; class M708 extends BaseController { @@ -129,7 +133,6 @@ class M708 extends BaseController $data = $this->model->getDetail($id); $memo = $this->model->getMemo($id); - $article = null; $confirm = null; if (!empty($data)) { @@ -360,6 +363,11 @@ class M708 extends BaseController // 확인결과 저장 public function saveResult() { + $naver = new NaverApiClient(); + $model710 = new M710Model(); + $model415 = new M415Model(); + $v2DailyModel = new V2StDailyModel(); + try { $fax_sq = $this->request->getPost('fax_sq'); $vr_sq = $this->request->getPost('vr_sq'); @@ -387,9 +395,72 @@ class M708 extends BaseController } // DB에 결과 저장 - // $this->model->saveHongBoFAX($fax_sq, $vr_sq, $atcl_no, $work_type, $send_yn, $result_d11, $comment_d11, $fax_conf_yn_1, $fax_conf_yn_2, $fax_conf_yn_3, $fax_conf_info_1, $fax_conf_info_2, $fax_conf_info_3, $file_type); + $return = $this->model->saveHongBoFAX($fax_sq, $vr_sq, $atcl_no, $work_type, $send_yn, $result_d11 ?? null, $comment_d11 ?? null, $fax_conf_yn_1 ?? null, $fax_conf_yn_2 ?? null, $fax_conf_yn_3 ?? null, $fax_conf_info_1 ?? null, $fax_conf_info_2 ?? null, $fax_conf_info_3 ?? null, $file_type); + if (empty($return['code']) && $work_type == '2') { + // 검증센터에 데이터를 전송한다. + $sendData = $this->model->getDataConfirmAPI($vr_sq); + if (($fax_conf_yn_3 ?? 'N') == 'Y' || (int) $article['try_cnt'] < 1) { + $send_result = $naver->confirm($sendData['atclNo'], $sendData['success'], $sendData['checkList'], $sendData['charger'], $sendData['modifyInfo'], $sendData['date']); + + if ($send_result['result'] == 'success') { + $this->model->InsCharger($vr_sq); + + // DB에 상태값을 전송완료로 저장한다. + if (empty($sendData['success'])) { + $stat_cd = '39'; // 서류/전화 확인 실패 + $this->model->saveChangeStep($fax_sq, $vr_sq, $stat_cd); // 전송완료 상태로 변경.. + + if ($sendData['try_cnt'] >= '1') { + $stat_cd = '69'; // 검증실패 + $this->model->saveChangeStep($fax_sq, $vr_sq, $stat_cd); // 전송완료 상태로 변경.. + $v2DailyModel->set_v2_st_daily(NULL, $v2_vrfc_req['cpid'], 'D0302', '1', 'add'); // 최종실패로 저장 + } else { + $v2DailyModel->set_v2_st_daily(NULL, $v2_vrfc_req['cpid'], 'D0301', '1', 'add'); // 1차실패로 저장 + } + // $res_try = $this->m708_model->chgTryCnt($vr_sq, intval($sendData['try_cnt']) +1); + + $this->model->increseTryCnt($vr_sq); + + if (($result_d11 ?? '') == '20013') { + $v2DailyModel->set_v2_st_daily(NULL, $v2_vrfc_req['cpid'], 'D0203', '1', 'add'); // 기타로 저장 + } else { + $v2DailyModel->set_v2_st_daily(NULL, $v2_vrfc_req['cpid'], 'D0202', '1', 'add'); // 불일치로 저장 + } + } else { + $stat_cd = '35'; // 서류/전화 확인 성공 + $this->model->saveChangeStep($fax_sq, $vr_sq, $stat_cd); // 전송완료 상태로 변경.. + + $rgbk_cofirm = $this->model->getRgbk_confirm($vr_sq); + if ($rgbk_cofirm == '1') { + $stat_cd = '40'; + $this->model->saveChangeStep($fax_sq, $vr_sq, $stat_cd); // 등기부등본 확인중 상태로 변경.. + + $v2DailyModel->set_v2_st_daily(NULL, $v2_vrfc_req['cpid'], 'D0201', '1', 'add'); // 일치로 저장 + } else { + $stat_cd = '60'; + $this->model->saveChangeStep($fax_sq, $vr_sq, $stat_cd); // 검증완료 상태로 변경.. + + $v2DailyModel->set_v2_st_daily(NULL, $v2_vrfc_req['cpid'], 'D0205', '1', 'add'); // 홍보확인서완료 등기부등본확인 안함 저장 + } + } + } else { + throw new \Exception($send_result['error']); + } + } else { + $stat_cd = '39'; // 서류/전화 확인 실패 + $this->model->saveChangeStep($fax_sq, $vr_sq, $stat_cd); + + $stat_cd = '30'; // 서류/전화 확인 중 + $this->model->saveChangeStep($fax_sq, $vr_sq, $stat_cd); + + $this->model->increseTryCnt($vr_sq); + + throw new \Exception('의뢰인 정보 불일치로 저장되었습니다.'); + } + + } return $this->response->setJSON([ @@ -408,14 +479,131 @@ class M708 extends BaseController } } - // 분양계약서 저장 + // 분양계약서 조회 public function saveBunyangCnt() { try { $vr_sq = $this->request->getPost('vr_sq'); + $rsrv_sq = $this->model->get_rsrv_sq($vr_sq); + $cnt = $this->model->getI8Cnt($rsrv_sq['rsrv_sq']); + return $this->response->setJSON([ + 'code' => '0', + 'msg' => 'success', + 'cnt' => $cnt, + ]); + + } catch (\Exception $e) { + return $this->response->setJSON([ + 'code' => '9', + 'msg' => $e->getMessage(), + ]); + } + } + + // 분양계약서 저장 + public function saveResult3() + { + $naver = new NaverApiClient(); + $v2StDailyModel = new V2StDailyModel(); + + try { + + $fax_sq = $this->request->getPost('fax_sq'); + $vr_sq = $this->request->getPost('vr_sq'); + $atcl_no = $this->request->getPost('atcl_no'); + $work_type = $this->request->getPost('work_type'); + + $resyn = $this->request->getPost('resYn'); + $dbusageagryn = $this->request->getPost('dbUsageAgrYn'); + $send_yn = 'Y'; // 업데이트 된다면 미처리->처리상태로 변경 + + $article = $this->model->getArticleInfo2($atcl_no, $vr_sq); + $v2_vrfc_req = $v2StDailyModel->get_v2_vrfc_req($vr_sq); + + if ((int) $article['stat_cd'] >= 40) { + throw new \Exception('이미 저장된 데이터입니다.'); + } else { + if (!empty($resyn)) { + $this->model->updateResDB($resyn, $dbusageagryn, $vr_sq); + } + + // DB에 결과를 저장한다. + $return = $this->model->saveresult3FAX($fax_sq, $vr_sq, $atcl_no, $work_type, $send_yn, $result_d11 ?? null, $comment_d11 ?? null, $fax_conf_yn_1 ?? null, $fax_conf_yn_2 ?? null, $fax_conf_yn_3 ?? null, $fax_conf_info_1 ?? null, $fax_conf_info_2 ?? null, $fax_conf_info_3 ?? null); + + if (empty($return['code']) && $work_type == '2') { + // 검증센터에 데이터를 전송한다. + $sendData = $this->model->getDataConfirmAPI($vr_sq); + + if (($fax_conf_yn_3 ?? 'N') == 'Y' || $article['try_cnt'] < '1') { + $send_result = $naver->confirm($sendData['atclNo'], $sendData['success'], $sendData['checkList'], $sendData['charger'], $sendData['modifyInfo'], $sendData['date']); + + if ($send_result['result'] == 'success') { + $this->model->InsCharger($vr_sq); + + // DB에 상태값을 전송완료로 저장한다. + if (empty($sendData['success'])) { + $stat_cd = '39'; // 서류/전화 확인 실패 + $this->model->saveChangeStep($fax_sq, $vr_sq, $stat_cd); // 전송완료 상태로 변경 + + if ($sendData['try_cnt'] >= '1') { + $stat_cd = '69'; // 검증실패 + $this->model->saveChangeStep($fax_sq, $vr_sq, $stat_cd); // 전송완료 상태로 변경.. + $v2StDailyModel->set_v2_st_daily(NULL, $v2_vrfc_req['cpid'], 'D0302', '1', 'add'); // 최종실패로 저장 + } else { + $v2StDailyModel->set_v2_st_daily(NULL, $v2_vrfc_req['cpid'], 'D0301', '1', 'add'); // 1차실패로 저장 + } + // $res_try = $this->m708_model->chgTryCnt($vr_sq, intval($sendData['try_cnt']) +1); + + $this->model->increseTryCnt($vr_sq); + + if (($result_d11 ?? '') == '20013') { + $v2StDailyModel->set_v2_st_daily(NULL, $v2_vrfc_req['cpid'], 'D0203', '1', 'add'); // 기타로 저장 + } else { + $v2StDailyModel->set_v2_st_daily(NULL, $v2_vrfc_req['cpid'], 'D0202', '1', 'add'); // 불일치로 저장 + } + } else { + $stat_cd = '35'; // 서류/전화 확인 성공 + $this->model->saveChangeStep($fax_sq, $vr_sq, $stat_cd); // 전송완료 상태로 변경.. + + $rgbk_cofirm = $this->model->getRgbk_confirm($vr_sq); + if ($rgbk_cofirm == '1') { + $stat_cd = '40'; + $this->model->saveChangeStep($fax_sq, $vr_sq, $stat_cd); // 등기부등본 확인중 상태로 변경.. + + $v2StDailyModel->set_v2_st_daily(NULL, $v2_vrfc_req['cpid'], 'D0201', '1', 'add'); // 일치로 저장 + } else { + $stat_cd = '60'; + $this->model->saveChangeStep($fax_sq, $vr_sq, $stat_cd); // 검증완료 상태로 변경.. + + $v2StDailyModel->set_v2_st_daily(NULL, $v2_vrfc_req['cpid'], 'D0205', '1', 'add'); // 홍보확인서완료 등기부등본확인 안함 저장 + } + } + } else { + throw new \Exception($send_result['error']); + } + } else { + $stat_cd = '39'; // 서류/전화 확인 실패 + $this->model->saveChangeStep($fax_sq, $vr_sq, $stat_cd); + + $stat_cd = '30'; // 서류/전화 확인 중 + $this->model->saveChangeStep($fax_sq, $vr_sq, $stat_cd); + + $this->model->increseTryCnt($vr_sq); + + + throw new \Exception('의뢰인 정보 불일치로 저장되었습니다.'); + } + } + + return $this->response->setJSON([ + 'code' => '0', + 'msg' => 'success', + ]); + + } } catch (\Exception $e) { return $this->response->setJSON([ diff --git a/app/Models/receipt/ReceiptModel.php b/app/Models/receipt/ReceiptModel.php index d1ed894..2454096 100644 --- a/app/Models/receipt/ReceiptModel.php +++ b/app/Models/receipt/ReceiptModel.php @@ -146,4 +146,21 @@ class ReceiptModel extends Model $data = [$imgSq, $faxSq]; $this->db->query($sql, $data); } + + // receipt 에서 지정한 1건만 가져온다. + public function selectReceiptOne($rcpt_sq) + { + $sql = "SELECT a.rcpt_sq,a.comp_sq,a.rcpt_rating,a.rcpt_key,a.rcpt_atclno,a.rcpt_type,a.rcpt_product,a.rcpt_product_nm,a.rcpt_product_area,a.rcpt_product_price,a.rcpt_product_info1,a.rcpt_product_info2,a.rcpt_product_info3,a.rcpt_product_info4,a.rcpt_product_info5,a.rcpt_office,a.rcpt_agent,a.rcpt_sido,a.rcpt_gugun,a.rcpt_dong,a.rcpt_hscp_nm,a.rcpt_dtl_addr,a.rcpt_floor,a.rcpt_bunji,a.rcpt_ho,a.rcpt_tm,a.rcpt_stat,a.rcpt_x,a.rcpt_y,a.rcpt_living_yn,a.cust_nm,a.cust_tel1,a.cust_tel2,a.cust_zip,a.cust_addr1,a.cust_addr2,a.remark,a.agent_id,a.agent_nm,a.agent_head,a.agent_head_tel,a.agent_contact,a.agent_contact_tel,a.agent_fax,a.rsrv_date,a.rsrv_tm_ap,a.insert_usr,a.insert_tm,a.update_usr,a.update_tm,a.svc_type1,a.svc_type2,a.reconf_yn,a.rcpt_exps_type" . + ", b.region_nm" . + ", c.rsrv_sq" . + " FROM receipt a" . + " LEFT JOIN region_codes b ON b.region_cd = a.rcpt_dong" . + " LEFT JOIN result c on c.rcpt_sq = a.rcpt_sq" . + " WHERE a.rcpt_sq = ?" . + " limit 1"; + $data = [$rcpt_sq]; + $query = $this->db->query($sql, $data); + + return $query->getRowArray(); + } } \ No newline at end of file diff --git a/app/Models/v2/M703Model.php b/app/Models/v2/M703Model.php index 6b5ebc0..ae39ac2 100644 --- a/app/Models/v2/M703Model.php +++ b/app/Models/v2/M703Model.php @@ -2,6 +2,7 @@ namespace App\Models\v2; use App\Models\receipt\ReceiptModel; +use App\Models\webfax\FaxModel; use CodeIgniter\Model; class M703Model extends Model @@ -1504,8 +1505,9 @@ class M703Model extends Model $this->saveChangedHistory($vr_sq, '35', 'C9', $insert_id, '현장확인 매물'); - $fax = $this->fax_model->selectFax($fax_sq); // fax 이미지 파일 가져오기 - $receipt = $this->receipt_model->selectReceiptOne($vr_sq); // 매물정보 가져오기 + $faxModel = new FaxModel(); + $fax = $faxModel->selectFax($fax_sq); // fax 이미지 파일 가져오기 + $receipt = $this->selectReceiptOne($vr_sq); // 매물정보 가져오기 // 40: 촬영, 70: 검수지연... 상태가 촬용 이전 또는 검수지연 상태일 경우에만 홍보확인서를 등록한다. if (substr($receipt['rcpt_stat'], 0, 2) <= '40' || substr($receipt['rcpt_stat'], 0, 2) == '70') { diff --git a/app/Models/v2/M708Model.php b/app/Models/v2/M708Model.php index e073e1e..8bffccf 100644 --- a/app/Models/v2/M708Model.php +++ b/app/Models/v2/M708Model.php @@ -1,6 +1,8 @@ getArticleInfo2($atcl_no, $vr_sq); - $this->saveFaxImgs($fax_sq, '2', $vr_sq, $atcl_no, $article['cpid'], $article['realtor_nm'], $article['stat_cd'], $current_tm, $article['address_code'], $article['address2']); + $this->saveFaxImgs($fax_sq, '2', $vr_sq, $atcl_no, $article['cpid'], $article['realtor_nm'], $article['stat_cd'], $current_tm, $article['address_code'], $article['address2'], 'Y'); return [ 'success' => true, @@ -1215,6 +1217,754 @@ class M708Model extends Model return $row; } + /** + * 매물정보와 FAX를 연결해 준다. + */ + public function saveArticleFAX($memo, $fax_sq, $vr_sq, $atcl_no, $work_type, $result_d11, $comment_d11, $fax_conf_yn_1, $fax_conf_yn_2, $fax_conf_yn_3, $fax_conf_info_1, $fax_conf_info_2, $fax_conf_info_3, $stat_cd = '') + { + // 1. 매물정보 저장 fax_imgs + // 2.1 확인결과 저장 v2_confirms + // 2.2 확인정보 체크 v2_check_list + // 3.1 검증요청 상태변경 v2_vrfc_req + // 3.2 상태변경 저장 v2_chg_stat + // 4. 첨부파일 저장 v2_files + // 5. 변경이력 저장 v2_chg_history + // 6. kiso 전송하기 + + $this->db->transStart(); + + $article = NULL; + $current_tm = date('Y-m-d H:i:s'); + $insert_user = session('usr_sq'); + $insert_id = session('usr_id'); + $update_user = $insert_user; + + switch ($work_type) { + case '1': // 현장확인매물 + $article = $this->getArticleInfo1($atcl_no, $vr_sq); + + // 1. 매물정보 저장 fax_imgs + $this->saveFaxImgs($fax_sq, $work_type, $vr_sq, $atcl_no, $article['cpid'], $article['realtor_nm'], '35', $current_tm, $article['address_code'], $article['address2'], 'Y'); + + // 2.1 확인결과 저장 v2_confirm + + if ($result_d11 == '10000' && $fax_conf_yn_1 == 'Y' && $fax_conf_yn_2 == 'Y' && $fax_conf_yn_3 == 'Y') { + $success = TRUE; + } else { + $success = FALSE; + } + + $fax = $this->getDetail($fax_sq); + $this->saveV2Confirm($vr_sq, 'D', $success, '1', $fax['charger'], $current_tm, $insert_user, $update_user, $work_type); + + // 2.2 확인정보 체크 v2_check_list + // $fax_conf_yn_1, $fax_conf_yn_2, $fax_conf_yn_3, + // $fax_conf_info_1, $fax_conf_info_2, $fax_conf_info_3 + if (is_array($comment_d11)) { + $comment = implode('|', $comment_d11); + } else { + $comment = $comment_d11; + } + + $this->saveV2CheckList($vr_sq, 'D', 'D11', $result_d11, $comment, $insert_user); + + if ($fax_conf_yn_1 == 'Y') { + $fax_conf_yn_1 = '10000'; + } else { + $fax_conf_yn_1 = '20000'; + } + $this->saveV2CheckList($vr_sq, 'D', 'D12', $fax_conf_yn_1, $fax_conf_info_1, $insert_user); + + if ($fax_conf_yn_2 == 'Y') { + $fax_conf_yn_2 = '10000'; + } else { + $fax_conf_yn_2 = '20000'; + } + $this->saveV2CheckList($vr_sq, 'D', 'D13', $fax_conf_yn_2, $fax_conf_info_2, $insert_user); + + if ($fax_conf_yn_3 == 'Y') { + $fax_conf_yn_3 = '10000'; + } else { + $fax_conf_yn_3 = '20000'; + } + $this->saveV2CheckList($vr_sq, 'D', 'D14', $fax_conf_yn_3, $fax_conf_info_3, $insert_user); + + $this->saveV2ChgHistory($vr_sq, '35', 'C9', $insert_id, '현장확인 매물'); + + $faxModel = new FaxModel(); + $fax = $faxModel->selectFax($fax_sq); // fax 이미지 파일 가져오기 + + $receiptModel = new ReceiptModel(); + $receipt = $receiptModel->selectReceiptOne($vr_sq); // 매물정보 가져오기 + + // 40: 촬영, 70: 검수지연... 상태가 촬용 이전 또는 검수지연 상태일 경우에만 홍보확인서를 등록한다. + if (substr($receipt['rcpt_stat'], 0, 2) <= '40' || substr($receipt['rcpt_stat'], 0, 2) == '70') { + $arrImagePath = array( + '/home/confirms/test-admin.confirms.co.kr/upload/', + '/home/confirms/upload/', + '/home/www/admin.confirms.co.kr/upload/', + '/home/www/upload/', + '/image/confirms_upload/', + '/misc/image/confirms_upload/', + '/storage/web/admin.confirms.co.kr/src/upload/', + '/storage/web/admin.confirms.co.kr/upload/', + $_SERVER['DOCUMENT_ROOT'] . '/upload/', + ); + + $image_path = str_replace($arrImagePath, '/upload/', $fax['file_path']); + + $receiptModel->saveFaxImage($fax_sq, $receipt['rcpt_sq'], $receipt['rsrv_sq'], 'I1', $image_path, $fax['file_name'], '.jpg', $fax['img_size'], $fax['img_width'], $fax['img_height'], $receipt); + } + + + break; + + case '2': // 일반확인매물 + $article = $this->getArticleInfo2($atcl_no, $vr_sq); + + $try_cnt = $article['try_cnt']; // 0 -> 1 차시도, 1 -> 2 차시도 + $try_cnt = $try_cnt + 1; + + //memo 저장 + $res_memo = $this->saveMemo([$memo, $vr_sq]); + + $stat_cd = "30"; // 전화/서류 확인 중 + + if ($result_d11 == '10000' && $fax_conf_yn_1 == 'Y' && $fax_conf_yn_2 == 'Y' && $fax_conf_yn_3 == 'Y') { + $success = TRUE; // 전화/서류 확인 성공 + } else { + $success = FALSE; // 전화/서류 확인 실패 + } + + // 1. 매물정보 저장 fax_imgs + $r = $this->saveFaxImgs($fax_sq, $work_type, $article['vr_sq'], $article['atcl_no'], $article['cpid'], $article['realtor_nm'], $stat_cd, $current_tm, $article['address_code'], $article['address2'], 'Y'); + + // 2.1 확인결과 저장 v2_confirm + $fax = $this->getDetail($fax_sq); + $this->saveV2Confirm($vr_sq, 'D', $success, $try_cnt, $fax['charger'], $current_tm, $insert_user, $update_user, $work_type); + + // 2.2 확인정보 체크 v2_check_list + // $fax_conf_yn_1, $fax_conf_yn_2, $fax_conf_yn_3, + // $fax_conf_info_1, $fax_conf_info_2, $fax_conf_info_3 + if (is_array($comment_d11)) { + $comment = implode('|', $comment_d11); + } else { + $comment = $comment_d11; + } + + $this->saveV2CheckList($vr_sq, 'D', 'D11', $result_d11, $comment, $insert_user); + + if ($fax_conf_yn_1 == 'Y') { + $fax_conf_yn_1 = '10000'; + } else { + $fax_conf_yn_1 = '20000'; + } + $this->saveV2CheckList($vr_sq, 'D', 'D12', $fax_conf_yn_1, $fax_conf_info_1, $insert_user); + + if ($fax_conf_yn_2 == 'Y') { + $fax_conf_yn_2 = '10000'; + } else { + $fax_conf_yn_2 = '20000'; + } + $this->saveV2CheckList($vr_sq, 'D', 'D13', $fax_conf_yn_2, $fax_conf_info_2, $insert_user); + + if ($fax_conf_yn_3 == 'Y') { + $fax_conf_yn_3 = '10000'; + } else { + $fax_conf_yn_3 = '20000'; + } + $this->saveV2CheckList($vr_sq, 'D', 'D14', $fax_conf_yn_3, $fax_conf_info_3, $insert_user); + + if ($success == TRUE) { + $stat_cd = '35'; // 서류확인완료 + $this->saveV2ChgStat($vr_sq, $stat_cd, $insert_user); + + $rgbk_confirm = $this->getRgbk_confirm($vr_sq); + if (empty($rgbk_confirm)) { + // 등기부등본 확인이 불필요할 경우 + $stat_cd = '60'; // 등기부등본 확인 중 + $this->saveV2ChgStat($vr_sq, $stat_cd, $insert_user); + } else { + // 등기부등본 확인이 필요할 경우 + $stat_cd = '40'; // 등기부등본 확인 중 + $this->saveV2ChgStat($vr_sq, $stat_cd, $insert_user); + } + } else { + $stat_cd = '39'; // 서류확인 불일치 + $this->saveV2ChgStat($vr_sq, $stat_cd, $insert_user); + } + + // 3.1 검증요청 상태변경 v2_vrfc_req + $this->saveV2VrfcReq($vr_sq, $stat_cd); + + // 4. 첨부파일 저장 v2_files + // fax_sq, mid, file_name, file_path, thumbnail, img_width, img_height, img_size, img_sq, remark, work_type, atcl_no, cpid, realtor_nm, stat_cd, proc_tm, send_tm, address_code, address2, charger + $pos = strpos($fax['file_name'], '.'); + if ($pos === false) { + $file_ext = ''; + } else { + $file_ext = substr($fax['file_name'], $pos); + } + $this->saveV2Files($vr_sq, $fax['file_path'], $fax['file_name'], $file_ext, $fax['img_size'], $fax['img_width'], $fax['img_height'], $insert_user); + + // 5. 변경이력 저장 v2_chg_history + $memo = ''; + $this->saveV2ChgHistory($vr_sq, $stat_cd, 'C9', $insert_id, $memo); + + break; + + default: // 오류 + break; + } + } + + + public function saveHongBoFAX($fax_sq, $vr_sq, $atcl_no, $work_type, $send_yn, $result_d11, $comment_d11, $fax_conf_yn_1, $fax_conf_yn_2, $fax_conf_yn_3, $fax_conf_info_1, $fax_conf_info_2, $fax_conf_info_3, $file_type, $stat_cd = '') + { + // 1. 매물정보 저장 fax_imgs + // 2.1 확인결과 저장 v2_confirms + // 2.2 확인정보 체크 v2_check_list + // 3.1 검증요청 상태변경 v2_vrfc_req + // 3.2 상태변경 저장 v2_chg_stat + // 4. 첨부파일 저장 v2_files + // 5. 변경이력 저장 v2_chg_history + // 6. kiso 전송하기 + + $this->db->transStart(); + + $article = NULL; + $current_tm = date('Y-m-d H:i:s'); + $insert_user = session('usr_sq'); + $insert_id = session('usr_id'); + $update_user = $insert_user; + + $article = $this->getArticleInfo1($atcl_no, $vr_sq); + + // 1. 매물정보 저장 fax_imgs + $this->saveFaxImgs($fax_sq, $work_type, $vr_sq, $atcl_no, $article['cpid'], $article['realtor_nm'], '35', $current_tm, $article['address_code'], $article['address2'], $send_yn); + + + // 2.1 확인결과 저장 v2_confirm + + if ($result_d11 == '10000' && $fax_conf_yn_1 == 'Y' && $fax_conf_yn_2 == 'Y' && $fax_conf_yn_3 == 'Y') { + $success = TRUE; + } else { + $success = FALSE; + } + + $fax = $this->getDetail($fax_sq); + $this->saveV2Confirm($vr_sq, 'D', $success, '1', $fax['charger'], $current_tm, $insert_user, $update_user, $work_type); + + // 2.2 확인정보 체크 v2_check_list +// $fax_conf_yn_1, $fax_conf_yn_2, $fax_conf_yn_3, +// $fax_conf_info_1, $fax_conf_info_2, $fax_conf_info_3 + if (is_array($comment_d11)) { + $comment = implode('|', $comment_d11); + } else { + $comment = $comment_d11; + } + + $this->saveV2CheckList($vr_sq, 'D', 'D11', $result_d11, $comment, $insert_user); + + if ($fax_conf_yn_1 == 'Y') { + $fax_conf_yn_1 = '10000'; + } else { + $fax_conf_yn_1 = '20000'; + } + $this->saveV2CheckList($vr_sq, 'D', 'D12', $fax_conf_yn_1, $fax_conf_info_1, $insert_user); + + if ($fax_conf_yn_2 == 'Y') { + $fax_conf_yn_2 = '10000'; + } else { + $fax_conf_yn_2 = '20000'; + } + $this->saveV2CheckList($vr_sq, 'D', 'D13', $fax_conf_yn_2, $fax_conf_info_2, $insert_user); + + if ($fax_conf_yn_3 == 'Y') { + $fax_conf_yn_3 = '10000'; + } else { + $fax_conf_yn_3 = '20000'; + } + $this->saveV2CheckList($vr_sq, 'D', 'D14', $fax_conf_yn_3, $fax_conf_info_3, $insert_user); + + $this->saveV2ChgHistory($vr_sq, '35', 'C9', $insert_id, '현장확인 매물'); + + $faxModel = new FaxModel(); + $fax = $faxModel->selectFax($fax_sq); // fax 이미지 파일 가져오기 + + $receiptModel = new ReceiptModel(); + $receipt = $receiptModel->selectReceiptOne($vr_sq); // 매물정보 가져오기 + + // 40: 촬영, 70: 검수지연... 상태가 촬용 이전 또는 검수지연 상태일 경우에만 홍보확인서를 등록한다. + if (substr($receipt['rcpt_stat'], 0, 2) <= '40' || substr($receipt['rcpt_stat'], 0, 2) == '70') { + $arrImagePath = array( + '/home/confirms/test-admin.confirms.co.kr/upload/', + '/home/confirms/upload/', + '/home/www/admin.confirms.co.kr/upload/', + '/home/www/upload/', + '/image/confirms_upload/', + '/misc/image/confirms_upload/', + '/storage/web/admin.confirms.co.kr/src/upload/', + '/storage/web/admin.confirms.co.kr/upload/', + $_SERVER['DOCUMENT_ROOT'] . '/upload/', + ); + + $image_path = str_replace($arrImagePath, '/upload/', $fax['file_path']); + + $receiptModel->saveFaxImage($fax_sq, $receipt['rcpt_sq'], $receipt['rsrv_sq'], $file_type, $image_path, $fax['file_name'], '.jpg', $fax['img_size'], $fax['img_width'], $fax['img_height'], $receipt); + } + + + $this->db->transComplete(); + $return = array( + 'code' => $this->db->_error_number(), + 'message' => $this->db->_error_message(), + ); + + return $return; + } + + + /** + * 검증결과 저장하기 + */ + public function saveV2Confirm($vr_sq, $vrfc_type, $success, $type, $charger, $date, $insert_user, $update_user, $work_type = '2') + { + $insert_user = session('usr_sq'); + $insert_id = session('usr_id'); + $update_user = $insert_user; + + // DB에서 변경되지 전 값을 읽어온다. + $sql = "select success, type, charger, date from v2_confirm" . + " where vr_sq = ?" . + " and vrfc_type = ?"; + $data = array( + $vr_sq, + $vrfc_type + ); + $query = $this->db->query($sql, $data); + $data_table = array(); + if ($query->getNumRows() > 0) { + $data_table = $query->getRowArray(); + } + + $date = str_replace(array(' ', '-', ':'), '', $date); + $sql = "INSERT INTO v2_confirm" . + " (vr_sq, vrfc_type, success, type, charger, date, insert_user, insert_tm, update_user, update_tm, work_type)" . + " VALUES" . + " (?, ?, ?, ?, ?, ?, ?, now(), ?, now(), ?)" . + " ON DUPLICATE KEY UPDATE" . + " success=values(success), type=values(type), charger=values(charger), date=values(date), update_user=values(update_user), update_tm=values(update_tm), work_type=values(work_type)"; + + $data = array( + 'vr_sq' => $vr_sq, + 'vrfc_type' => $vrfc_type, + 'success' => $success, + 'type' => $type, + 'charger' => $charger, + 'date' => $date, + 'insert_user' => $insert_user, + 'update_user' => $update_user, + 'work_type' => $work_type + ); + + $this->db->query($sql, $data); + + // 변경이력 저장하기 + if (!empty($data_table)) { + $this->saveV2ChgHistory($vr_sq, '30', 'C27', $insert_id, "검증결과 정보 저장"); + } + } + + /** + * 확인정보 저장하기 + */ + public function saveV2CheckList($vr_sq, $vrfc_type, $type, $code, $comment, $insert_user) + { + $insert_id = session('usr_id'); + + $sql = "select code, comment from v2_check_list" . + " where vr_sq = ?" . + " and type = ?"; + $data = array( + $vr_sq, + $type + ); + $query = $this->db->query($sql, $data); + $data_table = array(); + if ($query->getNumRows() > 0) { + $data_table = $query->getRowArray(); + } + + $sql = "INSERT INTO v2_check_list" . + " (vr_sq, vrfc_type, type, code, comment, insert_user, insert_tm)" . + " VALUES" . + " (?, ?, ?, ?, ?, ?, now())" . + " ON DUPLICATE KEY UPDATE" . + " vr_sq=values(vr_sq), vrfc_type=values(vrfc_type), type=values(type), code=values(code), comment=values(comment), insert_user=values(insert_user), insert_tm=values(insert_tm)"; + $data = array( + 'vr_sq' => $vr_sq, + 'vrfc_type' => $vrfc_type, + 'type' => $type, + 'code' => $code, + 'comment' => $comment, + 'insert_user' => $insert_user + ); + + $this->db->query($sql, $data); + + // 변경이력 저장하기 + if (!empty($data_table)) { + $this->saveV2ChgHistory($vr_sq, '30', 'C27', $insert_id, "확인정보 저장"); + } + } + + /** + * 상태변경시간 등록 + */ + public function saveV2ChgStat($vr_sq, $stat_cd, $insert_user) + { + $sql = "INSERT INTO v2_chg_stat" . + " (vr_sq, stat_cd, insert_user, insert_tm)" . + " VALUES" . + " (?, ?, ?, now())" . + " ON DUPLICATE KEY UPDATE" . + " insert_user=VALUES(insert_user), insert_tm=VALUES(insert_tm)"; + $data = array($vr_sq, $stat_cd, $insert_user); + $this->db->query($sql, $data); + log_message('debug', $this->db->getLastQuery()); + } + + /** + * 전송 후 FAX에 상태 및 전송시간을 저장한다. + */ + public function saveFaxImgsAfterSend($fax_sq, $vr_sq, $stat_cd, $send_tm = '') + { + if (empty($send_tm)) + $send_tm = date('Y-m-d H:i:s'); + + $data_fax_imgs = [ + 'stat_cd' => $stat_cd, + 'send_tm' => $send_tm, + ]; + + $builder = $this->db->table('fax_imgs'); + $builder->where('fax_sq', $fax_sq); + $builder->where('vr_sq', $vr_sq); + $builder->update($data_fax_imgs); + + log_message('debug', $this->db->getLastQuery()); + } + + /** + * 검증요청 v2_vrfc_req의 상태 stat_cd를 업데이트한다. + */ + public function saveV2VrfcReq($vr_sq, $stat_cd) + { + + $sql = "update v2_vrfc_req" . + " set stat_cd = ?" . + " where vr_sq = ?"; + $data = array($stat_cd, $vr_sq); + + $res = $this->db->query($sql, $data); + log_message('debug', $this->db->getLastQuery()); + log_message('debug', $res); + } + + /** + * 홍보확인서를 매물정보에 등록한다. + */ + public function saveV2Files($vr_sq, $file_path, $file_name, $file_ext, $file_size, $img_width, $img_height, $insert_user) + { + $arrImagePath = array( + '/home/confirms/test-admin.confirms.co.kr/upload/', + '/home/confirms/upload/', + '/home/www/admin.confirms.co.kr/upload/', + '/home/www/upload/', + '/image/confirms_upload/', + '/misc/image/confirms_upload/', + '/storage/web/admin.confirms.co.kr/src/upload/', + '/storage/web/admin.confirms.co.kr/upload/', + $_SERVER['DOCUMENT_ROOT'] . '/upload/', + ); + + $file_path = str_replace($arrImagePath, '/upload/', $file_path); + $file_type = '1'; // 홍보확인서 + + + // 1. 홍보확이서 등록여부 확인 + $sql = "SELECT count(*) file_cnt FROM v2_files" . + " WHERE vr_sq = ?" . + " AND file_type = ?" . + " AND file_path = ?" . + " AND file_name = ?" . + " AND use_yn = 'Y'"; + $data = array( + $vr_sq, + $file_type, + $file_path, + $file_name + ); + $query = $this->db->query($sql, $data); + $row = $query->getRowArray(); + + if (empty($row['file_cnt'])) { + // 2. 다른파일로 등록된 경우를 위해서 업데이트 + $sql = "UPDATE v2_files SET use_yn = 'N' WHERE vr_sq = ? AND file_type = ?"; + $data = array($vr_sq, $file_type); + $this->db->query($sql, $data); + + // 3. 등록 + $sql = "INSERT INTO v2_files " . + " (vr_sq, use_yn, file_type, view_odr, file_path, file_name, file_ext, file_size, img_width, img_height, insert_user, insert_tm)" . + " VALUES" . + " (?, 'Y', ?, '1', ?, ?, ?, ?, ?, ?, ?, NOW())"; + + $data = array($vr_sq, $file_type, $file_path, $file_name, $file_ext, $file_size, $img_width, $img_height, $insert_user); + $this->db->query($sql, $data); + } + } + + /** + * 검증결과 전송 API를 위한 데이터 조회.. + */ + public function getDataConfirmAPI($vr_sq) + { + // 요청정보 + $sql = "SELECT vr_sq, atcl_no, step, cpid, cp_atcl_id, trade_type, realtor_nm, realtor_tel_no, seller_tel_no, vrfc_type, rgbk_confirm, req_type, rdate, stat_cd, try_cnt, insert_user, insert_tm" . + " FROM v2_vrfc_req WHERE vr_sq = ?"; + + $query = $this->db->query($sql, [$vr_sq]); + $row_vrfc_req = $query->getRowArray(); + + // 매물정보 + $sql = "SELECT vr_sq, atcl_no, cpid, cp_atcl_id, rlet_type_cd, trade_type, address_code, address1, address2, address3, sply_spc, excls_spc, tot_spc, grnd_spc, bldg_spc, deal_amt, wrrnt_amt, lease_amt, isale_amt, prem_amt, sise, floor, rdate, seller_tel_no, seller_nm, realtor_nm, realtor_tel_no, hscp_no, hscp_nm, ptp_no, ptp_nm, charger, req_price_yn, reg_charger, dept1_sq, dept2_sq, reg_dept1_sq, reg_dept2_sq, floor2" . + " FROM v2_article_info WHERE vr_sq = ?"; + + $query = $this->db->query($sql, [$vr_sq]); + $query->getRowArray(); + + // 수정정보 + $sql = "SELECT vr_sq, bild_nm, rm_no, floor, address_code, address2, address3, address4, trade_type, deal_amt, wrrnt_amt, lease_amt, isale_amt, prem_amt, sply_spc, excls_spc, tot_spc, grnd_spc, bldg_spc, hscp_no, hscp_nm, ptp_no, ptp_nm, modify_yn, floor2 FROM v2_modify_info WHERE vr_sq = ?"; + + $query = $this->db->query($sql, [$vr_sq]); + $row_modify_info = $query->getRowArray(); + + // 검증결과 + $sql = "SELECT vr_sq, vrfc_type, success, type, charger, date, insert_user, insert_tm, update_user, update_tm, work_type" . + " FROM v2_confirm WHERE vr_sq = ? AND vrfc_type = ?"; + + $query = $this->db->query($sql, [$vr_sq, $row_vrfc_req['vrfc_type']]); + $row_confirm = $query->getRowArray(); + + // 확인정보 + $sql = "SELECT type, code, comment, ownerNm, ownerBirth FROM v2_check_list WHERE vr_sq = ? AND vrfc_type = ? AND type LIKE CONCAT(vrfc_type, '%')"; + + $query = $this->db->query($sql, [$vr_sq, $row_vrfc_req['vrfc_type']]); + $res_check_list = $query->getResultArray(); + + $atclNo = $row_vrfc_req['atcl_no']; + $success = empty($row_confirm['success']) ? false : true; + $charger = $row_confirm['charger']; + $date = $row_confirm['date']; + $try_cnt = $row_vrfc_req['try_cnt']; + + $checkList = []; + foreach ($res_check_list as $row) { + $checkList[] = [ + 'type' => $row['type'], + 'code' => $row['code'], + 'comment' => $row['comment'], + 'ownerNm' => $row['ownerNm'], + 'ownerBirth' => $row['ownerBirth'], + ]; + } + + $modifyInfo = []; + if ($row_modify_info['modify_yn'] == 'Y') { + if (!empty($row_modify_info['hscp_no'])) { + // 공동주택 + $modifyInfo = [ + 'hscpNo' => $row_modify_info['hscp_no'], + 'ptpNo' => $row_modify_info['ptp_no'], + 'bildNm' => $row_modify_info['address2'], + 'rmNo' => $row_modify_info['address3'], + 'tradeType' => $row_modify_info['trade_type'], + 'dealAmt' => $row_modify_info['deal_amt'], + 'wrrntAmt' => $row_modify_info['wrrnt_amt'], + 'leaseAmt' => $row_modify_info['lease_amt'], + 'isaleAmt' => $row_modify_info['isale_amt'], + 'premAmt' => $row_modify_info['prem_amt'], + 'floor' => $row_modify_info['floor'], + ]; + } else { + // 비공동주택 + $modifyInfo = [ + 'addressCode' => $row_modify_info['address_code'], + 'address2' => $row_modify_info['address2'], + 'address3' => $row_modify_info['address3'], + 'tradeType' => $row_modify_info['trade_type'], + 'dealAmt' => $row_modify_info['deal_amt'], + 'wrrntAmt' => $row_modify_info['wrrnt_amt'], + 'leaseAmt' => $row_modify_info['lease_amt'], + 'splySpc' => $row_modify_info['sply_spc'], + 'exclsSpc' => $row_modify_info['excls_spc'], + 'totSpc' => $row_modify_info['tot_spc'], + 'grndSpc' => $row_modify_info['grnd_spc'], + 'bldgSpc' => $row_modify_info['bldg_spc'], + 'floor' => $row_modify_info['floor'], + 'floor2' => $row_modify_info['floor2'], + ]; + } + + return [ + 'atclNo' => $atclNo, + 'success' => $success, + 'checkList' => $checkList, + 'charger' => $charger, + 'modifyInfo' => $modifyInfo, + 'date' => $date, + 'try_cnt' => $try_cnt, + ]; + } + + return [ + 'atclNo' => $atclNo, + 'success' => $success, + 'checkList' => $checkList, + 'charger' => $charger, + 'date' => $date, + 'try_cnt' => $try_cnt, + ]; + } + + /** + * 담당자를 지정해준다. + */ + public function InsCharger($vr_sq) + { + $usr_id = session('usr_id'); + + $sql = "UPDATE v2_article_info" . + " SET charger = ?" . + " WHERE vr_sq = ?"; + + $data = array( + $usr_id, + $vr_sq + ); + + $this->db->query($sql, $data); + } + + + /** + * 상태를 변경한다. + */ + public function saveChangeStep($fax_sq, $vr_sq, $stat_cd) + { + $insert_user = session('usr_sq'); + $insert_id = session('usr_id'); + + $this->db->transStart(); + + // 1. 검증요청 상태변경 v2_vrfc_req + $this->saveV2VrfcReq($vr_sq, $stat_cd); + + // 2. 상태변경 저장 v2_chg_stat + $this->saveV2ChgStat($vr_sq, $stat_cd, $insert_user); + + // 3. 변경이력 저장 v2_chg_history + $this->saveV2ChgHistory($vr_sq, $stat_cd, 'C9', $insert_id, ""); + + // 4. FAX에 최종 저장시 상태값 저장 + $this->saveFaxImgsAfterSend($fax_sq, $vr_sq, $stat_cd, $send_tm = ''); + + $this->db->transComplete(); + + $return = array( + 'code' => $this->db->_error_number(), + 'message' => $this->db->_error_message(), + ); + + return $return; + } + + /** + * 값을 실패횟수 값을 증가시킨다. + */ + public function increseTryCnt($vr_sq) + { + $sql = "update v2_vrfc_req set try_cnt = ifnull(try_cnt,0) +1 where vr_sq = ?"; + $data = array($vr_sq); + $this->db->query($sql, $data); + } + + public function getI8Cnt($rsrv_sq) + { + $sql = "SELECT COUNT(img_sq) cnt" . + " FROM result_imgs" . + " WHERE rsrv_sq = ?" . + " AND img_type = 'I8'" . + " AND use_yn = 'Y'"; + $data = array($rsrv_sq); + $query = $this->db->query($sql, $data); + return $query->getRowArray(); + } + + public function get_rsrv_sq($rcpt_sq) + { + $sql = "SELECT rsrv_sq " . + " FROM result" . + " WHERE rcpt_sq = ?"; + $data = array($rcpt_sq); + $query = $this->db->query($sql, $data); + + return $query->getRowArray(); + } + + // 메모저장 + public function saveMemo($data) + { + $usr_id = session('usr_id'); + + $sql = "UPDATE v2_vrfc_req SET + memo = ? + WHERE vr_sq = ?"; + + if ($this->db->query($sql, $data) === false) { + return [ + 'success' => false, + 'msg' => '파일정보 저장 실패', + ]; + } + + $row = $this->getDetail($data[1]); + + $memo = "메모변경 : " . $row['memo'] . " => " . $data[0]; + $this->saveChangedHistory($data[1], $row['pre_stat_cd'], 'C19', $usr_id, $memo); + + return [ + 'success' => true + ]; + } + + /** + * 변경이력 저장하기 + */ + public function saveV2ChgHistory($vr_sq, $stat_cd, $chg_type, $insert_id, $memo) + { + $sql = "INSERT INTO v2_chg_history" . + " (vr_sq, stat_cd, chg_type, insert_id, insert_tm, memo)" . + " VALUES" . + " (?, ?, ?, ?, now(), ?)"; + + $data = array($vr_sq, $stat_cd, $chg_type, $insert_id, $memo); + $this->db->query($sql, $data); + log_message('debug', $this->db->getLastQuery()); + } + // 변경내용 저장 public function saveChangedHistory($rcpt_sq, $rcpt_stat, $changed_type, $usr_id, $remark) diff --git a/app/Models/webfax/FaxModel.php b/app/Models/webfax/FaxModel.php index a6681ba..ff4b9b0 100644 --- a/app/Models/webfax/FaxModel.php +++ b/app/Models/webfax/FaxModel.php @@ -5,6 +5,19 @@ use CodeIgnier\Model; class FaxModel extends Model { + /** + * FAX 내용중 하나만 가져오기 + */ + public function selectFax($faxSq) + { + $sql = "SELECT mid, caller_no, recv_time, fax_sq, file_path, file_name, thumbnail, img_width, img_height, img_size" . + " FROM fax_imgs" . + " WHERE fax_sq = ?"; + $data = array($faxSq); + $query = $this->db->query($sql, $data); + return $query->getRowArray(); + } + public function selectFaxListNotExistsThumb() { helper('cron'); diff --git a/app/Views/pages/v2/m708/detail.php b/app/Views/pages/v2/m708/detail.php index 9356e76..e518cda 100644 --- a/app/Views/pages/v2/m708/detail.php +++ b/app/Views/pages/v2/m708/detail.php @@ -41,9 +41,9 @@ $usr_level = session('usr_level');
-
+ - + @@ -174,7 +174,7 @@ $usr_level = session('usr_level'); style="max-width: 320px;"> @@ -358,7 +358,7 @@ $usr_level = session('usr_level'); + value="" disabled>