- Auditable 트레잇: 모델 insert/update/delete 시 activity_log 자동 기록 (조회 제외, before/after JSON, 민감필드 마스킹, 사용자/IP) - 도메인 모델 28개에 적용 (로그성 테이블 제외) - 관리자 전용 조회: Admin\ActivityLog (기간/작업/대상/사용자 필터 + 상세 변경내역) - 라우트 admin/access/activity-logs(+상세), 메뉴 '활동 로그' 추가 - 테넌트 분리: 슈퍼=전체, 지자체관리자=소속 지자체만 Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
41 lines
1.2 KiB
PHP
41 lines
1.2 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use CodeIgniter\Model;
|
|
|
|
class BagInventoryModel extends Model
|
|
{
|
|
use \App\Models\Traits\Auditable;
|
|
|
|
protected $table = 'bag_inventory';
|
|
protected $primaryKey = 'bi_idx';
|
|
protected $returnType = 'object';
|
|
protected $useTimestamps = false;
|
|
protected $allowedFields = [
|
|
'bi_lg_idx', 'bi_bag_code', 'bi_bag_name', 'bi_qty', 'bi_updated_at',
|
|
];
|
|
|
|
/**
|
|
* 재고 증감 (upsert)
|
|
*/
|
|
public function adjustQty(int $lgIdx, string $bagCode, string $bagName, int $delta): void
|
|
{
|
|
$existing = $this->where('bi_lg_idx', $lgIdx)->where('bi_bag_code', $bagCode)->first();
|
|
if ($existing) {
|
|
$this->update($existing->bi_idx, [
|
|
'bi_qty' => max(0, (int) $existing->bi_qty + $delta),
|
|
'bi_updated_at' => date('Y-m-d H:i:s'),
|
|
]);
|
|
} else {
|
|
$this->insert([
|
|
'bi_lg_idx' => $lgIdx,
|
|
'bi_bag_code' => $bagCode,
|
|
'bi_bag_name' => $bagName,
|
|
'bi_qty' => max(0, $delta),
|
|
'bi_updated_at'=> date('Y-m-d H:i:s'),
|
|
]);
|
|
}
|
|
}
|
|
}
|