From f5687bc4fe8ce5904d6d477b04ffe196b02a32ea Mon Sep 17 00:00:00 2001 From: Leonmmcoset Date: Fri, 11 Jul 2025 09:03:25 +0800 Subject: [PATCH] =?UTF-8?q?feat(=E5=BA=94=E7=94=A8=E5=B1=95=E7=A4=BA):=20?= =?UTF-8?q?=E5=9C=A8=E5=A4=9A=E4=B8=AA=E9=A1=B5=E9=9D=A2=E6=B7=BB=E5=8A=A0?= =?UTF-8?q?=E5=BA=94=E7=94=A8=E6=A0=87=E7=AD=BE=E5=92=8C=E5=B9=B3=E5=8F=B0?= =?UTF-8?q?=E4=BF=A1=E6=81=AF=E5=B1=95=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 在开发者应用、标签和应用列表页面中,添加了应用标签和平台信息的展示功能。修改了SQL查询以包含platforms字段,并添加了获取标签的查询逻辑,将信息显示在卡片组件中,提升用户体验。 --- developer_apps.php | 19 +++++++++++++++++++ index.php | 39 +++++++++++++++++++++++++++++++++++++-- tags.php | 24 ++++++++++++++++++++++-- 3 files changed, 78 insertions(+), 4 deletions(-) diff --git a/developer_apps.php b/developer_apps.php index f042b12..561685f 100644 --- a/developer_apps.php +++ b/developer_apps.php @@ -143,6 +143,25 @@ $resultApps = $conn->query($sqlApps);

...

+ prepare($tagSql); + $tagStmt->bind_param('i', $app['id']); + $tagStmt->execute(); + $tagResult = $tagStmt->get_result(); + $tags = []; + while ($tag = $tagResult->fetch_assoc()) { + $tags[] = htmlspecialchars($tag['name']); + } + $tagStmt->close(); + + // 获取应用适用平台 + $platforms = json_decode($app['platforms'], true); + + echo '

标签: '. implode(', ', $tags) . '

'; + echo '

平台: '. implode(', ', $platforms) . '

'; + ?>

评分: /5 diff --git a/index.php b/index.php index 6ca3deb..98ced7b 100644 --- a/index.php +++ b/index.php @@ -177,7 +177,7 @@ $announcement = $announcementResult && $announcementResult->num_rows > 0 ? $anno // 基于标签推荐应用 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 + $recommendSql = "SELECT a.id, a.name, a.description, a.age_rating, a.platforms, 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 @@ -213,6 +213,23 @@ $announcement = $announcementResult && $announcementResult->num_rows > 0 ? $anno echo '

'; echo '
'. htmlspecialchars($row['name']) . '
'; echo '

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

'; + // 获取应用标签 + $tagSql = "SELECT t.name FROM tags t JOIN app_tags at ON t.id = at.tag_id WHERE at.app_id = ?"; + $tagStmt = $conn->prepare($tagSql); + $tagStmt->bind_param('i', $row['id']); + $tagStmt->execute(); + $tagResult = $tagStmt->get_result(); + $tags = []; + while ($tag = $tagResult->fetch_assoc()) { + $tags[] = htmlspecialchars($tag['name']); + } + $tagStmt->close(); + + // 获取应用适用平台 + $platforms = json_decode($row['platforms'], true); + if (!is_array($platforms)) $platforms = []; + echo '

标签: '. implode(', ', $tags) . '

'; + echo '

平台: '. implode(', ', $platforms) . '

'; echo '

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

'; echo '查看详情'; echo ''; @@ -231,7 +248,7 @@ $announcement = $announcementResult && $announcementResult->num_rows > 0 ? $anno num_rows > 0 ? $anno echo '
'; echo '
'. $row['name'] . '
'; echo '

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

'; + + // 获取应用标签 + $tagSql = "SELECT t.name FROM tags t JOIN app_tags at ON t.id = at.tag_id WHERE at.app_id = ?"; + $tagStmt = $conn->prepare($tagSql); + $tagStmt->bind_param('i', $row['id']); + $tagStmt->execute(); + $tagResult = $tagStmt->get_result(); + $tags = []; + while ($tag = $tagResult->fetch_assoc()) { + $tags[] = htmlspecialchars($tag['name']); + } + $tagStmt->close(); + + // 获取应用适用平台 + $platforms = json_decode($row['platforms'], true); + if (!is_array($platforms)) $platforms = []; + echo '

标签: '. implode(', ', $tags) . '

'; + echo '

平台: '. implode(', ', $platforms) . '

'; echo '

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

'; echo '查看详情'; echo '
'; diff --git a/tags.php b/tags.php index 8e206e0..cd79ba0 100644 --- a/tags.php +++ b/tags.php @@ -11,7 +11,7 @@ $search = isset($_GET['search']) ? $_GET['search'] : ''; $limit = isset($_GET['limit']) ? intval($_GET['limit']) : 12; $offset = isset($_GET['page']) ? (intval($_GET['page']) - 1) * $limit : 0; -$sql = "SELECT apps.id, apps.name, apps.description, apps.age_rating, AVG(reviews.rating) as avg_rating +$sql = "SELECT apps.id, apps.name, apps.description, apps.age_rating, apps.platforms, AVG(reviews.rating) as avg_rating FROM apps LEFT JOIN reviews ON apps.id = reviews.app_id "; @@ -142,7 +142,27 @@ $tagResult = $conn->query("SELECT id, name FROM tags ORDER BY name");

...

-

评分: /5

+ prepare($tagSql); + $tagStmt->bind_param('i', $row['id']); + $tagStmt->execute(); + $tagResult = $tagStmt->get_result(); + $tags = []; + while ($tag = $tagResult->fetch_assoc()) { + $tags[] = htmlspecialchars($tag['name']); + } + $tagStmt->close(); + + // 获取应用适用平台 + $platforms = json_decode($row['platforms'], true); + echo ' 标签: '. implode(', ', $tags) . '
'; + $platforms = $platforms ?? []; + echo ' 平台: '. implode(', ', $platforms) . '
'; + echo ' 评分: '. round($row['avg_rating'], 1) . '/5
'; + echo ''; + ?> 查看详情