getSeederCount('notification_logs', 50); $this->command->info('알림 발송 이력 시딩 시작...'); $channels = ['mail', 'database']; $types = [ ['type' => 'welcome', 'ext_type' => 'core', 'ext_id' => 'core'], ['type' => 'reset_password', 'ext_type' => 'core', 'ext_id' => 'core'], ['type' => 'password_changed', 'ext_type' => 'core', 'ext_id' => 'core'], ['type' => 'order_confirmed', 'ext_type' => 'module', 'ext_id' => 'sirsoft-ecommerce'], ['type' => 'order_shipped', 'ext_type' => 'module', 'ext_id' => 'sirsoft-ecommerce'], ['type' => 'new_comment', 'ext_type' => 'module', 'ext_id' => 'sirsoft-board'], ['type' => 'new_post_admin', 'ext_type' => 'module', 'ext_id' => 'sirsoft-board'], ]; $recipients = $this->getRecipients(); for ($i = 0; $i < $count; $i++) { $channel = $channels[array_rand($channels)]; $typeInfo = $types[array_rand($types)]; $recipient = $recipients[array_rand($recipients)]; $status = $this->randomStatus(); $sentAt = Carbon::now()->subDays(mt_rand(0, 30))->subHours(mt_rand(0, 23))->subMinutes(mt_rand(0, 59)); NotificationLog::create([ 'channel' => $channel, 'notification_type' => $typeInfo['type'], 'extension_type' => $typeInfo['ext_type'], 'extension_identifier' => $typeInfo['ext_id'], 'recipient_identifier' => $channel === 'mail' ? $recipient['email'] : (string) ($i + 1), 'recipient_name' => $recipient['name'], 'subject' => "[G7] {$typeInfo['type']} 알림", 'status' => $status->value, 'error_message' => $status === NotificationLogStatus::Failed ? 'SMTP connection refused' : null, 'source' => 'notification', 'sent_at' => $sentAt, ]); } $this->command->info("알림 발송 이력 시딩 완료 ({$count}건)"); } /** * 샘플 수신자 목록. * * @return array */ private function getRecipients(): array { return [ ['email' => 'hong@example.com', 'name' => '홍길동'], ['email' => 'kim@example.com', 'name' => '김철수'], ['email' => 'lee@example.com', 'name' => '이영희'], ['email' => 'park@example.com', 'name' => '박민수'], ['email' => 'john@example.com', 'name' => 'John Doe'], ['email' => 'jane@example.com', 'name' => 'Jane Smith'], ]; } /** * 가중치 기반 랜덤 상태. * * @return NotificationLogStatus */ private function randomStatus(): NotificationLogStatus { $rand = mt_rand(1, 100); if ($rand <= 80) { return NotificationLogStatus::Sent; } elseif ($rand <= 95) { return NotificationLogStatus::Failed; } return NotificationLogStatus::Skipped; } }