From 0bd6676770e28cc7621eff3d0b26b95aab27f62d Mon Sep 17 00:00:00 2001 From: muzi_ys <1099438829@qq.com> Date: Sat, 9 Jul 2022 20:04:08 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=AD=A3=E6=96=87=E7=AB=A0=E5=88=A0?= =?UTF-8?q?=E9=99=A4=E5=92=8C=E5=8D=95=E9=A1=B5=E9=9D=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/admin/controller/Article.php | 22 +++++++++++++++-- app/admin/controller/Page.php | 33 +++++++++++++++++++------- app/admin/view/article/index.html | 7 ++++-- app/admin/view/page/add.html | 20 +++++++++------- app/admin/view/page/edit.html | 25 +++++++++---------- app/admin/view/page/index.html | 4 ++-- app/admin/view/system_config/list.html | 9 ++++++- app/common/model/Document.php | 2 +- config/filesystem.php | 4 ++-- 9 files changed, 84 insertions(+), 42 deletions(-) diff --git a/app/admin/controller/Article.php b/app/admin/controller/Article.php index 793ce4b..91bcbf7 100644 --- a/app/admin/controller/Article.php +++ b/app/admin/controller/Article.php @@ -2,9 +2,9 @@ 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\DocumentPage; use app\common\model\Tag as TagModel; use app\common\model\DocumentArticle; use app\common\model\Comment as CommentModel; @@ -14,6 +14,7 @@ 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; /** @@ -24,6 +25,16 @@ use think\facade\Log; */ class Article extends AuthController { + /** + * 构造方法 初始化一些参数 + */ + public function initialize() + { + parent::initialize(); + //修正因为修改model名称和原来不能对应导致的model功能异常 + $this->model = new Document(); + } + /** * 文章管理主页 * @return string @@ -53,6 +64,7 @@ class Article extends AuthController ['page', 1], ['limit', 20], ]); + $where['type'] = Document::DOCUMENT_TYPE_ARTICLE; return app("json")->layui(aModel::systemPage($where)); } @@ -70,7 +82,7 @@ class Article extends AuthController ['author', ''], ['title', ''], ['alias', ''], - ['category_id', ''], + ['category_id', 0], ['type', 'article'], ['abstract', ''], ['keywords', ''], @@ -107,6 +119,8 @@ class Article extends AuthController 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']; @@ -147,11 +161,15 @@ class Article extends AuthController $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); } diff --git a/app/admin/controller/Page.php b/app/admin/controller/Page.php index d4ba6f8..584c2f0 100644 --- a/app/admin/controller/Page.php +++ b/app/admin/controller/Page.php @@ -2,18 +2,17 @@ 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\DocumentPage; 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; use think\db\exception\ModelNotFoundException; use think\Exception; +use think\facade\Db; use think\facade\Log; /** @@ -24,6 +23,17 @@ use think\facade\Log; */ class Page extends AuthController { + + /** + * 构造方法 初始化一些参数 + */ + public function initialize() + { + parent::initialize(); + //修正因为修改model名称和原来不能对应导致的model功能异常 + $this->model = new Document(); + } + /** * 文章管理主页 * @return string @@ -71,10 +81,10 @@ class Page extends AuthController ['author', ''], ['title', ''], ['alias', ''], - ['category_id', ''], ['type', 'page'], ['abstract', ''], ['keywords', ''], + ['category_id', 0], ['content', ''], ['description', ''], ['is_recommend', 0], @@ -89,7 +99,6 @@ class Page extends AuthController ]); 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 { @@ -108,6 +117,8 @@ class Page extends AuthController 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']; @@ -120,7 +131,7 @@ class Page extends AuthController 'id' => $id, 'content' => $content ]; - DocumentArticle::insert($updateData); + DocumentPage::insert($updateData); } if (!empty($data['tags'])) { $tagModel = new TagModel(); @@ -131,16 +142,16 @@ class Page extends AuthController if (!$ainfo) return app("json")->fail("数据不存在"); aModel::where('id', $id)->save($data); if (!empty($content)) { - $contentInfo = DocumentArticle::where('id', $id)->find(); + $contentInfo = DocumentPage::where('id', $id)->find(); if (!$contentInfo) { $updateData = [ 'id' => $id, 'content' => $content ]; - DocumentArticle::insert($updateData); + DocumentPage:insert($updateData); } else { //更新文档 - DocumentArticle::where('id', $id)->save(['content' => $content]); + DocumentPage::where('id', $id)->save(['content' => $content]); } } if (!empty($data['tags'])) { @@ -148,11 +159,15 @@ class Page extends AuthController $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); } diff --git a/app/admin/view/article/index.html b/app/admin/view/article/index.html index df64645..0b12b86 100644 --- a/app/admin/view/article/index.html +++ b/app/admin/view/article/index.html @@ -91,6 +91,9 @@ }, { field: 'title', title: '标题' + }, { + field: 'alias', + title: 'URL名称' }, { field: 'category_title', title: '分类', @@ -202,7 +205,7 @@ text: '确认', btnClass: 'btn-danger', action: function () { - $.post("/admin/admin_log/del", data = {id: id}, function (res) { + $.post("/admin/article/del", data = {id: id}, function (res) { if (res.status == 200 || res.code == 200) lightyear.notify(res.msg, 'success', 3000, 'mdi mdi-emoticon-happy', 'top', 'center'); else lightyear.notify(res.msg, 'danger', 3000, 'mdi mdi-emoticon-neutral', 'top', 'center'); location.reload(); @@ -234,7 +237,7 @@ text: '确认', btnClass: 'btn-danger', action: function () { - $.post("/admin/admin_log/del", data = {id: checkID}, function (res) { + $.post("/admin/article/del", data = {id: checkID}, function (res) { if (res.status == 200 || res.code == 200) { lightyear.notify(res.msg, 'success', 3000, 'mdi mdi-emoticon-happy', 'top', 'center'); location.reload(); diff --git a/app/admin/view/page/add.html b/app/admin/view/page/add.html index 7cb647b..b05e7cb 100644 --- a/app/admin/view/page/add.html +++ b/app/admin/view/page/add.html @@ -12,12 +12,15 @@