query($announcementQuery); $announcement = $announcementResult && $announcementResult->num_rows > 0 ? $announcementResult->fetch_assoc() : null; ?>

为你推荐

prepare($tagSql); $tagStmt->bind_param('i', $userId); $tagStmt->execute(); $tagResult = $tagStmt->get_result(); $tagIds = []; while ($tag = $tagResult->fetch_assoc()) { $tagIds[] = $tag['id']; } $tagStmt->close(); // 获取用户已下载的应用 $downloadedSql = "SELECT DISTINCT a.id FROM apps a JOIN app_versions av ON a.id = av.app_id JOIN download_history dh ON av.id = dh.version_id WHERE dh.user_id = ?"; $downloadedStmt = $conn->prepare($downloadedSql); $downloadedStmt->bind_param('i', $userId); $downloadedStmt->execute(); $downloadedResult = $downloadedStmt->get_result(); $downloadedIds = []; while ($app = $downloadedResult->fetch_assoc()) { $downloadedIds[] = $app['id']; } $downloadedStmt->close(); // 基于标签推荐应用 if (!empty($tagIds)) { $placeholders = implode(',', array_fill(0, count($tagIds), '?')); $recommendSql = "SELECT a.id, a.name, a.description, a.age_rating, AVG(r.rating) as avg_rating FROM apps a LEFT JOIN reviews r ON a.id = r.app_id JOIN app_tags at ON a.id = at.app_id WHERE at.tag_id IN ($placeholders) AND a.id NOT IN (" . (!empty($downloadedIds) ? implode(',', $downloadedIds) : '0') . ") AND a.status = 'approved' GROUP BY a.id ORDER BY COUNT(at.tag_id) DESC LIMIT 12"; $recommendStmt = $conn->prepare($recommendSql); $types = str_repeat('i', count($tagIds)); $recommendStmt->bind_param($types, ...$tagIds); $recommendStmt->execute(); $recommendResult = $recommendStmt->get_result(); } else { // 如果没有标签数据,显示热门应用 $recommendSql = "SELECT a.id, a.name, a.description, a.age_rating, AVG(r.rating) as avg_rating, SUM(av.download_count) as total_downloads FROM apps a LEFT JOIN reviews r ON a.id = r.app_id LEFT JOIN app_versions av ON a.id = av.app_id WHERE a.status = 'approved' GROUP BY a.id ORDER BY total_downloads DESC LIMIT 12"; $recommendResult = $conn->query($recommendSql); } if ($recommendResult && $recommendResult->num_rows > 0) { while ($row = $recommendResult->fetch_assoc()) { echo '
'; echo '
'; echo '
'; echo '
'. htmlspecialchars($row['name']) . '
'; echo '

'. substr(htmlspecialchars($row['description']), 0, 100) . '...

'; echo '

评分: '. round($row['avg_rating'] ?? 0, 1) . '/5

'; echo '查看详情'; echo ''; echo '
'; } } else { echo '

暂无推荐内容

'; } if (isset($recommendStmt)) $recommendStmt->close(); ?>

最新应用

prepare($sql); if (!$stmt) { die('预处理语句失败: ' . $conn->error); } call_user_func_array([$stmt, 'bind_param'], array_merge([$paramTypes], $params)); if (!$stmt->execute()) { die('执行语句失败: ' . $stmt->error); } $result = $stmt->get_result(); } else { $result = $conn->query($sql); if (!$result) { die('查询失败: ' . $conn->error); } } if ($result->num_rows > 0) { while ($row = $result->fetch_assoc()) { echo '
'; echo '
'; echo '
'; echo '
'. $row['name'] . '
'; echo '

'. substr($row['description'], 0, 100) . '...

'; echo '

评分: '. round($row['avg_rating'], 1) . '/5

'; echo '查看详情'; echo '
'; echo '
'; echo '
'; } } ?>