From 1cab267ec66a4a07b3afa996e4e4a0615cd7cc18 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B9=80=EB=B3=B4=EA=B3=A4?= Date: Tue, 10 Feb 2026 16:42:13 +0900 Subject: [PATCH] =?UTF-8?q?fix:=EC=9E=85=EC=B6=9C=EA=B8=88=EB=82=B4?= =?UTF-8?q?=EC=97=AD=20save()=EB=A5=BC=20=EC=88=9C=EC=88=98=20Query=20Buil?= =?UTF-8?q?der=EB=A1=9C=20=EC=A0=84=ED=99=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- .../Barobill/EaccountController.php | 26 ++++++++++--------- 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/app/Http/Controllers/Barobill/EaccountController.php b/app/Http/Controllers/Barobill/EaccountController.php index 1b51e9f0..943743c1 100644 --- a/app/Http/Controllers/Barobill/EaccountController.php +++ b/app/Http/Controllers/Barobill/EaccountController.php @@ -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++; } }