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();