fix:계좌입출금 저장 시 동일 거래일시 레코드 덮어쓰기 방지
- 기존: balance 제외 4컬럼 매칭 → 같은 시간/금액의 다른 거래가 중복으로 처리됨 - 수정: balance 포함 5컬럼 매칭 → DB unique 제약조건과 동일하게 정확히 식별 - update 시 balance 제외 (매칭 조건이므로 변경 불필요) Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -985,20 +985,21 @@ public function save(Request $request): JsonResponse
|
||||
$savedUniqueKeys[] = $uniqueKey;
|
||||
|
||||
// 순수 Query Builder로 Upsert (Eloquent 모델 우회)
|
||||
// balance 제외하고 매칭 → 같은 거래가 잔액만 다르게 들어와도 중복 방지
|
||||
// balance 포함하여 매칭 → DB unique 제약조건과 동일한 5개 컬럼으로 정확히 식별
|
||||
$existingIds = DB::table('barobill_bank_transactions')
|
||||
->where('tenant_id', $tenantId)
|
||||
->where('bank_account_num', $data['bank_account_num'])
|
||||
->where('trans_dt', $transDt)
|
||||
->where('deposit', $data['deposit'])
|
||||
->where('withdraw', $data['withdraw'])
|
||||
->where('balance', $data['balance'])
|
||||
->orderByDesc('id')
|
||||
->pluck('id');
|
||||
|
||||
if ($existingIds->isNotEmpty()) {
|
||||
$keepId = $existingIds->first(); // 최신 건 유지
|
||||
|
||||
// 중복 건 삭제 (잔액만 다른 이전 레코드)
|
||||
// 완전 동일한 중복 건 삭제
|
||||
if ($existingIds->count() > 1) {
|
||||
DB::table('barobill_bank_transactions')
|
||||
->whereIn('id', $existingIds->slice(1)->values())
|
||||
@@ -1008,7 +1009,6 @@ public function save(Request $request): JsonResponse
|
||||
DB::table('barobill_bank_transactions')
|
||||
->where('id', $keepId)
|
||||
->update([
|
||||
'balance' => $data['balance'],
|
||||
'summary' => $data['summary'],
|
||||
'cast' => $data['cast'],
|
||||
'trans_office' => $data['trans_office'],
|
||||
|
||||
Reference in New Issue
Block a user