현장 확인 업로드

This commit is contained in:
2026-03-03 21:41:02 +09:00
parent 243ca0c45e
commit f02f8c0457
126 changed files with 2716 additions and 438 deletions

View File

@@ -0,0 +1,154 @@
<?php
namespace App\Models\Entities;
use CodeIgniter\Model;
class WatermarkModel extends Model
{
protected $table = 'watermark';
protected $primaryKey = ['cpid', 'wm_type']; // 복합키
protected $useAutoIncrement = false;
protected $returnType = 'array';
protected $useSoftDeletes = false;
protected $allowedFields = [
'cpid',
'wm_type',
'wm_img_path',
'wm_img_height',
'wm_img_width',
'wm_position',
'wm_img_opacity',
'wm_space',
'text_font',
'text_color',
'text_opacity',
'text_size',
'text_pixel',
'img_width_min',
'img_width_max'
];
protected $useTimestamps = false;
protected $validationRules = [
'cpid' => 'required|max_length[20]',
'wm_type' => 'required|integer',
'wm_img_path' => 'required|max_length[300]',
'wm_img_height' => 'required|integer',
'wm_img_width' => 'required|integer',
'wm_position' => 'required|max_length[2]',
'wm_img_opacity' => 'required|integer',
'wm_space' => 'required|integer',
'img_width_min' => 'required|integer',
'img_width_max' => 'required|integer'
];
protected $validationMessages = [];
protected $skipValidation = false;
/**
* 워터마크 정보 조회 (복합키)
*
* @param string $cpid
* @param int $wm_type
* @return array|null
*/
public function getWatermark($cpid, $wm_type)
{
return $this->where('cpid', $cpid)
->where('wm_type', $wm_type)
->first();
}
/**
* cpid로 워터마크 목록 조회
*
* @param string $cpid
* @return array
*/
public function getWatermarksByCpid($cpid)
{
return $this->where('cpid', $cpid)->findAll();
}
/**
* 워터마크 타입별 조회
*
* @param int $wm_type
* @return array
*/
public function getWatermarksByType($wm_type)
{
return $this->where('wm_type', $wm_type)->findAll();
}
/**
* 워터마크 정보 저장/업데이트
*
* @param array $data
* @return bool
*/
public function saveWatermark($data)
{
if (!isset($data['cpid']) || !isset($data['wm_type'])) {
return false;
}
// 복합키로 기존 데이터 확인
$existing = $this->getWatermark($data['cpid'], $data['wm_type']);
if ($existing) {
// 업데이트
return $this->where('cpid', $data['cpid'])
->where('wm_type', $data['wm_type'])
->set($data)
->update();
} else {
// 삽입
return $this->insert($data);
}
}
/**
* 워터마크 삭제 (복합키)
*
* @param string $cpid
* @param int $wm_type
* @return bool
*/
public function deleteWatermark($cpid, $wm_type)
{
return $this->where('cpid', $cpid)
->where('wm_type', $wm_type)
->delete();
}
/**
* cpid로 모든 워터마크 삭제
*
* @param string $cpid
* @return bool
*/
public function deleteAllByCpid($cpid)
{
return $this->where('cpid', $cpid)->delete();
}
/**
* 이미지 크기 범위로 워터마크 조회
*
* @param string $cpid
* @param int $img_width
* @return array|null
*/
public function getWatermarkByImageSize($cpid, $img_width)
{
return $this->where('cpid', $cpid)
->where('img_width_min <=', $img_width)
->where('img_width_max >=', $img_width)
->findAll();
}
}

View File

