fix:입출금내역 save()를 순수 Query Builder로 전환

Eloquent 모델의 decimal cast + opcache 캐시 문제로 인해
deposit/withdraw/balance가 dirty 감지되어 unique 제약조건 위반.
- Eloquent 완전 우회: DB::table() 기반 lookup + update + insert
- CAST(AS SIGNED) 제거: 정확한 decimal 비교로 변경

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
김보곤
2026-02-10 16:42:13 +09:00
parent d5606e71d6
commit 1cab267ec6

View File

@@ -938,21 +938,20 @@ public function save(Request $request): JsonResponse
]);
$savedUniqueKeys[] = $uniqueKey;
// Upsert: 있으면 업데이트, 없으면 생성
// balance 포함: 같은 금액이라도 잔액이 다르면 별도 거래로 구분
$existing = BankTransaction::where('tenant_id', $tenantId)
// 순수 Query Builder로 Upsert (Eloquent 모델 우회)
// Eloquent의 decimal cast가 dirty 감지하여 unique 제약조건 위반을 일으키므로
$existingId = DB::table('barobill_bank_transactions')
->where('tenant_id', $tenantId)
->where('bank_account_num', $data['bank_account_num'])
->where('trans_dt', $transDt)
->whereRaw('CAST(deposit AS SIGNED) = ?', [(int) $data['deposit']])
->whereRaw('CAST(withdraw AS SIGNED) = ?', [(int) $data['withdraw']])
->whereRaw('CAST(balance AS SIGNED) = ?', [(int) $data['balance']])
->first();
->where('deposit', $data['deposit'])
->where('withdraw', $data['withdraw'])
->where('balance', $data['balance'])
->value('id');
if ($existing) {
// Query Builder 사용: Eloquent의 decimal:2 cast가 balance를
// dirty로 잘못 감지하여 unique 제약조건 위반을 일으키는 문제 방지
if ($existingId) {
DB::table('barobill_bank_transactions')
->where('id', $existing->id)
->where('id', $existingId)
->update([
'summary' => $data['summary'],
'cast' => $data['cast'],
@@ -963,7 +962,10 @@ public function save(Request $request): JsonResponse
]);
$updated++;
} else {
BankTransaction::create($data);
DB::table('barobill_bank_transactions')->insert(array_merge($data, [
'created_at' => now(),
'updated_at' => now(),
]));
$saved++;
}
}