From f665d3aea8cb85416ce5d90e93ccc767009d8f84 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=9C=A0=EB=B3=91=EC=B2=A0?= Date: Wed, 4 Mar 2026 14:28:00 +0900 Subject: [PATCH] =?UTF-8?q?fix:=20[entertainment,welfare]=20=EB=B0=94?= =?UTF-8?q?=EB=A1=9C=EB=B9=8C=20=EC=A1=B0=EC=9D=B8=20=EC=BB=AC=EB=9F=BC?= =?UTF-8?q?=EB=AA=85=20=EB=B0=8F=20=EC=8B=AC=EC=95=BC=20=EC=8B=9C=EA=B0=84?= =?UTF-8?q?=20=ED=8C=8C=EC=8B=B1=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - approval_no → approval_num 컬럼명 수정 - use_time 심야 판별: HOUR() → SUBSTRING 문자열 파싱으로 변경 - whereNotNull('bct.use_time') 조건 추가 Co-Authored-By: Claude Opus 4.6 --- app/Services/EntertainmentService.php | 9 +++++---- app/Services/WelfareService.php | 7 ++++--- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/app/Services/EntertainmentService.php b/app/Services/EntertainmentService.php index 773d3cd..b47da70 100644 --- a/app/Services/EntertainmentService.php +++ b/app/Services/EntertainmentService.php @@ -125,7 +125,7 @@ private function getWeekendLateNightRisk(int $tenantId, string $startDate, strin // 심야 사용 (barobill 카드 거래 내역에서 시간 확인) $lateNightResult = DB::table('expense_accounts as ea') ->leftJoin('barobill_card_transactions as bct', function ($join) { - $join->on('ea.receipt_no', '=', 'bct.approval_no') + $join->on('ea.receipt_no', '=', 'bct.approval_num') ->on('ea.tenant_id', '=', 'bct.tenant_id'); }) ->where('ea.tenant_id', $tenantId) @@ -133,9 +133,10 @@ private function getWeekendLateNightRisk(int $tenantId, string $startDate, strin ->whereBetween('ea.expense_date', [$startDate, $endDate]) ->whereNull('ea.deleted_at') ->whereRaw('DAYOFWEEK(ea.expense_date) NOT IN (1, 7)') // 주말 제외 (중복 방지) + ->whereNotNull('bct.use_time') ->where(function ($q) { - $q->whereRaw('HOUR(bct.use_time) >= ?', [self::LATE_NIGHT_START]) - ->orWhereRaw('HOUR(bct.use_time) < ?', [self::LATE_NIGHT_END]); + $q->whereRaw('CAST(SUBSTRING(bct.use_time, 1, 2) AS UNSIGNED) >= ?', [self::LATE_NIGHT_START]) + ->orWhereRaw('CAST(SUBSTRING(bct.use_time, 1, 2) AS UNSIGNED) < ?', [self::LATE_NIGHT_END]); }) ->selectRaw('COUNT(*) as count, COALESCE(SUM(ea.amount), 0) as total') ->first(); @@ -154,7 +155,7 @@ private function getProhibitedBizTypeRisk(int $tenantId, string $startDate, stri { $result = DB::table('expense_accounts as ea') ->join('barobill_card_transactions as bct', function ($join) { - $join->on('ea.receipt_no', '=', 'bct.approval_no') + $join->on('ea.receipt_no', '=', 'bct.approval_num') ->on('ea.tenant_id', '=', 'bct.tenant_id'); }) ->where('ea.tenant_id', $tenantId) diff --git a/app/Services/WelfareService.php b/app/Services/WelfareService.php index 7cad512..6231f9f 100644 --- a/app/Services/WelfareService.php +++ b/app/Services/WelfareService.php @@ -177,7 +177,7 @@ private function getPrivateUseRisk(int $tenantId, string $startDate, string $end // 심야 사용 (barobill 조인) $lateNightResult = DB::table('expense_accounts as ea') ->leftJoin('barobill_card_transactions as bct', function ($join) { - $join->on('ea.receipt_no', '=', 'bct.approval_no') + $join->on('ea.receipt_no', '=', 'bct.approval_num') ->on('ea.tenant_id', '=', 'bct.tenant_id'); }) ->where('ea.tenant_id', $tenantId) @@ -185,9 +185,10 @@ private function getPrivateUseRisk(int $tenantId, string $startDate, string $end ->whereBetween('ea.expense_date', [$startDate, $endDate]) ->whereNull('ea.deleted_at') ->whereRaw('DAYOFWEEK(ea.expense_date) NOT IN (1, 7)') + ->whereNotNull('bct.use_time') ->where(function ($q) { - $q->whereRaw('HOUR(bct.use_time) >= 22') - ->orWhereRaw('HOUR(bct.use_time) < 6'); + $q->whereRaw('CAST(SUBSTRING(bct.use_time, 1, 2) AS UNSIGNED) >= 22') + ->orWhereRaw('CAST(SUBSTRING(bct.use_time, 1, 2) AS UNSIGNED) < 6'); }) ->selectRaw('COUNT(*) as count, COALESCE(SUM(ea.amount), 0) as total') ->first();