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.author}
- {$article.create_time|date='Y-m-d H:i'}
- {$cateName}
- {$article.views} 阅读
+
+
+ 阅读
-
- {$article.content|raw}
+
标签:
- {if !empty($article.tags)}
- {foreach $article.tags as $tag}
-
{$tag}
- {/foreach}
- {else}
-
暂无标签
- {/if}
+
点赞
- {$article.likes|default=0}
+ 0
@@ -51,77 +42,17 @@
-
- {if !empty($prevArticle)}
-
- 上一篇:{$prevArticle.title}
-
- {else}
-
没有上一篇了
- {/if}
+
-
- {if !empty($nextArticle)}
-
- 下一篇:{$nextArticle.title}
-
- {else}
-
没有下一篇了
- {/if}
+
@@ -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 @@
@@ -81,10 +81,10 @@
diff --git a/app/index/view/program/detail.php b/app/index/view/program/detail.php
new file mode 100644
index 0000000..d51ed64
--- /dev/null
+++ b/app/index/view/program/detail.php
@@ -0,0 +1,540 @@
+{include file="component/head" /}
+{include file="component/header-simple" /}
+
+
+
+
+
+
+
+
+
+
+
+ 软件大小:
+
+
+
+ 运行环境:
+
+
+
+ 更新时间:
+
+
+
+ 软件版本:
+
+
+
+
+
+
+
+ 立即下载
+
+
+
+ 分享
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+{include file="component/footer" /}
+
+
+
+
+{include file="component/foot" /}
\ No newline at end of file
diff --git a/config/route.php b/config/route.php
index 9032ffc..9568abe 100644
--- a/config/route.php
+++ b/config/route.php
@@ -1,37 +1,76 @@
// +----------------------------------------------------------------------
return [
// pathinfo分隔符
'pathinfo_depr' => '/',
- // URL伪静态后缀
- 'url_html_suffix' => '',
// URL普通方式参数 用于自动生成
- 'url_common_param' => true,
+ 'url_common_param' => true,
+ // URL参数方式 0 按名称成对解析 1 按顺序解析
+ 'url_param_type' => 0,
// 是否开启路由延迟解析
- 'url_lazy_route' => false,
+ 'lazy_route' => false,
// 是否强制使用路由
'url_route_must' => false,
// 合并路由规则
'route_rule_merge' => false,
// 路由是否完全匹配
- 'route_complete_match' => true,
- // 访问控制器层名称
- 'controller_layer' => 'controller',
- // 空控制器名
- 'empty_controller' => 'Error',
- // 是否使用控制器后缀
- 'controller_suffix' => false,
+ 'route_complete_match' => false,
+ // 使用注解路由
+ 'route_annotation' => false,
// 默认的路由变量规则
'default_route_pattern' => '[\w\.]+',
+ // URL中的控制器访问命名空间(自动多应用模式有效)
+ 'controller_namespace' => '',
+ // 是否自动转换URL中的控制器和操作名
+ 'url_convert' => true,
+ // 默认的访问控制器层
+ 'controller_layer' => 'controller',
+ // 表单请求类型伪装变量
+ 'var_method' => '_method',
+ // 表单ajax伪装变量
+ 'var_ajax' => '_ajax',
+ // 表单pjax伪装变量
+ 'var_pjax' => '_pjax',
// 是否开启请求缓存 true自动缓存 支持设置请求缓存规则
- 'request_cache_key' => false,
+ 'request_cache' => false,
// 请求缓存有效期
'request_cache_expire' => null,
// 全局请求缓存排除规则
'request_cache_except' => [],
+ // 是否开启路由缓存
+ 'route_check_cache' => false,
+ // 路由缓存的Key自定义设置(闭包),默认为当前URL和请求类型的md5
+ 'route_check_cache_key' => '',
+ // 路由缓存类型及参数
+ 'route_cache_option' => [],
+ // 默认跳转页面对应的模板文件
+ 'dispatch_success_tmpl' => app()->getThinkPath() . 'tpl/dispatch_jump.tpl',
+ 'dispatch_error_tmpl' => app()->getThinkPath() . 'tpl/dispatch_jump.tpl',
+ // 异常页面的模板文件
+ 'exception_tmpl' => app()->getThinkPath() . 'tpl/think_exception.tpl',
+ // 错误显示信息,非调试模式有效
+ 'error_message' => '页面错误!请稍后再试~',
+ // 显示错误信息
+ 'show_error_msg' => false,
+ // 异常处理handle类 留空使用 \think\exception\Handle
+ 'exception_handle' => '',
+ // 是否开启URL后缀
+ 'url_html_suffix' => false,
+ // 空控制器名
+ 'empty_controller' => 'Error',
+ // 是否使用控制器后缀
+ 'controller_suffix' => false,
+ // 访问控制器层名称
+ 'controller_layer' => 'controller',
// 默认控制器名
'default_controller' => 'Index',
// 默认操作名
diff --git a/public/static/css/style.css b/public/static/css/style.css
index 95c51df..dc7909a 100644
--- a/public/static/css/style.css
+++ b/public/static/css/style.css
@@ -17,6 +17,65 @@ a:hover {
color: #fff !important;
}
+/* 代码块样式 */
+pre {
+ background-color: #f8f9fa;
+ border-radius: 6px;
+ padding: 16px;
+ margin: 20px 0;
+ overflow: auto;
+ font-family: 'SFMono-Regular', Consolas, 'Liberation Mono', Menlo, monospace;
+ font-size: 14px;
+ line-height: 1.6;
+ color: #333;
+ border-left: 4px solid #0d6efd;
+ box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
+}
+
+pre code {
+ background-color: transparent;
+ padding: 0;
+ font-size: inherit;
+ color: inherit;
+ white-space: pre;
+ word-break: normal;
+}
+
+/* 代码块响应式样式 */
+@media (max-width: 768px) {
+ pre {
+ padding: 12px;
+ font-size: 13px;
+ }
+}
+
+/* 代码高亮样式 */
+.hljs-keyword,
+.hljs-selector-tag {
+ color: #d73a49;
+}
+
+.hljs-string,
+.hljs-attr {
+ color: #032f62;
+}
+
+.hljs-number,
+.hljs-literal {
+ color: #005cc5;
+}
+
+.hljs-comment {
+ color: #6a737d;
+ font-style: italic;
+}
+
+.hljs-function,
+.hljs-title {
+ color: #6f42c1;
+}
+
+
/* 字体大小类 */
.f20,
.f-20 {
@@ -164,6 +223,8 @@ a:hover {
position: relative;
}
+
+
.main-menu__list {
display: flex;
justify-content: center;
diff --git a/runtime/index/temp/402d23cdf323169a38fb26d3649b6ad5.php b/runtime/index/temp/402d23cdf323169a38fb26d3649b6ad5.php
new file mode 100644
index 0000000..257edb4
--- /dev/null
+++ b/runtime/index/temp/402d23cdf323169a38fb26d3649b6ad5.php
@@ -0,0 +1,1036 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ 软件大小:
+
+
+
+ 运行环境:
+
+
+
+ 更新时间:
+
+
+
+ 软件版本:
+
+
+
+
+
+
+
+ 立即下载
+
+
+
+ 分享
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
Copyright 2025 | All Rights By Yunzer
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/runtime/index/temp/69170ce622adbb0032543cdbee52d3fd.php b/runtime/index/temp/69170ce622adbb0032543cdbee52d3fd.php
index 4129efa..aed2823 100644
--- a/runtime/index/temp/69170ce622adbb0032543cdbee52d3fd.php
+++ b/runtime/index/temp/69170ce622adbb0032543cdbee52d3fd.php
@@ -1,4 +1,4 @@
-
+
@@ -50,10 +50,10 @@
@@ -99,10 +99,10 @@
diff --git a/runtime/index/temp/d407556bb15ad99658fbd9b0fbe4c5e4.php b/runtime/index/temp/d407556bb15ad99658fbd9b0fbe4c5e4.php
index 6b193e9..f8015ee 100644
--- a/runtime/index/temp/d407556bb15ad99658fbd9b0fbe4c5e4.php
+++ b/runtime/index/temp/d407556bb15ad99658fbd9b0fbe4c5e4.php
@@ -1,4 +1,4 @@
-
+
@@ -17,21 +17,28 @@
-
-
-
+
+
+
+
+
+
@@ -65,58 +92,320 @@
-
-
+
+
+
+
+
+
+
+
-
-
-
-
+
点赞
-
+ 0
@@ -179,73 +485,17 @@
-
-
-
- 上一篇:
-
-
-
没有上一篇了
-
+
-
-
-
- 下一篇:
-
-
-
没有下一篇了
-
+
@@ -259,7 +509,7 @@
-
+
美天智能科技,这里是介绍!
@@ -291,7 +541,7 @@
-
+
微信公众号
@@ -654,33 +904,159 @@
height: 36px;
}
}
+
+ .location-item a {
+ color: #000 !important;
+ }