api
This commit is contained in:
50
app/Models/Entities/V2chgstatModel.php
Normal file
50
app/Models/Entities/V2chgstatModel.php
Normal file
@@ -0,0 +1,50 @@
|
||||
<?php
|
||||
namespace App\Models;
|
||||
|
||||
use CodeIgniter\Model;
|
||||
|
||||
class V2chgstatModel extends Model
|
||||
{
|
||||
protected $table = 'v2_chg_stat';
|
||||
protected $primaryKey = 'seq'; // 실제 PK 컬럼명으로 수정하세요 (st_date, cpid, gbn_cd가 복합키인 경우도 있음)
|
||||
protected $allowedFields = ['vr_sq', 'stat_cd', 'insert_user', 'insert_tm'];
|
||||
|
||||
protected $useTimestamps = false; // insert_tm을 직접 넣으시므로 false
|
||||
|
||||
/**
|
||||
* 상태 변경 이력 저장 (CI4 통합 버전)
|
||||
* @param array $data ['vr_sq' => 값, 'stat_cd' => 값, ...]
|
||||
* @param string $saveType 'I'(Upsert), 'U'(Update)
|
||||
*/
|
||||
public function saveChgstat(array $data, string $saveType)
|
||||
{
|
||||
// 1. 기본값 세팅 (데이터 유연성 확보)
|
||||
$payload = [
|
||||
'vr_sq' => $data['vr_sq'] ?? null,
|
||||
'stat_cd' => $data['stat_cd'] ?? '10', // 기본값 30
|
||||
'insert_user' => $data['insert_user'] ?? 0,
|
||||
'insert_tm' => $data['insert_tm'] ?? date('Y-m-d H:i:s'),
|
||||
];
|
||||
|
||||
if (empty($payload['vr_sq'])) {
|
||||
throw new \Exception("V2chgstatModel Error: vr_sq is required.");
|
||||
}
|
||||
|
||||
if ($saveType === 'I') {
|
||||
// CI2 방식의 ON DUPLICATE KEY UPDATE 유지 (seq 번호 보존을 위해)
|
||||
$sql = "INSERT INTO v2_chg_stat (vr_sq, stat_cd, insert_user, insert_tm)
|
||||
VALUES (:vr_sq:, :stat_cd:, :insert_user:, :insert_tm:)
|
||||
ON DUPLICATE KEY UPDATE
|
||||
insert_user = VALUES(insert_user),
|
||||
insert_tm = VALUES(insert_tm)";
|
||||
|
||||
return $this->db->query($sql, $payload);
|
||||
} else {
|
||||
// Update 방식
|
||||
return $this->where('vr_sq', $payload['vr_sq'])
|
||||
->where('stat_cd', $payload['stat_cd'])
|
||||
->set($payload)
|
||||
->update();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user