where('tenant_id', $tenantId) ->pluck('user_id') ->toArray(); if (empty($userIds)) { $this->command->warn(' ⚠ leave_grants: 사용자가 없습니다'); return; } $year = 2025; $count = 0; // 각 사용자별 연차/월차 부여 foreach ($userIds as $uId) { // 연차 부여 (1월 1일) $existing = LeaveGrant::where('tenant_id', $tenantId) ->where('user_id', $uId) ->where('grant_type', 'annual') ->whereYear('grant_date', $year) ->exists(); if (! $existing) { LeaveGrant::create([ 'tenant_id' => $tenantId, 'user_id' => $uId, 'grant_type' => 'annual', 'grant_date' => sprintf('%04d-01-01', $year), 'grant_days' => rand(12, 20), // 12~20일 'reason' => sprintf('%d년 연차 부여', $year), 'created_by' => $userId, ]); $count++; } // 월차 부여 (월별, 12건) for ($month = 1; $month <= 12; $month++) { $grantDate = sprintf('%04d-%02d-01', $year, $month); $monthlyExists = LeaveGrant::where('tenant_id', $tenantId) ->where('user_id', $uId) ->where('grant_type', 'monthly') ->where('grant_date', $grantDate) ->exists(); if (! $monthlyExists) { LeaveGrant::create([ 'tenant_id' => $tenantId, 'user_id' => $uId, 'grant_type' => 'monthly', 'grant_date' => $grantDate, 'grant_days' => 1, 'reason' => sprintf('%d년 %d월 월차', $year, $month), 'created_by' => $userId, ]); $count++; } } // 포상 휴가 (일부 사용자에게 랜덤) if (rand(1, 5) === 1) { // 20% 확률 $rewardMonth = rand(3, 11); LeaveGrant::create([ 'tenant_id' => $tenantId, 'user_id' => $uId, 'grant_type' => 'reward', 'grant_date' => sprintf('%04d-%02d-15', $year, $rewardMonth), 'grant_days' => rand(1, 3), 'reason' => '우수 사원 포상 휴가', 'created_by' => $userId, ]); $count++; } } $this->command->info(' ✓ leave_grants: '.$count.'건 생성'); } }