@@ -409,10 +409,9 @@ class ReceiptModel extends Model
}
// log_message('debug', '[getTotalCount] SQL = ' . $builder->getCompiledSelect());
$row = $builder->get()->getRowArray();
error_log('[getTotalCount] SQL = ' . $this->db->getLastQuery());
return (int) ($row['cnt'] ?? 0);
}
@@ -538,10 +537,10 @@ class ReceiptModel extends Model
$builder->join('result b', 'b.rcpt_sq = a.rcpt_sq', 'inner');
$builder->join('region_codes c', 'a.rcpt_dong = c.region_cd', 'inner');
$builder->join('departments d', 'b.dept_sq = d.dept_sq', 'left');
$builder->join('users u', 'b.usr_sq = u.usr_sq', 'left');
$builder->join('result_imgs e', "e.rsrv_sq = b.rsrv_sq AND e.img_type = 'I1' AND e.use_yn = 'Y'", 'left');
$builder->join('receipt_transimage_log l', 'a.rcpt_key = l.rcpt_key', 'left');
$builder->join('departments d', 'b.dept_sq = d.dept_sq', 'left outer');
$builder->join('users u', 'b.usr_sq = u.usr_sq', 'left outer');
$builder->join('result_imgs e', "e.rsrv_sq = b.rsrv_sq AND e.img_type = 'I1' AND e.use_yn = 'Y'", 'left outer');
$builder->join('receipt_transimage_log l', 'a.rcpt_key = l.rcpt_key', 'left outer');
$login_dept_info = $this->getDeptDetail($dept_sq); // 로그인 사용자 소속부서정보
@@ -573,8 +572,8 @@ class ReceiptModel extends Model
$builder->where('a.rcpt_tm >=', $data['sdate'] . ' 00:00:00');
$builder->where('a.rcpt_tm <=', $data['edate'] . ' 23:59:59');
} else {
$builder->where('b.rsrv_date >=', $data['sdate'] . ' 00:00:00');
$builder->where('b.rsrv_date <=', $data['edate'] . ' 23:59:59');
$builder->where('b.rsrv_date >=', $data['sdate'] );
$builder->where('b.rsrv_date <=', $data['edate'] );
}
// 지역
@@ -753,9 +752,12 @@ class ReceiptModel extends Model
$builder->limit($end, $start);
// log_message('debug', '[getResultList] SQL = ' . $builder->getCompiledSelect());
$result = $builder->get()->getResultArray();
error_log('[getResultList] SQL = ' . $this->db->getLastQuery());
error_log('[getResultList] Result count = ' . count($result));
return $builder->get()->getResultArray();
return $result;
}
@@ -1837,7 +1839,8 @@ class ReceiptModel extends Model
$receipt = $param['receipt'];
$cloud_upload_yn = 'Y';
// 실제 클라우드 업로드 성공 여부를 파라미터에서 받아옴 (기본값 'Y')
$cloud_upload_yn = $param['cloud_upload_yn'] ?? 'Y';
if ($param['img_type'] == 'I6' || $param['img_type'] == 'I7') {
$yn_sql = "update receipt " .
@@ -2011,103 +2014,161 @@ class ReceiptModel extends Model
// 이미지정보 조회
$row = $this->getUploadFileInfo($img_sq);
if (!empty($row)) {
if (empty($row)) {
$this->db->transComplete();
// 파일이 이미 삭제된 경우 성공으로 처리 (중복 삭제 요청 방지)
log_message('info', "[removeUploadFile] 파일 정보 없음 (이미 삭제됨): img_sq={$img_sq}");
return [
'success' => true,
'msg' => '이미 삭제된 파일입니다',
];
}
if ($row['img_type'] == 'I6' || $row['img_type'] == 'I7') {
$yn_sql = "update receipt " .
" set exp_spc_yn = 'N' " .
" where rcpt_sq = ? ";
$yn_data = [$rcpt_sq];
$this->db->query($yn_sql, $yn_data);
} else if ($row['img_type'] == 'I8') {
$yn_sql = "UPDATE receipt" .
" SET parcel_out_yn = CASE (SELECT COUNT('x')" .
" FROM result_imgs " .
" WHERE rsrv_sq = (SELECT rsrv_sq FROM result_imgs WHERE img_sq = ? AND img_type = 'I8')" .
" AND use_yn = 'Y'" .
" AND img_type = 'I8') WHEN 0 THEN 'N' ELSE 'Y' END" .
" WHERE rcpt_sq = ? ";
$yn_data = [$rcpt_sq];
$this->db->query($yn_sql, $yn_data);
} else if ($row['img_type'] == 'I9') {
$yn_sql = "UPDATE receipt" .
" SET image_360_yn = (" .
" CASE (SELECT COUNT(1)" .
" FROM result_imgs" .
" WHERE rsrv_sq = (SELECT rsrv_sq FROM result_imgs WHERE img_sq = ? AND img_type = 'I9')" .
" AND img_type = 'I9' AND use_yn = 'Y')" .
" WHEN 0 THEN 'N'" .
" ELSE 'Y'" .
" END" .
" )" .
" WHERE rcpt_sq = ?";
$yn_data = [$rcpt_sq];
$this->db->query($yn_sql, $yn_data);
} else if ($row['img_type'] == 'I11') {
$yn_sql = "update receipt " .
" set check_list_img_yn = 'N' " .
" where rcpt_sq = ? ";
$yn_data = [$rcpt_sq];
$this->db->query($yn_sql, $yn_data);
if ($row['img_type'] == 'I6' || $row['img_type'] == 'I7') {
$yn_sql = "update receipt " .
" set exp_spc_yn = 'N' " .
" where rcpt_sq = ? ";
$yn_data = [$rcpt_sq];
$this->db->query($yn_sql, $yn_data);
} else if ($row['img_type'] == 'I8') {
$yn_sql = "UPDATE receipt" .
" SET parcel_out_yn = CASE (SELECT COUNT('x')" .
" FROM result_imgs " .
" WHERE rsrv_sq = (SELECT rsrv_sq FROM result_imgs WHERE img_sq = ? AND img_type = 'I8')" .
" AND use_yn = 'Y'" .
" AND img_type = 'I8') WHEN 0 THEN 'N' ELSE 'Y' END" .
" WHERE rcpt_sq = ? ";
$yn_data = [$img_sq, $rcpt_sq];
$this->db->query($yn_sql, $yn_data);
} else if ($row['img_type'] == 'I9') {
$yn_sql = "UPDATE receipt" .
" SET image_360_yn = (" .
" CASE (SELECT COUNT(1)" .
" FROM result_imgs" .
" WHERE rsrv_sq = (SELECT rsrv_sq FROM result_imgs WHERE img_sq = ? AND img_type = 'I9')" .
" AND img_type = 'I9' AND use_yn = 'Y')" .
" WHEN 0 THEN 'N'" .
" ELSE 'Y'" .
" END" .
" )" .
" WHERE rcpt_sq = ?";
$yn_data = [$img_sq, $rcpt_sq];
$this->db->query($yn_sql, $yn_data);
} else if ($row['img_type'] == 'I11') {
$yn_sql = "update receipt " .
" set check_list_img_yn = 'N' " .
" where rcpt_sq = ? ";
$yn_data = [$rcpt_sq];
$this->db->query($yn_sql, $yn_data);
}
//삭제이미지보다 순번이 높은거는 순번 업데이트
$sql = "UPDATE result_imgs SET view_odr = view_odr - 1 WHERE rsrv_sq = ? AND img_type = ? AND view_odr > ? AND use_yn = 'Y'";
$data = [$row['rsrv_sq'], $row['img_type'], $row['view_odr']];
$this->db->query($sql, $data);
//이미지 삭제
$sql = "DELETE FROM result_imgs WHERE img_sq = ?";
$data = [$img_sq];
$deleteResult = $this->db->query($sql, $data);
if (in_array($row['img_type'], ['I1', 'I2', 'I8', 'I10', 'I11'])) {
$remark = "";
switch ($row['img_type']) {
case 'I1':
$remark = "홍보확인서 사진 삭제";
break;
case 'I2':
$remark = "현장확인 내역서 사진 삭제";
break;
case 'I8':
$remark = "분양권 파일 삭제";
break;
case 'I10':
$remark = "촬영동의서 사진 삭제";
break;
case 'I11':
$remark = "체크리스트 사진 삭제";
break;
}
// 상태값을 가져오기위한 쿼리 해오기
$sql = "SELECT rcpt_stat FROM receipt WHERE rcpt_sq = ?";
$data = [$rcpt_sq];
$query = $this->db->query($sql, $data);
$rowStat = $query->getRowArray();
//삭제이미지보다 순번이 높은거는 순번 업데이트
$sql = "UPDATE result_imgs SET view_odr = view_odr - 1 WHERE rsrv_sq = ? AND img_type = ? AND view_odr > ? AND use_yn = 'Y'";
$data = [$row['rsrv_sq'], $row['img_type'], $row['view_odr']];
$this->saveChangedHistory($rcpt_sq, $rowStat['rcpt_stat'], 'C31', $usr_id, $remark);
}
$this->db->query($sql, $data);
$this->db->transComplete();
if ($deleteResult === false || $this->db->transStatus() === false) {
return [
'success' => false,
'msg' => '삭제실패',
];
}
//이미지 삭제
$sql = "DELETE FROM result_imgs WHERE img_sq = ?";
$data = [$img_sq];
if ($this->db->query($sql, $data) === false) {
return [
'success' => true,
];
}
// 이미지 순서 업데이트
public function updateImageOrder($rcpt_sq, $img_type, $orderData)
{
log_message('info', '[ReceiptModel::updateImageOrder] 시작 - rcpt_sq: ' . $rcpt_sq . ', img_type: ' . $img_type . ', 개수: ' . count($orderData));
$this->db->transStart();
try {
$updateCount = 0;
foreach ($orderData as $item) {
$img_sq = $item['img_sq'] ?? null;
$view_odr = $item['view_odr'] ?? null;
if (!$img_sq || !$view_odr) {
log_message('warning', '[ReceiptModel::updateImageOrder] 스킵 - img_sq 또는 view_odr 없음');
continue;
}
$sql = "UPDATE result_imgs SET view_odr = ? WHERE img_sq = ? AND img_type = ?";
$data = [$view_odr, $img_sq, $img_type];
log_message('debug', '[ReceiptModel::updateImageOrder] 업데이트 - img_sq: ' . $img_sq . ', view_odr: ' . $view_odr);
$result = $this->db->query($sql, $data);
if ($result) {
$updateCount++;
}
}
$this->db->transComplete();
if ($this->db->transStatus() === false) {
log_message('error', '[ReceiptModel::updateImageOrder] 트랜잭션 실패');
return [
'success' => false,
'msg' => '삭제실패',
'msg' => '순서 업데이트 실패',
];
}
if (in_array($row['img_type'], ['I1', 'I2', 'I8', 'I10', 'I11'])) {
$remark = "";
switch ($row['img_type']) {
case 'I1':
$remark = "홍보확인서 사진 삭제";
break;
case 'I2':
$remark = "현장확인 내역서 사진 삭제";
break;
case 'I8':
$remark = "분양권 파일 삭제";
break;
case 'I10':
$remark = "촬영동의서 사진 삭제";
break;
case 'I11':
$remark = "체크리스트 사진 삭제";
break;
}
// 상태값을 가져오기위한 쿼리 해오기
$sql = "SELECT rcpt_stat FROM receipt WHERE rcpt_sq = ?";
$data = [$rcpt_sq];
$query = $this->db->query($sql, $data);
$row = $query->getRowArray();
$this->saveChangedHistory($rcpt_sq, $row['rcpt_stat'], 'C31', $usr_id, $remark);
}
$this->db->transComplete();
log_message('info', '[ReceiptModel::updateImageOrder] 완료 - 업데이트 수: ' . $updateCount);
return [
'success' => true,
];
} catch (\Exception $e) {
log_message('error', '[ReceiptModel::updateImageOrder] Exception: ' . $e->getMessage());
return [
'success' => false,
'msg' => '순서 업데이트 중 오류 발생: ' . $e->getMessage(),
];
}
}