From c491923d385c6362b048bc83788353eb479b54b4 Mon Sep 17 00:00:00 2001 From: muzi_ys <1099438829@qq.com> Date: Sun, 10 Jul 2022 00:01:52 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=AD=A3=E5=AE=8C=E5=96=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .example.env | 2 +- app/admin/common.php | 18 +++ app/admin/controller/Advert.php | 6 +- app/admin/controller/Article.php | 108 +++----------- app/admin/controller/Category.php | 26 +--- app/admin/controller/Databases.php | 14 +- app/admin/controller/FriendLink.php | 6 +- app/admin/controller/Invitation.php | 10 +- app/admin/controller/Message.php | 6 +- app/admin/controller/Nav.php | 7 +- app/admin/controller/Page.php | 139 ++++--------------- app/admin/controller/Theme.php | 6 +- app/admin/controller/User.php | 2 +- app/admin/view/page/add.html | 2 +- app/admin/view/page/edit.html | 5 +- app/api/controller/Index.php | 4 +- app/common.php | 4 +- app/common/constant/Data.php | 2 +- app/common/extend/Mail.php | 2 +- app/common/model/AdminAuth.php | 4 +- app/common/model/Advert.php | 4 +- app/common/model/Comment.php | 4 +- app/common/model/Document.php | 123 +++++++++++++++- app/common/model/DocumentArticle.php | 17 +-- app/common/model/DocumentCategory.php | 4 +- app/common/model/DocumentCategoryContent.php | 38 ----- app/common/model/DocumentPage.php | 18 +-- app/common/model/DocumentProduct.php | 4 +- app/common/model/FriendLink.php | 4 +- app/common/model/InvitationCode.php | 4 +- app/common/model/MessageForm.php | 4 +- app/common/model/Nav.php | 78 +---------- app/common/model/SystemConfigTab.php | 2 +- app/common/model/Tag.php | 8 +- app/common/model/User.php | 8 +- app/common/taglib/Ape.php | 6 +- app/index/common.php | 24 ++-- app/index/controller/Article.php | 12 +- app/index/controller/Base.php | 2 +- app/index/controller/Index.php | 64 +-------- app/index/controller/Page.php | 74 +++++++++- app/index/controller/User.php | 4 +- 42 files changed, 347 insertions(+), 532 deletions(-) delete mode 100644 app/common/model/DocumentCategoryContent.php diff --git a/.example.env b/.example.env index c0ed44a..82b23b1 100644 --- a/.example.env +++ b/.example.env @@ -1 +1 @@ -APP_DEBUG = true [APP] CDN = http://apeblog.io/ DEFAULT_TIMEZONE = Asia/Shanghai [DATABASE] TYPE = mysql HOSTNAME = 127.0.0.1 DATABASE = test USERNAME = username PASSWORD = password HOSTPORT = 3306 CHARSET = utf8 DEBUG = true [LANG] default_lang = zh-cn \ No newline at end of file +APP_DEBUG = true [APP] CDN = http://apeblog.io/ DEFAULT_TIMEZONE = Asia/Shanghai [DATABASE] TYPE = mysql HOSTNAME = 127.0.0.1 DATABASE = test USERNAME = username PASSWORD = password HOSTPORT = 3306 CHARSET = utf8 DEBUG = true [LANG] default_lang = zh-cn [FILESYSTEM] DRIVER=public \ No newline at end of file diff --git a/app/admin/common.php b/app/admin/common.php index c9ddaa1..3451c63 100644 --- a/app/admin/common.php +++ b/app/admin/common.php @@ -143,3 +143,21 @@ if (!function_exists('get_tree_list')) { } } + +if (!function_exists('get_theme_list')) { + function get_theme_list($type = ''):array + { + $themeList = []; + $themeDir = public_path('template') . system_config('web_template') . '/pc/' .$type; + if ($dh = opendir($themeDir)) { + while (($file = readdir($dh)) !== false) { + + if ($file != "." && $file != "..") { + $themeList[] = $file; + } + } + closedir($dh); + } + return $themeList; + } +} \ No newline at end of file diff --git a/app/admin/controller/Advert.php b/app/admin/controller/Advert.php index 0ebb51a..a53f9c2 100644 --- a/app/admin/controller/Advert.php +++ b/app/admin/controller/Advert.php @@ -18,7 +18,7 @@ use think\facade\Route as Url; /** * Class Advert * @package app\admin\controller - * @author 李玉坤 + * @author 木子的忧伤 * @date 2021-07-26 17:53 */ class Advert extends AuthController @@ -27,7 +27,7 @@ class Advert extends AuthController * 广告管理 * @return string * @throws Exception - * @author 李玉坤 + * @author 木子的忧伤 * @date 2021-02-19 11:53 */ public function index() @@ -47,7 +47,7 @@ class Advert extends AuthController * @throws DataNotFoundException * @throws DbException * @throws ModelNotFoundException - * @author 李玉坤 + * @author 木子的忧伤 * @date 2021-02-15 23:26 */ public function lst(Request $request) diff --git a/app/admin/controller/Article.php b/app/admin/controller/Article.php index 91bcbf7..8cd91f6 100644 --- a/app/admin/controller/Article.php +++ b/app/admin/controller/Article.php @@ -3,12 +3,10 @@ namespace app\admin\controller; use app\common\model\Document; -use app\common\model\Document as aModel; use app\common\model\DocumentCategory as cModel; use app\common\model\Tag as TagModel; use app\common\model\DocumentArticle; use app\common\model\Comment as CommentModel; -use app\Request; use app\admin\extend\Util as Util; use think\db\exception\DataNotFoundException; use think\db\exception\DbException; @@ -20,7 +18,7 @@ use think\facade\Log; /** * Class Article * @package app\admin\controller\system - * @author 李玉坤 + * @author 木子的忧伤 * @date 2021-02-15 23:20 */ class Article extends AuthController @@ -51,7 +49,7 @@ class Article extends AuthController * @throws DataNotFoundException * @throws DbException * @throws ModelNotFoundException - * @author 李玉坤 + * @author 木子的忧伤 * @date 2021-02-15 23:26 */ public function lst() @@ -65,14 +63,14 @@ class Article extends AuthController ['limit', 20], ]); $where['type'] = Document::DOCUMENT_TYPE_ARTICLE; - return app("json")->layui(aModel::systemPage($where)); + return app("json")->layui(Document::systemPage($where)); } /** * 保存 * @param string $id * @return mixed - * @author 李玉坤 + * @author 木子的忧伤 * @date 2021-02-28 22:43 */ public function save($id = "") @@ -97,81 +95,16 @@ class Article extends AuthController ['tags', ''], ['sort', ''], ['status', 1], + ['author', $this->adminInfo['nickname']], + ['uid', $this->adminId], ]); if ($data['title'] == "") return app("json")->fail("文章名称不能为空"); if ($data['category_id'] == "") return app("json")->fail("栏目分类不能为空"); if ($data['cover_path'] == "") return app("json")->fail("主图不能为空"); - $error = ""; - try { - $data['author'] = $data['author'] ?: $this->adminInfo['nickname']; - $data['uid'] = $this->adminId; - $content = ''; - if (!empty($data['content'])) { - $content = $data['content']; - } - //判断摘要是否为空,为空则从内容摘取 - $data['abstract'] = $data['abstract'] ?: mb_substr(strip_tags($content), 0, 100); - //判断是否写了别名,没写则需要生成 - if ($data['alias'] == "") $data['alias'] = get_rand_str(6); - unset($data['content']); - if ($data['is_recommend']) $data['is_recommend'] = 1; - if ($data['is_hot']) $data['is_hot'] = 1; - if ($data['display']) $data['display'] = 1; - if ($data['is_top']) $data['is_top'] = 1; - // 启动事务 - Db::startTrans(); - if ($id == "") { - $data['uid'] = $this->adminInfo['uid']; - $data['author'] = $data['author'] ?: $this->adminInfo['nickname']; - $data['create_date'] = date("Y-m-d"); - $data['create_time'] = time(); - $data['update_time'] = time(); - $id = aModel::insertGetId($data); - if (!empty($content)) { - $updateData = [ - 'id' => $id, - 'content' => $content - ]; - DocumentArticle::insert($updateData); - } - if (!empty($data['tags'])) { - $tagModel = new TagModel(); - $tagModel->createTags($data['tags'], $id, $this->adminId); - } - } else { - $ainfo = aModel::get($id); - if (!$ainfo) return app("json")->fail("数据不存在"); - aModel::where('id', $id)->save($data); - if (!empty($content)) { - $contentInfo = DocumentArticle::where('id', $id)->find(); - if (!$contentInfo) { - $updateData = [ - 'id' => $id, - 'content' => $content - ]; - DocumentArticle::insert($updateData); - } else { - //更新文档 - DocumentArticle::where('id', $id)->save(['content' => $content]); - } - } - if (!empty($data['tags'])) { - $tagModel = new TagModel(); - $tagModel->createTags($data['tags'], $id, $this->adminId); - } - } - // 启动事务 - Db::startTrans(); - $res = true; - } catch (Exception $e) { - Log::error('文章修改失败:失败原因:' . $e->getMessage()); - $error = $e->getMessage(); - $res = false; - // 回滚事务 - Db::rollback(); - } - return $res ? app("json")->success("操作成功", 'code') : app("json")->fail("操作失败,错误原因:".$error); + $model = new Document(); + $res = $model->updateInfo($data,Document::DOCUMENT_TYPE_ARTICLE); + return $res ? app("json")->success("操作成功", 'code') : app("json")->fail("操作失败,错误原因:".$model->getError()); } @@ -179,7 +112,7 @@ class Article extends AuthController * 修改字段 * @param $id * @return mixed - * @author 李玉坤 + * @author 木子的忧伤 * @date 2021-02-16 23:12 */ public function field($id) @@ -187,7 +120,7 @@ class Article extends AuthController if (!$id) return app("json")->fail("参数有误,Id为空!"); $where = Util::postMore([['field', ''], ['value', '']]); if ($where['field'] == '' || $where['value'] == '') return app("json")->fail("参数有误!"); - return aModel::update([$where['field'] => $where['value']], ['id' => $id]) ? app("json")->success("操作成功") : app("json")->fail("操作失败"); + return Document::update([$where['field'] => $where['value']], ['id' => $id]) ? app("json")->success("操作成功") : app("json")->fail("操作失败"); } /** @@ -197,7 +130,7 @@ class Article extends AuthController * @throws DataNotFoundException * @throws DbException * @throws ModelNotFoundException - * @author 李玉坤 + * @author 木子的忧伤 * @date 2021-03-10 14:46 */ public function add($category_id = '') @@ -217,7 +150,7 @@ class Article extends AuthController * 编辑页 * @return string * @throws \Exception - * @author 李玉坤 + * @author 木子的忧伤 * @date 2021-02-20 17:00 */ public function edit() @@ -227,21 +160,14 @@ class Article extends AuthController ['id', ''] ]); if ($where['id'] == '') { - $this->error('数据不存在'); + $this->error('参数错误'); } - $info = (new DocumentArticle())->getInfo($where["id"]); + $info = (new Document())->getInfo($where["id"],Document::DOCUMENT_TYPE_ARTICLE); if (empty($info)) { $this->error('数据不存在'); } $category = cModel::systemPage($where); $category = get_tree_list($category); - $info = aModel::get($where['id']); - $content = DocumentArticle::get($where['id']); - if ($content) { - $info->content = $content->content; - } else { - $info->content = ''; - } $this->assign("category", $category); $this->assign("info", $info); return $this->fetch(); @@ -263,7 +189,7 @@ class Article extends AuthController * @throws DataNotFoundException * @throws DbException * @throws ModelNotFoundException - * @author 李玉坤 + * @author 木子的忧伤 * @date 2021-11-03 23:28 */ public function commentList() @@ -287,7 +213,7 @@ class Article extends AuthController * 修改字段 * @param $id * @return mixed - * @author 李玉坤 + * @author 木子的忧伤 * @date 2021-02-16 23:12 */ public function commentField($id) diff --git a/app/admin/controller/Category.php b/app/admin/controller/Category.php index 5172361..338cd7b 100644 --- a/app/admin/controller/Category.php +++ b/app/admin/controller/Category.php @@ -15,7 +15,7 @@ use think\db\exception\ModelNotFoundException; /** * Class Article * @package app\admin\controller\system - * @author 李玉坤 + * @author 木子的忧伤 * @date 2021-02-15 23:20 */ class Category extends AuthController @@ -24,7 +24,7 @@ class Category extends AuthController * 分类 * @return string * @throws Exception - * @author 李玉坤 + * @author 木子的忧伤 * @date 2021-02-17 11:40 */ public function index() @@ -66,30 +66,18 @@ class Category extends AuthController ['description', ''], ['template', ''], ['link_str', ''], - ['content', ''], ['sort', 0], ['status', 1] ]); if ($data['title'] == "") return app("json")->fail("分类名称不能为空"); if ($data['type'] == "") return app("json")->fail("类型不能为空"); - $content = $data['content']; - unset($data['content']); //判断是否写了别名,没写则需要生成 if ($data['alias'] == "") $data['alias'] = get_rand_str(8); if ($id == "") { $model = new aModel(); - $id = $model->insert($data, true); - $data = [ - 'id' => $id, - 'content' => $content - ]; - $model = new DocumentCategoryContent(); - $res = $model->save($data); + $res = $model->insert($data); } else { $res = aModel::update($data, ['id' => $id]); - if ($res) { - $res = DocumentCategoryContent::update(['content' => $content], ['id' => $id]); - } } cache(Data::DATA_DOCUMENT_CATEGORY_LIST, null); return $res ? app("json")->success("操作成功", 'code') : app("json")->fail("操作失败"); @@ -140,7 +128,7 @@ class Category extends AuthController * 编辑页 * @return string * @throws Exception - * @author 李玉坤 + * @author 木子的忧伤 * @date 2021-02-20 17:00 */ public function edit(Request $request) @@ -160,7 +148,6 @@ class Category extends AuthController $category = aModel::systemPage($where); $category = get_tree_list($category); $info = aModel::get($request->param(['id'])); - $info->content = DocumentCategoryContent::get($request->param(['id']))->content; $this->assign("category", $category); $this->assign("info", $info); $this->assign("template_list", $themeList); @@ -171,7 +158,7 @@ class Category extends AuthController * 删除分类 * @param Request $request * @return mixed|void - * @author 李玉坤 + * @author 木子的忧伤 * @date 2021-04-01 21:56 */ public function del(Request $request) @@ -180,8 +167,7 @@ class Category extends AuthController ['id', ''], ]); $model = new aModel(); - $model->where('id', $where['id'])->delete(); - $res = DocumentCategoryContent::where('id', $where['id'])->delete(); + $res = $model->where('id', $where['id'])->delete(); cache(Data::DATA_DOCUMENT_CATEGORY_LIST, null); return $res ? app("json")->success("操作成功", 'code') : app("json")->fail("操作失败"); } diff --git a/app/admin/controller/Databases.php b/app/admin/controller/Databases.php index 39222d2..6077046 100644 --- a/app/admin/controller/Databases.php +++ b/app/admin/controller/Databases.php @@ -30,7 +30,7 @@ class Databases extends AuthController * @param null $type * @return string * @throws Exception - * @author 李玉坤 + * @author 木子的忧伤 * @date 2021-10-30 12:45 */ public function index($type = null) @@ -61,7 +61,7 @@ class Databases extends AuthController * @throws DataNotFoundException * @throws DbException * @throws ModelNotFoundException - * @author 李玉坤 + * @author 木子的忧伤 * @date 2021-10-31 0:12 */ public function lst(Request $request) @@ -126,7 +126,7 @@ class Databases extends AuthController /** * 优化表 - * @author 李玉坤 + * @author 木子的忧伤 * @date 2021-10-30 12:46 */ public function optimize() @@ -148,7 +148,7 @@ class Databases extends AuthController /** * 修复表 - * @author 李玉坤 + * @author 木子的忧伤 * @date 2021-10-31 0:12 */ public function repair() @@ -174,7 +174,7 @@ class Databases extends AuthController * @throws DataNotFoundException * @throws DbException * @throws ModelNotFoundException - * @author 李玉坤 + * @author 木子的忧伤 * @date 2021-10-30 13:31 */ public function delOne() @@ -195,7 +195,7 @@ class Databases extends AuthController * @throws DataNotFoundException * @throws DbException * @throws ModelNotFoundException - * @author 李玉坤 + * @author 木子的忧伤 * @date 2021-10-31 0:35 */ public function export() @@ -277,7 +277,7 @@ class Databases extends AuthController /** * 还原数据库 - * @author 李玉坤 + * @author 木子的忧伤 * @date 2021-10-30 12:46 */ public function import() diff --git a/app/admin/controller/FriendLink.php b/app/admin/controller/FriendLink.php index 666cb56..c5c5648 100644 --- a/app/admin/controller/FriendLink.php +++ b/app/admin/controller/FriendLink.php @@ -18,7 +18,7 @@ use think\facade\Route as Url; /** * Class Message * @package app\admin\controller\system - * @author 李玉坤 + * @author 木子的忧伤 * @date 2021-02-15 23:20 */ class FriendLink extends AuthController @@ -40,7 +40,7 @@ class FriendLink extends AuthController * @throws DataNotFoundException * @throws DbException * @throws ModelNotFoundException - * @author 李玉坤 + * @author 木子的忧伤 * @date 2021-02-15 23:26 */ public function lst(Request $request) @@ -136,7 +136,7 @@ class FriendLink extends AuthController * 修改字段 * @param $id * @return mixed - * @author 李玉坤 + * @author 木子的忧伤 * @date 2021-02-16 23:12 */ public function field($id) diff --git a/app/admin/controller/Invitation.php b/app/admin/controller/Invitation.php index c8af5f6..1fb1942 100644 --- a/app/admin/controller/Invitation.php +++ b/app/admin/controller/Invitation.php @@ -13,7 +13,7 @@ use think\db\exception\ModelNotFoundException; /** * Class Invitation * @package app\admin\controller\system - * @author 李玉坤 + * @author 木子的忧伤 * @date 2021-02-15 23:20 */ class Invitation extends AuthController @@ -32,7 +32,7 @@ class Invitation extends AuthController * 邀请码列表 * @return string * @throws Exception - * @author 李玉坤 + * @author 木子的忧伤 * @date 2021-02-16 13:15 */ public function index() @@ -47,7 +47,7 @@ class Invitation extends AuthController * @throws DataNotFoundException * @throws DbException * @throws ModelNotFoundException - * @author 李玉坤 + * @author 木子的忧伤 * @date 2021-02-15 23:26 */ public function lst(Request $request) @@ -67,7 +67,7 @@ class Invitation extends AuthController * @throws DataNotFoundException * @throws DbException * @throws ModelNotFoundException - * @author 李玉坤 + * @author 木子的忧伤 * @date 2021-02-20 14:32 */ public function save($id = "") @@ -99,7 +99,7 @@ class Invitation extends AuthController * @throws DataNotFoundException * @throws DbException * @throws ModelNotFoundException - * @author 李玉坤 + * @author 木子的忧伤 * @date 2021-02-20 14:35 */ public function addMultiple($id = "") diff --git a/app/admin/controller/Message.php b/app/admin/controller/Message.php index d57e4b2..88a6c0a 100644 --- a/app/admin/controller/Message.php +++ b/app/admin/controller/Message.php @@ -13,7 +13,7 @@ use think\db\exception\ModelNotFoundException; /** * Class Message * @package app\admin\controller\system - * @author 李玉坤 + * @author 木子的忧伤 * @date 2021-02-15 23:20 */ class Message extends AuthController @@ -32,7 +32,7 @@ class Message extends AuthController * 留言管理 * @return string * @throws Exception - * @author 李玉坤 + * @author 木子的忧伤 * @date 2021-02-19 11:53 */ public function index() @@ -47,7 +47,7 @@ class Message extends AuthController * @throws DataNotFoundException * @throws DbException * @throws ModelNotFoundException - * @author 李玉坤 + * @author 木子的忧伤 * @date 2021-02-19 11:54 */ public function lst(Request $request) diff --git a/app/admin/controller/Nav.php b/app/admin/controller/Nav.php index efa3e1a..9969a45 100644 --- a/app/admin/controller/Nav.php +++ b/app/admin/controller/Nav.php @@ -3,6 +3,7 @@ namespace app\admin\controller; use app\admin\extend\FormBuilder as Form; +use app\common\constant\Data; use app\common\model\Nav as aModel; use app\Request; use app\admin\extend\Util as Util; @@ -17,7 +18,7 @@ use think\facade\Route as Url; /** * Class Nav * @package app\admin\controller\system - * @author 李玉坤 + * @author 木子的忧伤 * @date 2021-02-15 23:20 */ class Nav extends AuthController @@ -123,7 +124,7 @@ class Nav extends AuthController $res = aModel::update($data, ['id' => $id]); } //清理缓存 - aModel::clearCache($this->adminId); + cache(Data::DATA_NAV_LIST, null); return $res ? app("json")->success("操作成功", 'code') : app("json")->fail("操作失败"); } @@ -138,7 +139,7 @@ class Nav extends AuthController $where = Util::postMore([['field', ''], ['value', '']]); if ($where['field'] == '' || $where['value'] == '') return app("json")->fail("参数有误!"); //清理缓存 - aModel::clearCache($this->adminId); + cache(Data::DATA_NAV_LIST, null); return aModel::update([$where['field'] => $where['value']], ['id' => $id]) ? app("json")->success("操作成功") : app("json")->fail("操作失败"); } } \ No newline at end of file diff --git a/app/admin/controller/Page.php b/app/admin/controller/Page.php index 584c2f0..9d60487 100644 --- a/app/admin/controller/Page.php +++ b/app/admin/controller/Page.php @@ -3,22 +3,16 @@ namespace app\admin\controller; use app\common\model\Document; -use app\common\model\Document as aModel; -use app\common\model\DocumentPage; -use app\common\model\Tag as TagModel; use app\common\model\Comment as CommentModel; use app\admin\extend\Util as Util; use think\db\exception\DataNotFoundException; use think\db\exception\DbException; use think\db\exception\ModelNotFoundException; -use think\Exception; -use think\facade\Db; -use think\facade\Log; /** * Class Page * @package app\admin\controller\system - * @author 李玉坤 + * @author 木子的忧伤 * @date 2021-02-15 23:20 */ class Page extends AuthController @@ -50,7 +44,7 @@ class Page extends AuthController * @throws DataNotFoundException * @throws DbException * @throws ModelNotFoundException - * @author 李玉坤 + * @author 木子的忧伤 * @date 2021-02-15 23:26 */ public function lst() @@ -63,18 +57,18 @@ class Page extends AuthController ['page', 1], ['limit', 20], ]); - $where["type"] = aModel::DOCUMENT_TYPE_PAGE; - return app("json")->layui(aModel::systemPage($where)); + $where["type"] = Document::DOCUMENT_TYPE_PAGE; + return app("json")->layui(Document::systemPage($where)); } /** * 保存 * @param string $id * @return mixed - * @author 李玉坤 + * @author 木子的忧伤 * @date 2021-02-28 22:43 */ - public function save($id = "") + public function save() { $data = Util::postMore([ ['id', ''], @@ -90,86 +84,22 @@ class Page extends AuthController ['is_recommend', 0], ['is_top', 0], ['is_hot', 0], + ['theme',''], ['link_str', ''], ['cover_path', ''], ['display', 1], ['tags', ''], ['sort', ''], ['status', 1], + ['author', $this->adminInfo['nickname']], + ['uid', $this->adminId], ]); - if ($data['title'] == "") return app("json")->fail("文章名称不能为空"); + if ($data['theme'] == "") return app("json")->fail("文章模板不能为空"); if ($data['cover_path'] == "") return app("json")->fail("主图不能为空"); - $error = ""; - try { - $data['author'] = $data['author'] ?: $this->adminInfo['nickname']; - $data['uid'] = $this->adminId; - $content = ''; - if (!empty($data['content'])) { - $content = $data['content']; - } - //判断摘要是否为空,为空则从内容摘取 - $data['abstract'] = $data['abstract'] ?: mb_substr(strip_tags($content), 0, 100); - //判断是否写了别名,没写则需要生成 - if ($data['alias'] == "") $data['alias'] = get_rand_str(6); - unset($data['content']); - if ($data['is_recommend']) $data['is_recommend'] = 1; - if ($data['is_hot']) $data['is_hot'] = 1; - if ($data['display']) $data['display'] = 1; - if ($data['is_top']) $data['is_top'] = 1; - // 启动事务 - Db::startTrans(); - if ($id == "") { - $data['uid'] = $this->adminInfo['uid']; - $data['author'] = $data['author'] ?: $this->adminInfo['nickname']; - $data['create_date'] = date("Y-m-d"); - $data['create_time'] = time(); - $data['update_time'] = time(); - $id = aModel::insertGetId($data); - if (!empty($content)) { - $updateData = [ - 'id' => $id, - 'content' => $content - ]; - DocumentPage::insert($updateData); - } - if (!empty($data['tags'])) { - $tagModel = new TagModel(); - $tagModel->createTags($data['tags'], $id, $this->adminId); - } - } else { - $ainfo = aModel::get($id); - if (!$ainfo) return app("json")->fail("数据不存在"); - aModel::where('id', $id)->save($data); - if (!empty($content)) { - $contentInfo = DocumentPage::where('id', $id)->find(); - if (!$contentInfo) { - $updateData = [ - 'id' => $id, - 'content' => $content - ]; - DocumentPage:insert($updateData); - } else { - //更新文档 - DocumentPage::where('id', $id)->save(['content' => $content]); - } - } - if (!empty($data['tags'])) { - $tagModel = new TagModel(); - $tagModel->createTags($data['tags'], $id, $this->adminId); - } - } - // 启动事务 - Db::startTrans(); - $res = true; - } catch (Exception $e) { - Log::error('文章修改失败:失败原因:' . $e->getMessage()); - $error = $e->getMessage(); - $res = false; - // 回滚事务 - Db::rollback(); - } - return $res ? app("json")->success("操作成功", 'code') : app("json")->fail("操作失败,错误原因:".$error); + $model = new Document(); + $res = $model->updateInfo($data,Document::DOCUMENT_TYPE_PAGE); + return $res ? app("json")->success("操作成功", 'code') : app("json")->fail("操作失败,错误原因:".$model->getError()); } @@ -177,7 +107,7 @@ class Page extends AuthController * 修改字段 * @param $id * @return mixed - * @author 李玉坤 + * @author 木子的忧伤 * @date 2021-02-16 23:12 */ public function field($id) @@ -185,7 +115,7 @@ class Page extends AuthController if (!$id) return app("json")->fail("参数有误,Id为空!"); $where = Util::postMore([['field', ''], ['value', '']]); if ($where['field'] == '' || $where['value'] == '') return app("json")->fail("参数有误!"); - return aModel::update([$where['field'] => $where['value']], ['id' => $id]) ? app("json")->success("操作成功") : app("json")->fail("操作失败"); + return Document::update([$where['field'] => $where['value']], ['id' => $id]) ? app("json")->success("操作成功") : app("json")->fail("操作失败"); } /** @@ -194,24 +124,15 @@ class Page extends AuthController * @throws DataNotFoundException * @throws DbException * @throws ModelNotFoundException - * @author 李玉坤 + * @author 木子的忧伤 * @date 2021-03-10 14:46 */ public function add() { // 获取页面模板列表 - $themeList = []; - $themeDir = public_path('template').system_config('web_template').'/pc/page'; - if ($dh = opendir($themeDir)) { - while (($file = readdir($dh)) !== false) { - - if ( $file != "." && $file != "..") { - $themeList[] = $file; - } - } - closedir($dh); - } - $this->assign("themeList", $themeList); + $this->getThemeList(); + $themeList = get_theme_list(Document::DOCUMENT_TYPE_PAGE); + $this->assign("theme_list", $themeList); return $this->fetch(); } @@ -230,24 +151,13 @@ class Page extends AuthController if ($where['id'] == '') { $this->error('数据不存在'); } - $info = (new DocumentPage())->getInfo($where["id"]); + $info = (new Document())->getInfo($where["id"],Document::DOCUMENT_TYPE_PAGE); if (empty($info)) { $this->error('数据不存在'); } // 获取页面模板列表 - $themeList = []; - $themeDir = public_path('template/'); - $defaultTheme = system_config('web_template'); - if ($dh = opendir($themeDir.'/'.$defaultTheme.'/pc/page')) { - if ((is_dir($themeDir . "/" . $file)) && $file != "." && $file != "..") { - while (($file = readdir($dh)) !== false) { - $pageList[] = $file; - } - } - - closedir($dh); - } - $this->assign("themeList", $themeList); + $themeList = get_theme_list(Document::DOCUMENT_TYPE_PAGE); + $this->assign("theme_list", $themeList); $this->assign("info", $info); return $this->fetch(); } @@ -268,7 +178,7 @@ class Page extends AuthController * @throws DataNotFoundException * @throws DbException * @throws ModelNotFoundException - * @author 李玉坤 + * @author 木子的忧伤 * @date 2021-11-03 23:28 */ public function commentList() @@ -292,7 +202,7 @@ class Page extends AuthController * 修改字段 * @param $id * @return mixed - * @author 李玉坤 + * @author 木子的忧伤 * @date 2021-02-16 23:12 */ public function commentField($id) @@ -302,5 +212,4 @@ class Page extends AuthController if ($where['field'] == '' || $where['value'] == '') return app("json")->fail("参数有误!"); return CommentModel::update([$where['field'] => $where['value']], ['id' => $id]) ? app("json")->success("操作成功") : app("json")->fail("操作失败"); } - } \ No newline at end of file diff --git a/app/admin/controller/Theme.php b/app/admin/controller/Theme.php index 4e4e9e9..0d8ef32 100644 --- a/app/admin/controller/Theme.php +++ b/app/admin/controller/Theme.php @@ -10,7 +10,7 @@ use Exception; /** * Class Theme * @package app\admin\controller\system - * @author 李玉坤 + * @author 木子的忧伤 * @date 2021-02-15 23:20 */ class Theme extends AuthController @@ -19,7 +19,7 @@ class Theme extends AuthController * 主题列表 * @return string * @throws Exception - * @author 李玉坤 + * @author 木子的忧伤 * @date 2021-02-17 11:40 */ public function index() @@ -55,7 +55,7 @@ class Theme extends AuthController * 更新主题 * @return string * @throws Exception - * @author 李玉坤 + * @author 木子的忧伤 * @date 2021-02-17 11:40 */ public function change_theme() diff --git a/app/admin/controller/User.php b/app/admin/controller/User.php index 61c46ee..6229718 100644 --- a/app/admin/controller/User.php +++ b/app/admin/controller/User.php @@ -18,7 +18,7 @@ use think\facade\Route as Url; * 用户管理 * Class User * @package app\admin\controller\system - * @author 李玉坤 + * @author 木子的忧伤 * @date 2021-02-15 23:20 */ class User extends AuthController diff --git a/app/admin/view/page/add.html b/app/admin/view/page/add.html index b05e7cb..0bfd979 100644 --- a/app/admin/view/page/add.html +++ b/app/admin/view/page/add.html @@ -33,7 +33,7 @@
diff --git a/app/admin/view/page/edit.html b/app/admin/view/page/edit.html index a7d0338..f0db494 100644 --- a/app/admin/view/page/edit.html +++ b/app/admin/view/page/edit.html @@ -24,7 +24,8 @@
- + +
@@ -33,7 +34,7 @@
diff --git a/app/api/controller/Index.php b/app/api/controller/Index.php index fa383c9..3537969 100644 --- a/app/api/controller/Index.php +++ b/app/api/controller/Index.php @@ -46,7 +46,7 @@ class Index extends AuthController * @throws DataNotFoundException * @throws DbException * @throws ModelNotFoundException - * @author 李玉坤 + * @author 木子的忧伤 * @date 2021-10-17 1:03 */ public function msg(Request $request) @@ -82,7 +82,7 @@ class Index extends AuthController /** * 标签列表 * @return mixed - * @author 李玉坤 + * @author 木子的忧伤 * @date 2021-11-11 0:27 */ public function tagList() diff --git a/app/common.php b/app/common.php index 6ee07f7..9c9e808 100644 --- a/app/common.php +++ b/app/common.php @@ -136,7 +136,7 @@ if (!function_exists('file_cdn')) { * 文件cdn * @param $path * @return string - * @author 李玉坤 + * @author 木子的忧伤 * @date 2021-02-17 23:32 */ function file_cdn($path) @@ -169,7 +169,7 @@ if (!function_exists('get_rand_str')) { * 生成随机字符串 * @param $length * @return string - * @author 李玉坤 + * @author 木子的忧伤 * @date 2022-04-11 18:26 */ function get_rand_str($length){ diff --git a/app/common/constant/Data.php b/app/common/constant/Data.php index 31c6fea..396c22a 100644 --- a/app/common/constant/Data.php +++ b/app/common/constant/Data.php @@ -1,6 +1,6 @@ leftJoin('document_article p','a.id = p.id') + ->where("a.type",Document::DOCUMENT_TYPE_PAGE); + if (is_numeric($id)){ + $model->where("a.id",$id); + }else{ + $model->where("a.alias",$id); + } + if ($type !=='') $model->where("a.type",$type); + if ($status !=='')$model->where("a.status",$status); + $info = $model->find(); + if (!$info){ + return []; + } + return $info->toArray(); + } + + /** + * 更新文件信息 + * @param $dat + * @param string $type + * @throws DataNotFoundException + * @throws DbException + * @throws ModelNotFoundException + */ + public function updateInfo($data, string $type=self::DOCUMENT_TYPE_ARTICLE) + { + try { + $content = !empty($data['content'])?$data['content']:''; + //判断摘要是否为空,为空则从内容摘取 + $data['abstract'] = $data['abstract'] ?: mb_substr(strip_tags($content), 0, 100); + //判断是否写了别名,没写则需要生成 + if ($data['alias'] == "") $data['alias'] = get_rand_str(6); + unset($data['content']); + if ($data['is_recommend']) $data['is_recommend'] = 1; + if ($data['is_hot']) $data['is_hot'] = 1; + if ($data['display']) $data['display'] = 1; + if ($data['is_top']) $data['is_top'] = 1; + // 启动事务 + Db::startTrans(); + if (empty($data['id'])) { + $data['create_date'] = date("Y-m-d"); + $data['create_time'] = time(); + $data['update_time'] = time(); + $id = Document::insertGetId($data); + if (!empty($content)) { + $updateData = [ + 'id' => $id, + 'content' => $content + ]; + DocumentPage::insert($updateData); + } + if (!empty($data['tags'])) { + $tagModel = new TagModel(); + $tagModel->createTags($data['tags'], $id, $data['uid']); + } + } else { + $ainfo = Document::get($data['id']); + if (!$ainfo) return app("json")->fail("数据不存在"); + Document::where('id', $data['id'])->save($data); + if (!empty($content)) { + switch ($type) { + case self::DOCUMENT_TYPE_ARTICLE: + $updateData = [ + 'id' => $data['id'], + 'content' => $content + ]; + $model = new DocumentArticle(); + $model->save($updateData); + break; + case self::DOCUMENT_TYPE_PAGE: + $updateData = [ + 'id' => $data['id'], + 'content' => $content + ]; + $model = new DocumentPage(); + $model->save($updateData); + break; + case self::DOCUMENT_TYPE_CATEGORY; + break; + default: + //默认暂时不处理 + break; + } + } + if (!empty($data['tags'])) { + $tagModel = new TagModel(); + $tagModel->createTags($data['tags'], $data['id'], $data['uid']); + } + } + // 提交事务 + Db::commit(); + $res = true; + } catch (\Exception $e) { + Log::error('文章修改失败:失败原因:' . $e->getMessage()); + $res = false; + self::setErrorInfo($e->getMessage()); + // 回滚事务 + Db::rollback(); + } + return $res; + } } \ No newline at end of file diff --git a/app/common/model/DocumentArticle.php b/app/common/model/DocumentArticle.php index 9e2f8a7..03b6d94 100644 --- a/app/common/model/DocumentArticle.php +++ b/app/common/model/DocumentArticle.php @@ -12,24 +12,9 @@ use think\db\exception\ModelNotFoundException; /** * Class DocumentArticle * @package app\admin\model\system - * @author 李玉坤 + * @author 木子的忧伤 * @date 2021-02-15 23:22 */ class DocumentArticle extends BaseModel { - public function getInfo($id) - { - if (empty($id)){ - return []; - } - $info = aModel::alias('a') - ->leftJoin('document_article p','a.id = p.id') - ->where("a.id",$id) - ->where("a.type",Document::DOCUMENT_TYPE_PAGE) - ->find(); - if (!$info){ - return []; - } - return $info->toArray(); - } } \ No newline at end of file diff --git a/app/common/model/DocumentCategory.php b/app/common/model/DocumentCategory.php index 27611c8..b8d8fe3 100644 --- a/app/common/model/DocumentCategory.php +++ b/app/common/model/DocumentCategory.php @@ -10,7 +10,7 @@ use think\db\exception\ModelNotFoundException; /** * Class DocumentCategory * @package app\admin\model\system - * @author 李玉坤 + * @author 木子的忧伤 * @date 2021-02-15 23:22 */ class DocumentCategory extends BaseModel @@ -22,7 +22,7 @@ class DocumentCategory extends BaseModel * @throws DataNotFoundException * @throws DbException * @throws ModelNotFoundException - * @author 李玉坤 + * @author 木子的忧伤 * @date 2021-11-08 0:25 */ public static function systemPage($where): array diff --git a/app/common/model/DocumentCategoryContent.php b/app/common/model/DocumentCategoryContent.php deleted file mode 100644 index a8330bd..0000000 --- a/app/common/model/DocumentCategoryContent.php +++ /dev/null @@ -1,38 +0,0 @@ -page((int)$where['page'], (int)$where['limit']); - $data = $model->select(); - if ($data) $data = $data->toArray(); - return compact('data', 'count'); - } -} \ No newline at end of file diff --git a/app/common/model/DocumentPage.php b/app/common/model/DocumentPage.php index a3c47bd..547ffc9 100644 --- a/app/common/model/DocumentPage.php +++ b/app/common/model/DocumentPage.php @@ -12,25 +12,9 @@ use think\db\exception\ModelNotFoundException; /** * Class DocumentPage * @package app\admin\model\system - * @author 李玉坤 + * @author 木子的忧伤 * @date 2021-02-15 23:22 */ class DocumentPage extends BaseModel { - public function getInfo($id) - { - if (empty($id)){ - return []; - } - $info = aModel::alias('a') - ->leftJoin('document_page p','a.id = p.id') - ->where("a.id",$id) - ->where("a.type",Document::DOCUMENT_TYPE_PAGE) - ->find(); - if (!$info){ - return []; - } - return $info->toArray(); - } - } \ No newline at end of file diff --git a/app/common/model/DocumentProduct.php b/app/common/model/DocumentProduct.php index a5b0d41..124d21d 100644 --- a/app/common/model/DocumentProduct.php +++ b/app/common/model/DocumentProduct.php @@ -11,7 +11,7 @@ use think\db\exception\ModelNotFoundException; /** * Class DocumentProduct * @package app\admin\model\system - * @author 李玉坤 + * @author 木子的忧伤 * @date 2021-02-15 23:22 */ class DocumentProduct extends BaseModel @@ -23,7 +23,7 @@ class DocumentProduct extends BaseModel * @throws DataNotFoundException * @throws DbException * @throws ModelNotFoundException - * @author 李玉坤 + * @author 木子的忧伤 * @date 2021-02-15 23:24 */ public static function systemPage($where): array diff --git a/app/common/model/FriendLink.php b/app/common/model/FriendLink.php index d465d9e..8db9bb5 100644 --- a/app/common/model/FriendLink.php +++ b/app/common/model/FriendLink.php @@ -11,7 +11,7 @@ use think\db\exception\ModelNotFoundException; /** * Class FriendLink * @package app\admin\model\system - * @author 李玉坤 + * @author 木子的忧伤 * @date 2021-02-15 23:22 */ class FriendLink extends BaseModel @@ -23,7 +23,7 @@ class FriendLink extends BaseModel * @throws DataNotFoundException * @throws DbException * @throws ModelNotFoundException - * @author 李玉坤 + * @author 木子的忧伤 * @date 2021-02-15 23:24 */ public static function systemPage($where): array diff --git a/app/common/model/InvitationCode.php b/app/common/model/InvitationCode.php index 475a47c..37ab343 100644 --- a/app/common/model/InvitationCode.php +++ b/app/common/model/InvitationCode.php @@ -11,7 +11,7 @@ use think\db\exception\ModelNotFoundException; /** * Class InvitationCode * @package app\admin\model\system - * @author 李玉坤 + * @author 木子的忧伤 * @date 2021-02-15 23:22 */ class InvitationCode extends BaseModel @@ -23,7 +23,7 @@ class InvitationCode extends BaseModel * @throws DataNotFoundException * @throws DbException * @throws ModelNotFoundException - * @author 李玉坤 + * @author 木子的忧伤 * @date 2021-02-15 23:24 */ public static function systemPage($where): array diff --git a/app/common/model/MessageForm.php b/app/common/model/MessageForm.php index 9037652..312f220 100644 --- a/app/common/model/MessageForm.php +++ b/app/common/model/MessageForm.php @@ -10,7 +10,7 @@ use think\db\exception\ModelNotFoundException; /** * Class Document * @package app\admin\model\system - * @author 李玉坤 + * @author 木子的忧伤 * @date 2021-02-15 23:22 */ class MessageForm extends BaseModel @@ -22,7 +22,7 @@ class MessageForm extends BaseModel * @throws DataNotFoundException * @throws DbException * @throws ModelNotFoundException - * @author 李玉坤 + * @author 木子的忧伤 * @date 2021-02-15 23:24 */ public static function systemPage($where): array diff --git a/app/common/model/Nav.php b/app/common/model/Nav.php index fd61526..3cf75b8 100644 --- a/app/common/model/Nav.php +++ b/app/common/model/Nav.php @@ -11,7 +11,7 @@ use think\db\exception\ModelNotFoundException; /** * Class Document * @package app\admin\model\system - * @author 李玉坤 + * @author 木子的忧伤 * @date 2021-02-15 23:22 */ class Nav extends BaseModel @@ -57,34 +57,6 @@ class Nav extends BaseModel return $data->toArray() ?: []; } - /** - * 获取菜单列表缓存key - * @param $adminId - * @return string - * @author 李玉坤 - * @date 2021-06-09 17:24 - */ - public static function getMenuCacheKey($adminId) - { - return 'menu:List:' . $adminId; - } - - /** - * @return string - * @author 李玉坤 - * @date 2021-06-15 11:11 - */ - public static function getAuthCacheKey() - { - return 'auth:key:list'; - } - - public static function clearCache($adminId) - { - cache(AdminAuth::getMenuCacheKey($adminId), null); - cache(AdminAuth::getAuthCacheKey(), null); - } - /** * 遍历选择项 * @param array $data @@ -132,54 +104,6 @@ class Nav extends BaseModel return $str . " "; } - /** - * 生成treeData - * @param int $pid - * @param array $auth - * @param array $list - * @return array - * @throws DataNotFoundException - * @throws DbException - * @throws ModelNotFoundException - */ - public static function selectAndBuildTree(int $pid = 0, array $auth = [], array $list = []) - { - $model = new self; - $model = $model->where("pid", $pid); - if ($auth != []) $model = $model->where("id", 'in', $auth); - $model = $model->where("status", 1); - $model = $model->field(['title', 'id']); - $model = $model->order(["sort desc", "id"]); - $data = $model->select(); - foreach ($data as $k => $v) { - $list[] = self::buildTreeData($v['id'], $v['title'], self::selectAndBuildTree($v['id'], $auth)); - } - return $list; - } - - /** - * 获取所有权限id - * @param array $ids - * @return array - */ - public static function getIds(array $ids = []): array - { - if (empty($ids)) return self::where("status", 1)->column("id"); - $pids = self::where("id", "in", $ids)->column("pid"); - return array_merge($ids, $pids) ?: []; - } - - /** - * 获取操作名 - * @param string $module - * @param string $controller - * @param string $action - * @return string - */ - public static function getNameByAction(string $module, string $controller, string $action) - { - return self::where("module", $module)->where("controller", $controller)->where("action", $action)->value("title") ?: '未知操作'; - } /** * 生成单个节点 * @param $id diff --git a/app/common/model/SystemConfigTab.php b/app/common/model/SystemConfigTab.php index ba8fc19..9e317fa 100644 --- a/app/common/model/SystemConfigTab.php +++ b/app/common/model/SystemConfigTab.php @@ -17,7 +17,7 @@ class SystemConfigTab extends BaseModel * @throws DataNotFoundException * @throws DbException * @throws ModelNotFoundException - * @author 李玉坤 + * @author 木子的忧伤 * @date 2022-02-28 9:19 */ public static function lst($where) diff --git a/app/common/model/Tag.php b/app/common/model/Tag.php index 15acf73..a6970f0 100644 --- a/app/common/model/Tag.php +++ b/app/common/model/Tag.php @@ -12,7 +12,7 @@ use think\db\exception\ModelNotFoundException; /** * Class Tag * @package app\common\model - * @author 李玉坤 + * @author 木子的忧伤 * @date 2021-11-08 0:11 */ class Tag extends BaseModel @@ -24,7 +24,7 @@ class Tag extends BaseModel * @throws DataNotFoundException * @throws DbException * @throws ModelNotFoundException - * @author 李玉坤 + * @author 木子的忧伤 * @date 2021-02-15 23:24 */ public static function systemPage($where): array @@ -49,7 +49,7 @@ class Tag extends BaseModel * @param $user_id * @return Collection * @throws Exception - * @author 李玉坤 + * @author 木子的忧伤 * @date 2021-11-08 0:53 */ public function createTags($tags, $document_id, $user_id) @@ -78,7 +78,7 @@ class Tag extends BaseModel * @throws DataNotFoundException * @throws DbException * @throws ModelNotFoundException - * @author 李玉坤 + * @author 木子的忧伤 * @date 2021-02-15 23:24 */ public static function getList($where): array diff --git a/app/common/model/User.php b/app/common/model/User.php index 2bf949b..771b606 100644 --- a/app/common/model/User.php +++ b/app/common/model/User.php @@ -13,7 +13,7 @@ use think\facade\Session; * 用户管理 * Class User * @package app\admin\model - * @author 李玉坤 + * @author 木子的忧伤 * @date 2021-02-18 15:49 */ class User extends BaseModel @@ -49,7 +49,7 @@ class User extends BaseModel * @throws DataNotFoundException * @throws DbException * @throws ModelNotFoundException - * @author 李玉坤 + * @author 木子的忧伤 * @date 2022-01-16 1:33 */ public static function register(string $username, string $email, string $password): bool @@ -90,7 +90,7 @@ class User extends BaseModel * 添加后台用户信息 * @param $data * @return bool|int|string - * @author 李玉坤 + * @author 木子的忧伤 * @date 2022-01-03 3:46 */ public static function addAdminUser($data) @@ -114,7 +114,7 @@ class User extends BaseModel * @param $id * @param $data * @return bool|int|string - * @author 李玉坤 + * @author 木子的忧伤 * @date 2022-01-03 3:48 */ public static function updateAdminUser($id, $data) diff --git a/app/common/taglib/Ape.php b/app/common/taglib/Ape.php index 9ba61da..cd688a5 100644 --- a/app/common/taglib/Ape.php +++ b/app/common/taglib/Ape.php @@ -234,7 +234,7 @@ class Ape extends TagLib * @param $tag * @param $content * @return string - * @author 李玉坤 + * @author 木子的忧伤 * @date 2021-07-26 23:22 */ public function tagAdvert($tag, $content) @@ -302,7 +302,7 @@ class Ape extends TagLib * @param $tag * @param $content * @return bool|string - * @author 李玉坤 + * @author 木子的忧伤 * @date 2021-11-27 23:44 */ public function tagComment($tag, $content) @@ -331,7 +331,7 @@ class Ape extends TagLib * @param $tag * @param $content * @return string - * @author 李玉坤 + * @author 木子的忧伤 * @date 2021-11-28 0:52 */ public function tagRelevant($tag, $content) diff --git a/app/index/common.php b/app/index/common.php index 6437594..27ee5da 100644 --- a/app/index/common.php +++ b/app/index/common.php @@ -135,7 +135,7 @@ function get_document_category_by_name($name, $field = false) * @throws DataNotFoundException * @throws DbException * @throws ModelNotFoundException - * @author 李玉坤 + * @author 木子的忧伤 * @date 2021-11-12 21:48 */ function tpl_get_channel($type, $typeId, $row = 100, $where = '', $orderby = '') @@ -596,7 +596,7 @@ function tpl_get_friend_link($type, $row) * @throws DataNotFoundException * @throws DbException * @throws ModelNotFoundException - * @author 李玉坤 + * @author 木子的忧伤 * @date 2021-07-26 23:24 */ function tpl_get_advert($type, $row) @@ -626,7 +626,7 @@ function tpl_get_advert($type, $row) * @param $type * @param $format * @return mixed - * @author 李玉坤 + * @author 木子的忧伤 * @date 2022-06-01 10:06 */ function tpl_get_archive_list($type,$format){ @@ -661,7 +661,7 @@ if (!function_exists('web_config')) { * 获取系统配置值 * @param string $formName * @return string - * @author 李玉坤 + * @author 木子的忧伤 * @date 2021-11-12 0:34 */ function web_config(string $formName): string @@ -679,7 +679,7 @@ if (!function_exists('web_config')) { * 模板-文章标签 * @param $tags * @return array|bool - * @author 李玉坤 + * @author 木子的忧伤 * @date 2021-11-12 0:34 */ if (!function_exists('tpl_get_tags_list')) { @@ -705,7 +705,7 @@ if (!function_exists('tpl_get_tags_list')) { * @param array $positionList * @return string * @throws Exception - * @author 李玉坤 + * @author 木子的忧伤 * @date 2021-12-05 22:40 */ function tpl_get_position($dc, $positionList = array()) @@ -745,7 +745,7 @@ function get_comment_children($parentIds) * @param string $orderBy * @return array * @throws DbException - * @author 李玉坤 + * @author 木子的忧伤 * @date 2021-12-05 23:54 */ function tpl_get_comment_list($id, $type, $pageSize, $orderBy) @@ -787,7 +787,7 @@ function tpl_get_comment_list($id, $type, $pageSize, $orderBy) * @param $documentId * @param string $type * @return int - * @author 李玉坤 + * @author 木子的忧伤 * @date 2021-12-05 23:16 */ function get_comment_count($documentId, $type = 'top') @@ -816,7 +816,7 @@ function get_comment_count($documentId, $type = 'top') * @throws DataNotFoundException * @throws DbException * @throws ModelNotFoundException - * @author 李玉坤 + * @author 木子的忧伤 * @date 2021-11-28 1:02 */ function tpl_get_relevant_list($documentId, $row, $table = 'article') @@ -995,7 +995,7 @@ function is_mobile() /** * 加载svg * @param $path - * @author 李玉坤 + * @author 木子的忧伤 * @date 2021-12-05 21:35 */ function file_echo_svg($path) @@ -1008,7 +1008,7 @@ function file_echo_svg($path) * 加载表情 * @param $path * @return string|null - * @author 李玉坤 + * @author 木子的忧伤 * @date 2021-12-05 21:36 */ function file_load_face($path) @@ -1056,7 +1056,7 @@ function comment_face($incoming_comment,$path) * @throws DataNotFoundException * @throws DbException * @throws ModelNotFoundException - * @author 李玉坤 + * @author 木子的忧伤 * @date 2021-11-12 21:48 */ function tpl_get_nav($type, $typeId, $row = 100, $where = '', $orderby = '') diff --git a/app/index/controller/Article.php b/app/index/controller/Article.php index 1c53d8f..58b384d 100644 --- a/app/index/controller/Article.php +++ b/app/index/controller/Article.php @@ -30,7 +30,7 @@ class Article extends Base * @throws DataNotFoundException * @throws DbException * @throws ModelNotFoundException - * @author 李玉坤 + * @author 木子的忧伤 * @date 2021-10-29 0:17 */ public function lists() @@ -107,7 +107,7 @@ class Article extends Base * @throws DataNotFoundException * @throws DbException * @throws ModelNotFoundException - * @author 李玉坤 + * @author 木子的忧伤 * @date 2021-10-29 0:17 */ public function detail() @@ -175,7 +175,7 @@ class Article extends Base * 创建评论 * @param Request $request * @return mixed - * @author 李玉坤 + * @author 木子的忧伤 * @date 2021-10-17 19:13 */ public function create_comment(Request $request) @@ -220,7 +220,7 @@ class Article extends Base * @throws DataNotFoundException * @throws DbException * @throws ModelNotFoundException - * @author 李玉坤 + * @author 木子的忧伤 * @date 2021-10-29 0:19 */ public function tag() @@ -259,7 +259,7 @@ class Article extends Base * @throws DataNotFoundException * @throws DbException * @throws ModelNotFoundException - * @author 李玉坤 + * @author 木子的忧伤 * @date 2021-10-29 0:18 */ public function search() @@ -295,7 +295,7 @@ class Article extends Base * 用户首页 * @return string * @throws Exception - * @author 李玉坤 + * @author 木子的忧伤 * @date 2022-01-24 1:23 */ public function user() diff --git a/app/index/controller/Base.php b/app/index/controller/Base.php index 48d3574..3e4ef31 100644 --- a/app/index/controller/Base.php +++ b/app/index/controller/Base.php @@ -68,7 +68,7 @@ class Base extends BaseController /** * url 统计 * @param $title - * @author 李玉坤 + * @author 木子的忧伤 * @date 2021-05-09 23:44 */ protected function urlrecord($title) diff --git a/app/index/controller/Index.php b/app/index/controller/Index.php index 9674cba..dbe28b8 100644 --- a/app/index/controller/Index.php +++ b/app/index/controller/Index.php @@ -46,7 +46,7 @@ class Index extends Base * @throws DataNotFoundException * @throws DbException * @throws ModelNotFoundException - * @author 李玉坤 + * @author 木子的忧伤 * @date 2021-10-17 1:03 */ public function applylink(Request $request) @@ -91,7 +91,7 @@ class Index extends Base * @throws DataNotFoundException * @throws DbException * @throws ModelNotFoundException - * @author 李玉坤 + * @author 木子的忧伤 * @date 2021-10-17 1:03 */ public function msg(Request $request) @@ -123,64 +123,4 @@ class Index extends Base return $this->fetch(); } } - - /** - * 关于页面 - * @param Request $request - * @author 李玉坤 - * @date 2022-06-21 23:48 - */ - public function about(Request $request) - { - $id = "about"; - //获取该文章 - $documentModel = new Document(); - $article = $documentModel->where('status', 1)->where('id|alias', $id)->find(); - if (!$article) { - $this->error('文章不存在或已删除!'); - } - $article = $article->toArray(); - //根据分类id找分类信息 - $dc = get_document_category($article['category_id']); - if (!$dc) { - $this->error('栏目不存在或已删除!'); - } - //获取该文章内容 - //根据文章类型,加载不同的内容。 - $articleType = $article['type'] ? $article['type'] : 'article'; - $articleExt = $documentModel::name('document_' . $articleType)->where('id', $article['id'])->find(); - if (!$articleExt) { - $this->error('文章不存在或已删除!'); - } - $articleExt = $articleExt->toArray(); - $article = array_merge($article, $articleExt); - //添加当前页面的位置信息 - $article['position'] = tpl_get_position($dc); - //更新浏览次数 - $documentModel->where('id', $article['id'])->inc('view')->update(); - $templateFile = config('view.view_path') . 'article/' . $articleType . '.html'; - if (!is_file($templateFile)) { - $this->error('模板文件不存在!'); - } - $article['category_title'] = $dc['title']; - //判断SEO 为空则取系统 - $article['keywords'] = $article['keywords'] ?: web_config('keywords'); - $article['description'] = $article['description'] ?: web_config('description'); - //输出文章内容 - $this->assign('apeField', $article); - $this->assign('id', $id); - //当前页面所属分类id - $this->assign('cid', $article['category_id']); - //缓存当前页面栏目分类树ids - cache(Data::CURR_CATEGORY_PATENT_ID, $dc['pid'] ? $dc['pid'] . ',' . $article['category_id'] : $article['category_id']); - //设置文章的url - $article['link_str'] = make_detail_url($article); - //判断后台统计配置是否开启 1 开启 - if (web_config("web_statistics") == 1) { - //统计url - $this->urlrecord($article['title']); - } - Log::info('详情页模板路径:' . $templateFile); - return $this->fetch('article/' . $articleType); - } } \ No newline at end of file diff --git a/app/index/controller/Page.php b/app/index/controller/Page.php index b37ecd3..6a346a4 100644 --- a/app/index/controller/Page.php +++ b/app/index/controller/Page.php @@ -30,7 +30,7 @@ class Page extends Base * @throws DataNotFoundException * @throws DbException * @throws ModelNotFoundException - * @author 李玉坤 + * @author 木子的忧伤 * @date 2021-10-29 0:17 */ public function lists() @@ -107,7 +107,7 @@ class Page extends Base * @throws DataNotFoundException * @throws DbException * @throws ModelNotFoundException - * @author 李玉坤 + * @author 木子的忧伤 * @date 2021-10-29 0:17 */ public function detail() @@ -171,7 +171,7 @@ class Page extends Base * 创建评论 * @param Request $request * @return mixed - * @author 李玉坤 + * @author 木子的忧伤 * @date 2021-10-17 19:13 */ public function create_comment(Request $request) @@ -216,7 +216,7 @@ class Page extends Base * @throws DataNotFoundException * @throws DbException * @throws ModelNotFoundException - * @author 李玉坤 + * @author 木子的忧伤 * @date 2021-10-29 0:19 */ public function tag() @@ -252,7 +252,7 @@ class Page extends Base /** * 标签列表 * @return mixed - * @author 李玉坤 + * @author 木子的忧伤 * @date 2021-11-11 0:27 */ public function tagList() @@ -274,7 +274,7 @@ class Page extends Base * @throws DataNotFoundException * @throws DbException * @throws ModelNotFoundException - * @author 李玉坤 + * @author 木子的忧伤 * @date 2021-10-29 0:18 */ public function search() @@ -310,7 +310,7 @@ class Page extends Base * 用户首页 * @return string * @throws Exception - * @author 李玉坤 + * @author 木子的忧伤 * @date 2022-01-24 1:23 */ public function user() @@ -342,4 +342,64 @@ class Page extends Base } return $this->fetch(); } + + /** + * 关于页面 + * @param Request $request + * @author 木子的忧伤 + * @date 2022-06-21 23:48 + */ + public function about(Request $request) + { + $id = "about"; + //获取该文章 + $documentModel = new Document(); + $article = $documentModel->where('status', 1)->where('id|alias', $id)->find(); + if (!$article) { + $this->error('文章不存在或已删除!'); + } + $article = $article->toArray(); + //根据分类id找分类信息 + $dc = get_document_category($article['category_id']); + if (!$dc) { + $this->error('栏目不存在或已删除!'); + } + //获取该文章内容 + //根据文章类型,加载不同的内容。 + $articleType = Document::DOCUMENT_TYPE_PAGE; + $articleExt = $documentModel::name('document_' . $articleType)->where('id', $article['id'])->find(); + if (!$articleExt) { + $this->error('文章不存在或已删除!'); + } + $articleExt = $articleExt->toArray(); + $article = array_merge($article, $articleExt); + //添加当前页面的位置信息 + $article['position'] = tpl_get_position($dc); + //更新浏览次数 + $documentModel->where('id', $article['id'])->inc('view')->update(); + $templateFile = config('view.view_path') . 'article/' . $articleType . '.html'; + if (!is_file($templateFile)) { + $this->error('模板文件不存在!'); + } + $article['category_title'] = $dc['title']; + //判断SEO 为空则取系统 + $article['keywords'] = $article['keywords'] ?: web_config('keywords'); + $article['description'] = $article['description'] ?: web_config('description'); + //输出文章内容 + $this->assign('apeField', $article); + $this->assign('id', $id); + //当前页面所属分类id + $this->assign('cid', $article['category_id']); + //缓存当前页面栏目分类树ids + cache(Data::CURR_CATEGORY_PATENT_ID, $dc['pid'] ? $dc['pid'] . ',' . $article['category_id'] : $article['category_id']); + //设置文章的url + $article['link_str'] = make_detail_url($article); + //判断后台统计配置是否开启 1 开启 + if (web_config("web_statistics") == 1) { + //统计url + $this->urlrecord($article['title']); + } + Log::info('详情页模板路径:' . $templateFile); + return $this->fetch('article/' . $articleType); + } } \ No newline at end of file diff --git a/app/index/controller/User.php b/app/index/controller/User.php index c7b1232..c3a4ca5 100644 --- a/app/index/controller/User.php +++ b/app/index/controller/User.php @@ -1,6 +1,6 @@