From 614cbaef1510afb84d438cfba199842412f641d7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B9=80=EB=B3=B4=EA=B3=A4?= Date: Tue, 3 Mar 2026 21:11:35 +0900 Subject: [PATCH] =?UTF-8?q?fix:=20[eaccount]=20=EA=B3=84=EC=A2=8C=20?= =?UTF-8?q?=EC=9E=85=EC=B6=9C=EA=B8=88=EB=82=B4=EC=97=AD=20=EC=A0=81?= =?UTF-8?q?=EC=9A=94=20=EC=A4=91=EB=B3=B5=20=ED=91=9C=EC=8B=9C=20=EC=88=98?= =?UTF-8?q?=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - BankTransaction::cleanSummary() 메서드 추가: 상대계좌예금주명(cast) 중복 제거 - parseTransactionLogs: 적요 표시 시 remark2 중복 제거 적용 - cacheApiTransactions: DB 저장 시에도 중복 제거 적용 - 기존 DB 데이터 45건 정리 완료 --- .../Barobill/EaccountController.php | 16 +++++++++---- app/Models/Barobill/BankTransaction.php | 23 ++++++++++++++++++- 2 files changed, 34 insertions(+), 5 deletions(-) diff --git a/app/Http/Controllers/Barobill/EaccountController.php b/app/Http/Controllers/Barobill/EaccountController.php index 45ca95b9..cfcba3b1 100644 --- a/app/Http/Controllers/Barobill/EaccountController.php +++ b/app/Http/Controllers/Barobill/EaccountController.php @@ -562,8 +562,10 @@ private function parseTransactionLogs($resultData, string $defaultBankName = '', $withdraw = (int) floatval($log->Withdraw ?? 0); $balance = (int) floatval($log->Balance ?? 0); $summary = $log->TransRemark1 ?? $log->Summary ?? ''; + $remark2 = $log->TransRemark2 ?? ''; + $cleanSummary = BankTransaction::cleanSummary($summary, $remark2); - $uniqueKey = implode('|', [$bankAccountNum, $transDT, $deposit, $withdraw, $balance, $summary]); + $uniqueKey = implode('|', [$bankAccountNum, $transDT, $deposit, $withdraw, $balance, $cleanSummary]); $uniqueKeys[] = $uniqueKey; } @@ -596,15 +598,18 @@ private function parseTransactionLogs($resultData, string $defaultBankName = '', $remark2 = $log->TransRemark2 ?? ''; $transType = $log->TransType ?? ''; + // ★ 적요에서 상대계좌예금주명(remark2) 중복 제거 + $cleanSummary = BankTransaction::cleanSummary($summary, $remark2); + $bankAccountNum = $log->BankAccountNum ?? ''; // 고유 키 생성하여 저장된 데이터와 매칭 (숫자는 정수로 변환하여 형식 통일) - $uniqueKey = implode('|', [$bankAccountNum, $transDT, (int) $deposit, (int) $withdraw, (int) $balance, $summary]); + $uniqueKey = implode('|', [$bankAccountNum, $transDT, (int) $deposit, (int) $withdraw, (int) $balance, $cleanSummary]); $savedItem = $savedData?->get($uniqueKey); $override = $overrides->get($uniqueKey); // 원본 적요/내용 (remark2를 합산하지 않음 - 상대계좌예금주명 컬럼에서 별도 표시) - $originalSummary = $summary; + $originalSummary = $cleanSummary; $originalCast = $savedItem?->cast ?? $remark2; // 오버라이드 적용 (수정된 값이 있으면 사용) @@ -850,6 +855,9 @@ private function cacheApiTransactions(int $tenantId, string $accNum, string $ban $summary = $log->TransRemark1 ?? $log->Summary ?? ''; $remark2 = $log->TransRemark2 ?? ''; + // ★ 적요에서 상대계좌예금주명(remark2) 중복 제거 + $cleanSummary = BankTransaction::cleanSummary($summary, $remark2); + $rows[] = [ 'tenant_id' => $tenantId, 'bank_account_num' => $log->BankAccountNum ?? $accNum, @@ -861,7 +869,7 @@ private function cacheApiTransactions(int $tenantId, string $accNum, string $ban 'deposit' => $deposit, 'withdraw' => $withdraw, 'balance' => $balance, - 'summary' => $summary, + 'summary' => $cleanSummary, 'cast' => $remark2, 'memo' => $log->Memo ?? '', 'trans_office' => $log->TransOffice ?? '', diff --git a/app/Models/Barobill/BankTransaction.php b/app/Models/Barobill/BankTransaction.php index 242491d3..bb054196 100644 --- a/app/Models/Barobill/BankTransaction.php +++ b/app/Models/Barobill/BankTransaction.php @@ -49,19 +49,40 @@ public function tenant(): BelongsTo return $this->belongsTo(Tenant::class); } + /** + * 적요(summary)에서 상대계좌예금주명(cast/remark2) 중복 제거 + * 바로빌 API 응답에서 TransRemark1에 TransRemark2가 포함되는 경우 정리 + */ + public static function cleanSummary(string $summary, string $remark): string + { + if (empty($remark) || empty($summary) || ! str_contains($summary, $remark)) { + return $summary; + } + + $result = rtrim($summary); + + while (str_ends_with($result, $remark) && strlen($result) > strlen($remark)) { + $result = rtrim(substr($result, 0, -strlen($remark))); + } + + return $result; + } + /** * 거래 고유 키 생성 (매칭용) * 숫자는 정수로 변환하여 형식 통일 */ public function getUniqueKeyAttribute(): string { + $cleanSummary = self::cleanSummary($this->summary ?? '', $this->cast ?? ''); + return implode('|', [ $this->bank_account_num, $this->trans_dt, (int) $this->deposit, (int) $this->withdraw, (int) $this->balance, - $this->summary ?? '', + $cleanSummary, ]); }