From 6b32df536865c868fd513a85c5a9f10bac445519 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E5=BF=97=E5=BC=BA?= <357099073@qq.com> Date: Thu, 10 Jul 2025 11:32:20 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E5=89=8D=E7=AB=AF=E8=B5=84?= =?UTF-8?q?=E6=BA=90=E8=AF=A6=E6=83=85=E9=A1=B5=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/index/controller/ResourcesController.php | 105 +++--- app/index/view/articles/index.php | 145 +++++---- app/index/view/resources/detail.php | 321 +++++++++++++------ 3 files changed, 367 insertions(+), 204 deletions(-) diff --git a/app/index/controller/ResourcesController.php b/app/index/controller/ResourcesController.php index 2946474..cf2ab8a 100644 --- a/app/index/controller/ResourcesController.php +++ b/app/index/controller/ResourcesController.php @@ -17,7 +17,7 @@ */ /** - * 游戏下载控制器 + * 资源下载控制器 */ namespace app\index\controller; use app\index\controller\BaseController; @@ -27,6 +27,8 @@ use think\facade\Request; use app\index\model\Resources\Resources; use app\index\model\Resources\ResourcesCategory; use app\index\model\Attachments; +use app\index\model\Users; +use app\index\model\Articles\Articles; class ResourcesController extends BaseController { @@ -66,7 +68,7 @@ class ResourcesController extends BaseController return View::fetch(); } - // 游戏列表页 + // 资源列表页 public function list() { $cid = input('cid/d', 0); @@ -99,60 +101,84 @@ class ResourcesController extends BaseController return View::fetch('list'); } - // 游戏详情页 + // 资源详情页 public function detail() { $id = Request::param('id/d', 0); - $game = Resources::where('id', $id)->find(); + $resources = Resources::where('id', $id)->find(); - if (!$game) { - return json(['code' => 0, 'msg' => '游戏不存在或已被删除']); + if (!$resources) { + return json(['code' => 0, 'msg' => '资源不存在或已被删除']); } // 如果size没有,从附件表中获取 - if (empty($game['size']) && !empty($game['fileurl'])) { - $attachment = Attachments::where('src', $game['fileurl']) + if (empty($resources['size']) && !empty($resources['fileurl'])) { + $attachment = Attachments::where('src', $resources['fileurl']) ->find(); if ($attachment && !empty($attachment['size'])) { $size = $attachment['size']; // 转换文件大小为合适的单位 if ($size >= 1073741824) { // 1GB = 1024MB = 1024*1024KB = 1024*1024*1024B - $game['size'] = round($size / 1073741824, 2) . 'GB'; + $resources['size'] = round($size / 1073741824, 2) . 'GB'; } elseif ($size >= 1048576) { // 1MB = 1024KB = 1024*1024B - $game['size'] = round($size / 1048576, 2) . 'MB'; + $resources['size'] = round($size / 1048576, 2) . 'MB'; } else { - $game['size'] = round($size / 1024, 2) . 'KB'; + $resources['size'] = round($size / 1024, 2) . 'KB'; } } } // 获取分类名称 - $cateName = ResourcesCategory::where('id', $game['cate']) + $cateName = ResourcesCategory::where('id', $resources['cate']) ->value('name'); - // 获取上一个和下一个游戏 - $prevGame = Resources::where('id', '<', $id) + // 获取作者信息 + $authorInfo = Users::where('name', $resources['uploader'])->find(); + // var_dump($authorInfo); + if ($authorInfo) { + // 统计作者的文章数 + $resourcesCount = Articles::where('author', $resources['uploader'])->count(); + // 统计作者的资源数 + $resourceCount = Resources::where('uploader', $resources['uploader'])->count(); + + $authorData = [ + 'avatar' => $authorInfo['avatar'] ?: '/static/images/avatar.png', + 'name' => $authorInfo['name'], + 'resource_count' => $resourceCount, + 'article_count' => $resourcesCount + ]; + } else { + $authorData = [ + 'avatar' => '/static/images/avatar.png', + 'name' => $resources['author'], + 'resource_count' => 0, + 'article_count' => 0 + ]; + } + + // 获取上一个和下一个资源 + $prevResources = Resources::where('id', '<', $id) ->where('delete_time', null) ->where('status', 1) - ->where('cate', $game['cate']) + ->where('cate', $resources['cate']) ->field(['id', 'title']) ->order('id DESC') ->find(); - $nextGame = Resources::where('id', '>', $id) + $nextResources = Resources::where('id', '>', $id) ->where('delete_time', null) ->where('status', 1) - ->where('cate', $game['cate']) + ->where('cate', $resources['cate']) ->field(['id', 'title']) ->order('id ASC') ->find(); - // 获取相关游戏(同分类的其他游戏) - $relatedGames = Db::table('yz_resources') + // 获取相关资源(同分类的其他资源) + $relatedResourcess = Db::table('yz_resources') ->alias('g') ->join('yz_resources_category c', 'g.cate = c.id') - ->where('g.cate', $game['cate']) + ->where('g.cate', $resources['cate']) ->where('g.id', '<>', $id) ->where('g.delete_time', null) ->where('g.status', 1) @@ -162,7 +188,7 @@ class ResourcesController extends BaseController 'IF(g.icon IS NULL OR g.icon = "", c.icon, g.icon) as icon' ]) ->order('g.id DESC') - ->limit(3) + ->limit(5) ->select() ->toArray(); @@ -172,28 +198,29 @@ class ResourcesController extends BaseController 'code' => 1, 'msg' => '获取成功', 'data' => [ - 'game' => $game, + 'resources' => $resources, 'cateName' => $cateName, - 'prevGame' => $prevGame, - 'nextGame' => $nextGame, - 'relatedGames' => $relatedGames + 'prevResources' => $prevResources, + 'nextResources' => $nextResources, + 'relatedResourcess' => $relatedResourcess ] ]); } // 非 AJAX 请求返回视图 View::assign([ - 'game' => $game, + 'resources' => $resources, 'cateName' => $cateName, - 'prevGame' => $prevGame, - 'nextGame' => $nextGame, - 'relatedGames' => $relatedGames + 'authorInfo' => $authorData, + 'prevResources' => $prevResources, + 'nextResources' => $nextResources, + 'relatedResourcess' => $relatedResourcess ]); return View::fetch('detail'); } - // 游戏下载 + // 资源下载 public function downloadurl() { if (!Request::isAjax()) { @@ -202,13 +229,13 @@ class ResourcesController extends BaseController $id = Request::param('id/d', 0); - // 获取游戏信息 - $game = Resources::where('id', $id) + // 获取资源信息 + $resources = Resources::where('id', $id) ->where('delete_time', null) ->find(); - if (!$game) { - return json(['code' => 0, 'msg' => '游戏不存在']); + if (!$resources) { + return json(['code' => 0, 'msg' => '资源不存在']); } // 更新下载次数 @@ -222,7 +249,7 @@ class ResourcesController extends BaseController 'code' => 1, 'msg' => '下载成功', 'data' => [ - 'url' => $game['url'] + 'url' => $resources['url'] ] ]); } else { @@ -248,7 +275,7 @@ class ResourcesController extends BaseController } /** - * 更新游戏访问次数 + * 更新资源访问次数 */ public function updateViews() { @@ -263,9 +290,9 @@ class ResourcesController extends BaseController try { // 更新访问次数 - $game = Resources::where('id', $id)->find(); - if (!$game) { - return json(['code' => 0, 'msg' => '游戏不存在']); + $resources = Resources::where('id', $id)->find(); + if (!$resources) { + return json(['code' => 0, 'msg' => '资源不存在']); } // 更新访问次数 diff --git a/app/index/view/articles/index.php b/app/index/view/articles/index.php index 9ad61c3..d9086b3 100644 --- a/app/index/view/articles/index.php +++ b/app/index/view/articles/index.php @@ -23,7 +23,8 @@