From 4c6f7277b012fc52dcfb391938ffe81d99ecae12 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BA=91=E6=B3=BD=E7=BD=91?= <”357099073@qq.com“> Date: Sat, 17 May 2025 01:38:45 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0program=E8=AF=A6=E6=83=85?= =?UTF-8?q?=E9=A1=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/index/controller/Article.php | 87 +- app/index/controller/Program.php | 233 ++++ app/index/view/article/detail.php | 281 +++-- app/index/view/component/header-simple.php | 417 ++++++- app/index/view/component/header.php | 16 +- app/index/view/program/detail.php | 540 +++++++++ config/route.php | 65 +- public/static/css/style.css | 61 + .../temp/402d23cdf323169a38fb26d3649b6ad5.php | 1036 +++++++++++++++++ .../temp/69170ce622adbb0032543cdbee52d3fd.php | 18 +- .../temp/d407556bb15ad99658fbd9b0fbe4c5e4.php | 698 ++++++++--- 11 files changed, 3101 insertions(+), 351 deletions(-) create mode 100644 app/index/controller/Program.php create mode 100644 app/index/view/program/detail.php create mode 100644 runtime/index/temp/402d23cdf323169a38fb26d3649b6ad5.php diff --git a/app/index/controller/Article.php b/app/index/controller/Article.php index ac6e0ac..b629ad8 100644 --- a/app/index/controller/Article.php +++ b/app/index/controller/Article.php @@ -94,38 +94,48 @@ class Article extends Base // 获取相关文章(同分类的其他文章) $relatedArticles = Db::table('yz_article') - ->where('cate', $article['cate']) - ->where('id', '<>', $id) - ->where('delete_time', null) - ->where('status', '<>', 3) - ->order('id DESC') + ->alias('a') + ->join('yz_article_category c', 'a.cate = c.id') + ->where('a.cate', $article['cate']) + ->where('a.id', '<>', $id) + ->where('a.delete_time', null) + ->where('a.status', '=', 2) + ->field([ + 'a.id', + 'a.title', + 'a.desc', + 'IF(a.image IS NULL OR a.image = "", c.image, a.image) as image' + ]) + ->order('a.id DESC') ->limit(3) ->select() ->toArray(); + + // 如果是 AJAX 请求,返回 JSON 数据 + if (Request::isAjax()) { + return json([ + 'code' => 1, + 'msg' => '获取成功', + 'data' => [ + 'article' => $article, + 'cateName' => $cateName, + 'prevArticle' => $prevArticle, + 'nextArticle' => $nextArticle, + 'relatedArticles' => $relatedArticles + ] + ]); + } - // 获取评论列表 - // $comments = Db::table('yz_article_comment') - // ->where('article_id', $id) - // ->where('delete_time', null) - // ->order('id DESC') - // ->select() - // ->toArray(); - - // 更新浏览量(使用Cookie和IP双重验证) - $ip = Request::ip(); - $cookieKey = 'article_view_' . $id; - $viewCookie = Request::cookie($cookieKey); - + // 非 AJAX 请求返回视图 View::assign([ 'article' => $article, 'cateName' => $cateName, 'prevArticle' => $prevArticle, 'nextArticle' => $nextArticle, - 'relatedArticles' => $relatedArticles, - // 'comments' => $comments + 'relatedArticles' => $relatedArticles ]); - - return View::fetch(); + + return view('detail'); } // 文章点赞 @@ -229,4 +239,37 @@ class Article extends Base ] ]); } + + /** + * 更新文章访问次数 + */ + public function updateViews() + { + if (!Request::isPost()) { + return json(['code' => 0, 'msg' => '非法请求']); + } + + $id = Request::post('id'); + if (!$id) { + return json(['code' => 0, 'msg' => '参数错误']); + } + + try { + // 更新访问次数 + $article = Db::table('yz_article')->where('id', $id)->find(); + if (!$article) { + return json(['code' => 0, 'msg' => '文章不存在']); + } + + // 更新访问次数 + Db::table('yz_article')->where('id', $id)->inc('views')->update(); + + // 获取更新后的访问次数 + $newViews = Db::table('yz_article')->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/controller/Program.php b/app/index/controller/Program.php new file mode 100644 index 0000000..7bd1825 --- /dev/null +++ b/app/index/controller/Program.php @@ -0,0 +1,233 @@ + 0) { + $where[] = ['cate', '=', $cateId]; + } + + // 获取程序列表 + $programs = Db::table('yz_resources') + ->where($where) + ->order('id DESC') + ->paginate([ + 'list_rows' => 10, + 'query' => Request::instance()->param() + ]); + + // 获取分类信息 + $category = null; + if ($cateId > 0) { + $category = Db::table('yz_resources_category') + ->where('id', $cateId) + ->where('delete_time', null) + ->where('status', 1) + ->find(); + } + + // 获取所有分类 + $categories = Db::table('yz_resources_category') + ->where('delete_time', null) + ->where('status', 1) + ->select() + ->toArray(); + + // 将变量传递给视图 + View::assign([ + 'programs' => $programs, + 'category' => $category, + 'categories' => $categories + ]); + + return view('list'); + } + + // 程序详情页 + public function detail() + { + $id = Request::param('id/d', 0); + $program = Db::table('yz_resources')->where('id', $id)->find(); + + // 如果size没有,从附件表中获取 + if (empty($program['size']) && !empty($program['fileurl'])) { + $attachment = Db::table('yz_attachments') + ->where('src', $program['fileurl']) + ->find(); + + if ($attachment && !empty($attachment['size'])) { + $size = $attachment['size']; + // 转换文件大小为合适的单位 + if ($size >= 1073741824) { // 1GB = 1024MB = 1024*1024KB = 1024*1024*1024B + $program['size'] = round($size / 1073741824, 2) . 'GB'; + } elseif ($size >= 1048576) { // 1MB = 1024KB = 1024*1024B + $program['size'] = round($size / 1048576, 2) . 'MB'; + } else { + $program['size'] = round($size / 1024, 2) . 'KB'; + } + } + } + + if (!$program) { + return json(['code' => 0, 'msg' => '程序不存在或已被删除']); + } + + // 获取分类名称 + $cateName = Db::table('yz_resources_category') + ->where('id', $program['cate']) + ->value('name'); + + // 获取上一个和下一个程序 + $prevProgram = Db::table('yz_resources') + ->where('id', '<', $id) + ->where('delete_time', null) + ->where('status', 1) + ->order('id DESC') + ->find(); + + $nextProgram = Db::table('yz_resources') + ->where('id', '>', $id) + ->where('delete_time', null) + ->where('status', 1) + ->order('id ASC') + ->find(); + + // 获取相关程序(同分类的其他程序) + $relatedPrograms = Db::table('yz_resources') + ->alias('p') + ->join('yz_resources_category c', 'p.cate = c.id') + ->where('p.cate', $program['cate']) + ->where('p.id', '<>', $id) + ->where('p.delete_time', null) + ->where('p.status', 1) + ->field([ + 'p.id', + 'p.title', + 'p.desc', + 'IF(p.icon IS NULL OR p.icon = "", c.icon, p.icon) as icon' + ]) + ->order('p.id DESC') + ->limit(3) + ->select() + ->toArray(); + + // 如果是 AJAX 请求,返回 JSON 数据 + if (Request::isAjax()) { + return json([ + 'code' => 1, + 'msg' => '获取成功', + 'data' => [ + 'program' => $program, + 'cateName' => $cateName, + 'prevProgram' => $prevProgram, + 'nextProgram' => $nextProgram, + 'relatedPrograms' => $relatedPrograms + ] + ]); + } + + // 非 AJAX 请求返回视图 + View::assign([ + 'program' => $program, + 'cateName' => $cateName, + 'prevProgram' => $prevProgram, + 'nextProgram' => $nextProgram, + 'relatedPrograms' => $relatedPrograms + ]); + + return view('detail'); + } + + // 程序下载 + public function download() + { + if (!Request::isAjax()) { + return json(['code' => 0, 'msg' => '非法请求']); + } + + $id = Request::param('id/d', 0); + + // 更新下载次数 + $result = Db::table('yz_resources') + ->where('id', $id) + ->where('delete_time', null) + ->inc('downloads', 1) + ->update(); + + if ($result) { + return json(['code' => 1, 'msg' => '下载成功']); + } else { + return json(['code' => 0, 'msg' => '下载失败']); + } + } + + // 获取访问统计 + public function viewStats() + { + $id = Request::param('id/d', 0); + + // 获取总访问量 + $totalViews = Db::table('yz_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 { + // 更新访问次数 + $program = Db::table('yz_resources')->where('id', $id)->find(); + if (!$program) { + return json(['code' => 0, 'msg' => '程序不存在']); + } + + // 更新访问次数 + Db::table('yz_resources')->where('id', $id)->inc('views')->update(); + + // 获取更新后的访问次数 + $newViews = Db::table('yz_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/article/detail.php b/app/index/view/article/detail.php index 551827f..c2c283c 100644 --- a/app/index/view/article/detail.php +++ b/app/index/view/article/detail.php @@ -4,45 +4,36 @@
-
-

{$article.title}

+

-
- {$article.content|raw} +
- @@ -479,33 +410,159 @@ height: 36px; } } + + .location-item a { + color: #000 !important; + } {include file="component/foot" /} \ No newline at end of file diff --git a/app/index/view/component/header-simple.php b/app/index/view/component/header-simple.php index 3b236d1..49a4e85 100644 --- a/app/index/view/component/header-simple.php +++ b/app/index/view/component/header-simple.php @@ -1,19 +1,26 @@
-
@@ -47,58 +74,320 @@
- \ No newline at end of file diff --git a/app/index/view/component/header.php b/app/index/view/component/header.php index 9cf56fe..96e1494 100644 --- a/app/index/view/component/header.php +++ b/app/index/view/component/header.php @@ -32,10 +32,10 @@ @@ -65,58 +92,320 @@ -
-
-

+

-
- +
- @@ -259,7 +509,7 @@
- +

美天智能科技,这里是介绍!

@@ -291,7 +541,7 @@
- 微信二维码 + 微信二维码

微信公众号

@@ -654,33 +904,159 @@ height: 36px; } } + + .location-item a { + color: #000 !important; + }