- {if condition="isset($resource.images) && !empty($resource.images)"}
- {if condition="strpos($resource.images, ',') !== false"}
- {volist name="resource.images|explode=',',true" id="image"}
-
-

-
-
+
+
+
+
+
+
+
-
-
-
-
-
-
-
-
-
@@ -796,4 +807,17 @@
margin-right: 4px;
/* 添加图标右边距 */
}
+
+ .form-container {
+ display: flex;
+
+ }
+
+ .container-left {
+ width: 35%;
+ }
+
+ .container-right {
+ width: 65%;
+ }
\ No newline at end of file
diff --git a/app/index/controller/ResourcesController.php b/app/index/controller/ResourcesController.php
new file mode 100644
index 0000000..95a8655
--- /dev/null
+++ b/app/index/controller/ResourcesController.php
@@ -0,0 +1,281 @@
+where('status', 1)
+ ->order('sort', 'asc')
+ ->select();
+
+ // 获取每个顶级分类下的子分类
+ $categories = [];
+ foreach ($parentCategories as $parent) {
+ $subCategories = ResourcesCategory::where('cid', $parent->id)
+ ->where('status', 1)
+ ->order('sort', 'asc')
+ ->select();
+
+ // 获取每个子分类下的资源数量
+ foreach ($subCategories as &$subCategory) {
+ $subCategory['resource_count'] = Resources::where('cate', $subCategory->id)
+ ->where('status', 1)
+ ->count();
+ }
+
+ $categories[] = [
+ 'parent' => $parent,
+ 'subCategories' => $subCategories
+ ];
+ }
+
+ // 将数据传递给视图
+ View::assign('categories', $categories);
+
+ return View::fetch();
+ }
+
+ // 游戏列表页
+ public function list()
+ {
+ $cid = input('cid/d', 0);
+ $page = input('page/d', 1);
+
+ // 获取分类信息
+ $category = ResourcesCategory::where('id', $cid)
+ ->where('status', 1)
+ ->find();
+
+ if (!$category) {
+ $this->error('分类不存在');
+ }
+
+ // 获取该分类下的资源,带分页
+ $resources = Resources::where('cate', $cid)
+ ->where('status', 1)
+ ->order('sort', 'asc')
+ ->paginate([
+ 'list_rows' => 20,
+ 'page' => $page,
+ 'query' => Request::instance()->param()
+ ]);
+
+ // 将数据传递给视图
+ View::assign('category', $category);
+ View::assign('data', $resources);
+
+ return View::fetch('list');
+ }
+
+ // 游戏详情页
+ public function detail()
+ {
+ $id = Request::param('id/d', 0);
+ $game = Resources::where('id', $id)->find();
+
+ if (!$game) {
+ return json(['code' => 0, 'msg' => '游戏不存在或已被删除']);
+ }
+
+ // 如果size没有,从附件表中获取
+ if (empty($game['size']) && !empty($game['fileurl'])) {
+ $attachment = Attachments::where('src', $game['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';
+ } elseif ($size >= 1048576) { // 1MB = 1024KB = 1024*1024B
+ $game['size'] = round($size / 1048576, 2) . 'MB';
+ } else {
+ $game['size'] = round($size / 1024, 2) . 'KB';
+ }
+ }
+ }
+
+ // 获取分类名称
+ $cateName = ResourcesCategory::where('id', $game['cate'])
+ ->value('name');
+
+ // 获取上一个和下一个游戏
+ $prevGame = Resources::where('id', '<', $id)
+ ->where('delete_time', null)
+ ->where('status', 1)
+ ->where('cate', $game['cate'])
+ ->field(['id', 'title'])
+ ->order('id DESC')
+ ->find();
+
+ $nextGame = Resources::where('id', '>', $id)
+ ->where('delete_time', null)
+ ->where('status', 1)
+ ->where('cate', $game['cate'])
+ ->field(['id', 'title'])
+ ->order('id ASC')
+ ->find();
+
+ // 获取相关游戏(同分类的其他游戏)
+ $relatedGames = Db::table('yz_resources')
+ ->alias('g')
+ ->join('yz_resources_category c', 'g.cate = c.id')
+ ->where('g.cate', $game['cate'])
+ ->where('g.id', '<>', $id)
+ ->where('g.delete_time', null)
+ ->where('g.status', 1)
+ ->field([
+ 'g.id',
+ 'g.title',
+ 'IF(g.icon IS NULL OR g.icon = "", c.icon, g.icon) as icon'
+ ])
+ ->order('g.id DESC')
+ ->limit(3)
+ ->select()
+ ->toArray();
+
+ // 如果是 AJAX 请求,返回 JSON 数据
+ if (Request::isAjax()) {
+ return json([
+ 'code' => 1,
+ 'msg' => '获取成功',
+ 'data' => [
+ 'game' => $game,
+ 'cateName' => $cateName,
+ 'prevGame' => $prevGame,
+ 'nextGame' => $nextGame,
+ 'relatedGames' => $relatedGames
+ ]
+ ]);
+ }
+
+ // 非 AJAX 请求返回视图
+ View::assign([
+ 'game' => $game,
+ 'cateName' => $cateName,
+ 'prevGame' => $prevGame,
+ 'nextGame' => $nextGame,
+ 'relatedGames' => $relatedGames
+ ]);
+
+ return View::fetch('detail');
+ }
+
+ // 游戏下载
+ public function downloadurl()
+ {
+ if (!Request::isAjax()) {
+ return json(['code' => 0, 'msg' => '非法请求']);
+ }
+
+ $id = Request::param('id/d', 0);
+
+ // 获取游戏信息
+ $game = Resources::where('id', $id)
+ ->where('delete_time', null)
+ ->find();
+
+ if (!$game) {
+ return json(['code' => 0, 'msg' => '游戏不存在']);
+ }
+
+ // 更新下载次数
+ $result = Resources::where('id', $id)
+ ->where('delete_time', null)
+ ->inc('downloads', 1)
+ ->update();
+
+ if ($result) {
+ return json([
+ 'code' => 1,
+ 'msg' => '下载成功',
+ 'data' => [
+ 'url' => $game['url']
+ ]
+ ]);
+ } else {
+ return json(['code' => 0, 'msg' => '下载失败']);
+ }
+ }
+
+ // 获取访问统计
+ public function viewStats()
+ {
+ $id = Request::param('id/d', 0);
+
+ // 获取总访问量
+ $totalViews = Resources::where('id', $id)
+ ->value('views');
+
+ return json([
+ 'code' => 1,
+ 'data' => [
+ 'total' => $totalViews
+ ]
+ ]);
+ }
+
+ /**
+ * 更新游戏访问次数
+ */
+ public function updateViews()
+ {
+ if (!Request::isPost()) {
+ return json(['code' => 0, 'msg' => '非法请求']);
+ }
+
+ $id = Request::post('id');
+ if (!$id) {
+ return json(['code' => 0, 'msg' => '参数错误']);
+ }
+
+ try {
+ // 更新访问次数
+ $game = Resources::where('id', $id)->find();
+ if (!$game) {
+ return json(['code' => 0, 'msg' => '游戏不存在']);
+ }
+
+ // 更新访问次数
+ Resources::where('id', $id)->inc('views')->update();
+
+ // 获取更新后的访问次数
+ $newViews = Resources::where('id', $id)->value('views');
+
+ return json(['code' => 1, 'msg' => '更新成功', 'data' => ['views' => $newViews]]);
+ } catch (\Exception $e) {
+ return json(['code' => 0, 'msg' => '更新失败:' . $e->getMessage()]);
+ }
+ }
+}
diff --git a/app/index/view/component/main.php b/app/index/view/component/main.php
index 9fae7fd..77c5980 100644
--- a/app/index/view/component/main.php
+++ b/app/index/view/component/main.php
@@ -14,7 +14,7 @@