From acf9bc09522103636e15d514daf37f14bae2ae71 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, 25 Dec 2025 17:27:58 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E7=A8=8B=E5=BA=8F=E8=AF=A6?= =?UTF-8?q?=E6=83=85=E7=9B=B8=E5=85=B3=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/index/controller/ProgramController.php | 385 +++++++++++++++++- .../temp/f8995f34639557c9f17f79801bc58d25.php | 7 +- 2 files changed, 383 insertions(+), 9 deletions(-) diff --git a/app/index/controller/ProgramController.php b/app/index/controller/ProgramController.php index 547285e..2014f53 100644 --- a/app/index/controller/ProgramController.php +++ b/app/index/controller/ProgramController.php @@ -65,7 +65,7 @@ class ProgramController extends BaseController ]); } - // 获取officeResources内容,传参 + // 获取officeResources内容 public function getOfficeResourcesLists() { try { @@ -136,7 +136,112 @@ class ProgramController extends BaseController } // 格式化时间 - //$resource['create_time'] = date('Y-m-d H:i:s', strtotime($resource['create_time'])); + $resource['create_time'] = date('Y-m-d H:i:s', strtotime($resource['create_time'])); + + // 获取分类名称 + $resourceCategory = ResourcesCategory::where('id', $resource['cate'])->find(); + $resource['category_name'] = $resourceCategory ? $resourceCategory['name'] : ''; + } + + // 返回数据 + return json([ + 'code' => 0, + 'msg' => '获取成功', + 'data' => [ + 'category' => [ + 'id' => $category['id'], + 'name' => $category['name'], + 'desc' => $category['desc'], + 'image' => $category['image'] + ], + 'resources' => $resources, + 'total' => $total, + 'page' => $page, + 'limit' => $limit, + 'total_pages' => ceil($total / $limit) + ] + ]); + + } catch (\Exception $e) { + return json([ + 'code' => 1, + 'msg' => '获取失败:' . $e->getMessage() + ]); + } + } + + // 获取officeResources内容 + public function getOfficeResourcesSimpleLists() + { + try { + // 获取前端传递的分类ID + $cateid = input('cateid/d', 0); + + // 验证分类ID + if ($cateid <= 0) { + return json([ + 'code' => 1, + 'msg' => '分类ID不能为空' + ]); + } + + // 检查分类是否存在且有效 + $category = ResourcesCategory::where('id', $cateid) + ->where('delete_time', null) + ->where('status', 1) + ->find(); + + if (!$category) { + return json([ + 'code' => 1, + 'msg' => '分类不存在或已禁用' + ]); + } + + // 获取分页参数 + $page = input('page/d', 1); + $limit = input('limit/d', 10); + + // 获取该分类下的所有子分类ID(包括自身) + $subCategoryIds = [$cateid]; + + // 查找所有子分类 + $subCategories = ResourcesCategory::where('cid', $cateid) + ->where('delete_time', null) + ->where('status', 1) + ->column('id'); + + if (!empty($subCategories)) { + $subCategoryIds = array_merge($subCategoryIds, $subCategories); + } + + // 构建查询条件 + $where = [ + ['delete_time', '=', null], + ['status', '=', 1], // 已发布的文章 + ['cate', 'in', $subCategoryIds] + ]; + + // 查询文章总数 + $total = Resources::where($where)->count(); + + // 查询文章列表 + $resources = Resources::where($where) + ->field('id,title,cate,icon,views,downloads,create_time') + ->order('sort DESC, id DESC') + ->page($page, $limit) + ->select() + ->toArray(); + + // 处理文章数据 + foreach ($resources as &$resource) { + // 如果文章没有封面图,使用分类封面图 + if (empty($resource['icon'])) { + $resource['icon'] = $category['icon'] ?? ''; + } + + // 格式化时间 + $resource['create_time'] = date('Y-m-d H:i:s', strtotime($resource['create_time'])); // 获取分类名称 $resourceCategory = ResourcesCategory::where('id', $resource['cate'])->find(); @@ -202,7 +307,7 @@ class ProgramController extends BaseController ]); } - // 获取downloadPrograms内容,传参 + // 获取downloadPrograms内容 public function getDownloadProgramsLists() { try { @@ -273,7 +378,7 @@ class ProgramController extends BaseController } // 格式化时间 - //$resource['create_time'] = date('Y-m-d H:i:s', strtotime($resource['create_time'])); + $resource['create_time'] = date('Y-m-d H:i:s', strtotime($resource['create_time'])); // 获取分类名称 $resourceCategory = ResourcesCategory::where('id', $resource['cate'])->find(); @@ -307,6 +412,169 @@ class ProgramController extends BaseController } } + // 获取downloadPrograms内容 + public function getDownloadProgramsSimpleLists() + { + try { + // 获取前端传递的分类ID + $cateid = input('cateid/d', 0); + + // 验证分类ID + if ($cateid <= 0) { + return json([ + 'code' => 1, + 'msg' => '分类ID不能为空' + ]); + } + + // 检查分类是否存在且有效 + $category = ResourcesCategory::where('id', $cateid) + ->where('delete_time', null) + ->where('status', 1) + ->find(); + + if (!$category) { + return json([ + 'code' => 1, + 'msg' => '分类不存在或已禁用' + ]); + } + + // 获取分页参数 + $page = input('page/d', 1); + $limit = input('limit/d', 10); + + // 获取该分类下的所有子分类ID(包括自身) + $subCategoryIds = [$cateid]; + + // 查找所有子分类 + $subCategories = ResourcesCategory::where('cid', $cateid) + ->where('delete_time', null) + ->where('status', 1) + ->column('id'); + + if (!empty($subCategories)) { + $subCategoryIds = array_merge($subCategoryIds, $subCategories); + } + + // 构建查询条件 + $where = [ + ['delete_time', '=', null], + ['status', '=', 1], // 已发布的文章 + ['cate', 'in', $subCategoryIds] + ]; + + // 查询文章总数 + $total = Resources::where($where)->count(); + + // 查询文章列表 + $resources = Resources::where($where) + ->field('id,title,cate,icon,views,downloads,create_time') + ->order('sort DESC, id DESC') + ->page($page, $limit) + ->select() + ->toArray(); + + // 处理文章数据 + foreach ($resources as &$resource) { + // 如果文章没有封面图,使用分类封面图 + if (empty($resource['icon'])) { + $resource['icon'] = $category['icon'] ?? ''; + } + + // 格式化时间 + $resource['create_time'] = date('Y-m-d H:i:s', strtotime($resource['create_time'])); + + // 获取分类名称 + $resourceCategory = ResourcesCategory::where('id', $resource['cate'])->find(); + $resource['category_name'] = $resourceCategory ? $resourceCategory['name'] : ''; + } + + // 返回数据 + return json([ + 'code' => 0, + 'msg' => '获取成功', + 'data' => [ + 'category' => [ + 'id' => $category['id'], + 'name' => $category['name'], + 'image' => $category['image'] + ], + 'resources' => $resources, + 'total' => $total, + 'page' => $page, + 'limit' => $limit, + 'total_pages' => ceil($total / $limit) + ] + ]); + + } catch (\Exception $e) { + return json([ + 'code' => 1, + 'msg' => '获取失败:' . $e->getMessage() + ]); + } + } + + // 获取downloadPrograms详情 + public function getDownloadProgramsDetail() + { + try { + // 获取前端传递的ID + $id = input('id/d', 0); + + // 验证ID + if ($id <= 0) { + return json([ + 'code' => 1, + 'msg' => 'ID参数错误' + ]); + } + + // 构建查询条件 + $where = [ + ['r.id', '=', $id], + ['r.delete_time', '=', null], + ['r.status', '=', 1], // 已审核的资源 + ['r.push', '=', 1], // 已推送的资源 + ]; + + // 查询资源详情,联查分类名称 + $resource = Resources::where($where) + ->field('r.id,r.title,r.cate,r.icon,r.price,r.code,r.desc,r.number,r.content,r.views,r.downloads,r.create_time,r.update_time,r.url,r.fileurl,c.name as cate_name') + ->alias('r') + ->join('resources_category c', 'r.cate = c.id') + ->find(); + + if (!$resource) { + return json([ + 'code' => 1, + 'msg' => '资源不存在或已删除' + ]); + } + + // 转换为数组并处理数据 + $resource = $resource->toArray(); + + // 将cate字段替换为分类名称 + $resource['cate'] = $resource['cate_name']; + unset($resource['cate_name']); + + // 返回数据 + return json([ + 'code' => 0, + 'msg' => '获取成功', + 'data' => $resource + ]); + + } catch (\Exception $e) { + return json([ + 'code' => 1, + 'msg' => '获取失败:' . $e->getMessage() + ]); + } + } + // 获取downloadGames分类 public function getDownloadGamesCategory() { @@ -339,7 +607,7 @@ class ProgramController extends BaseController ]); } - // 获取downloadGames内容,传参 + // 获取downloadGames内容 public function getDownloadGamesLists() { try { @@ -410,7 +678,112 @@ class ProgramController extends BaseController } // 格式化时间 - //$resource['create_time'] = date('Y-m-d H:i:s', strtotime($resource['create_time'])); + $resource['create_time'] = date('Y-m-d H:i:s', strtotime($resource['create_time'])); + + // 获取分类名称 + $resourceCategory = ResourcesCategory::where('id', $resource['cate'])->find(); + $resource['category_name'] = $resourceCategory ? $resourceCategory['name'] : ''; + } + + // 返回数据 + return json([ + 'code' => 0, + 'msg' => '获取成功', + 'data' => [ + 'category' => [ + 'id' => $category['id'], + 'name' => $category['name'], + 'desc' => $category['desc'], + 'image' => $category['image'] + ], + 'resources' => $resources, + 'total' => $total, + 'page' => $page, + 'limit' => $limit, + 'total_pages' => ceil($total / $limit) + ] + ]); + + } catch (\Exception $e) { + return json([ + 'code' => 1, + 'msg' => '获取失败:' . $e->getMessage() + ]); + } + } + + // 获取downloadGames内容 + public function getDownloadGamesSimpleLists() + { + try { + // 获取前端传递的分类ID + $cateid = input('cateid/d', 0); + + // 验证分类ID + if ($cateid <= 0) { + return json([ + 'code' => 1, + 'msg' => '分类ID不能为空' + ]); + } + + // 检查分类是否存在且有效 + $category = ResourcesCategory::where('id', $cateid) + ->where('delete_time', null) + ->where('status', 1) + ->find(); + + if (!$category) { + return json([ + 'code' => 1, + 'msg' => '分类不存在或已禁用' + ]); + } + + // 获取分页参数 + $page = input('page/d', 1); + $limit = input('limit/d', 10); + + // 获取该分类下的所有子分类ID(包括自身) + $subCategoryIds = [$cateid]; + + // 查找所有子分类 + $subCategories = ResourcesCategory::where('cid', $cateid) + ->where('delete_time', null) + ->where('status', 1) + ->column('id'); + + if (!empty($subCategories)) { + $subCategoryIds = array_merge($subCategoryIds, $subCategories); + } + + // 构建查询条件 + $where = [ + ['delete_time', '=', null], + ['status', '=', 1], // 已发布的文章 + ['cate', 'in', $subCategoryIds] + ]; + + // 查询文章总数 + $total = Resources::where($where)->count(); + + // 查询文章列表 + $resources = Resources::where($where) + ->field('id,title,cate,icon,views,downloads,create_time') + ->order('sort DESC, id DESC') + ->page($page, $limit) + ->select() + ->toArray(); + + // 处理文章数据 + foreach ($resources as &$resource) { + // 如果文章没有封面图,使用分类封面图 + if (empty($resource['icon'])) { + $resource['icon'] = $category['icon'] ?? ''; + } + + // 格式化时间 + $resource['create_time'] = date('Y-m-d H:i:s', strtotime($resource['create_time'])); // 获取分类名称 $resourceCategory = ResourcesCategory::where('id', $resource['cate'])->find(); diff --git a/runtime/index/temp/f8995f34639557c9f17f79801bc58d25.php b/runtime/index/temp/f8995f34639557c9f17f79801bc58d25.php index 26e7e27..4a45f48 100644 --- a/runtime/index/temp/f8995f34639557c9f17f79801bc58d25.php +++ b/runtime/index/temp/f8995f34639557c9f17f79801bc58d25.php @@ -1,4 +1,4 @@ - + @@ -10,8 +10,10 @@ + + @@ -1716,8 +1718,7 @@ $loginStatus = [ .disclaimers { color: #b1b1b1; - width: 80%; - margin: 20px auto; + margin: 20px 0; margin-bottom: 60px; }