argument('user_id'); $this->info("=== 用户日志清理逻辑测试 ==="); $this->newLine(); // 1. 查看用户当前的日志数量 $this->info("1. 查看用户 {$testUserId} 当前可见的日志数量:"); $logs = UserLogService::getUserLogs($testUserId, 1, 10); $this->line(" 可见日志总数: {$logs->total()}"); $this->line(" 当前页日志数: {$logs->count()}"); $this->newLine(); // 2. 查看用户的清理记录 $this->info("2. 查看用户的清理记录:"); $clearRecord = UserLogClearRecord::getUserLastClearTime($testUserId); if ($clearRecord) { $this->line(" 最后清理时间: {$clearRecord->toDateTimeString()}"); } else { $this->line(" 无清理记录"); } $this->newLine(); // 3. 执行清理操作 $this->info("3. 执行清理操作:"); $success = UserLogService::clearUserLogs($testUserId); if ($success) { $this->line(" 清理成功"); } else { $this->line(" 清理失败"); } $this->newLine(); // 4. 查看清理后的日志数量 $this->info("4. 查看清理后的日志数量:"); $logsAfterClear = UserLogService::getUserLogs($testUserId, 1, 10); $this->line(" 可见日志总数: {$logsAfterClear->total()}"); $this->line(" 当前页日志数: {$logsAfterClear->count()}"); $this->newLine(); // 5. 查看新的清理记录 $this->info("5. 查看新的清理记录:"); $newClearRecord = UserLogClearRecord::getUserLastClearTime($testUserId); if ($newClearRecord) { $this->line(" 最后清理时间: {$newClearRecord->toDateTimeString()}"); } else { $this->line(" 无清理记录"); } $this->newLine(); // 6. 验证数据库中的实际日志数量没有减少 $this->info("6. 验证数据库中的实际日志数量:"); $totalLogsInDb = UserLog::byUser($testUserId)->count(); $this->line(" 数据库中实际日志总数: {$totalLogsInDb}"); $this->line(" 说明: 实际日志没有被删除,只是逻辑上被隐藏"); $this->newLine(); $this->info("=== 测试完成 ==="); return 0; } }