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 @@
-
-
@@ -211,7 +213,7 @@ switch (item.name) { case 'title': if (!item.value) { - throw "页面名称不能为空"; + throw "文章名称不能为空"; } break; case 'cover_path': @@ -230,11 +232,11 @@ if (!checkResult) { return false; } - $.post(url = "/admin/article/save", $('.add-form').serialize(), function (res) { + $.post(url = "/admin/page/save", $('.add-form').serialize(), function (res) { if (res.code == 200) { lightyear.notify(res.msg, 'success', 3000, 'mdi mdi-emoticon-happy', 'top', 'center'); setTimeout(function () { - location.href = '/admin/article/index'; + location.href = '/admin/page/index'; }, 2000) } else lightyear.notify(res.msg, 'danger', 3000, 'mdi mdi-emoticon-happy', 'top', 'center'); }); diff --git a/app/admin/view/page/edit.html b/app/admin/view/page/edit.html index 1dcb163..a7d0338 100644 --- a/app/admin/view/page/edit.html +++ b/app/admin/view/page/edit.html @@ -12,13 +12,16 @@
-
-
@@ -224,11 +226,6 @@ $.each(Arr, function (index, item) { try { switch (item.name) { - case 'category_id': - if (!item.value) { - throw "栏目分类不能为空"; - } - break; case 'title': if (!item.value) { throw "文章名称不能为空"; @@ -250,11 +247,11 @@ if (!checkResult) { return false; } - $.post(url = "/admin/article/save", $('.add-form').serialize(), function (res) { + $.post(url = "/admin/page/save", $('.add-form').serialize(), function (res) { if (res.code == 200) { lightyear.notify(res.msg, 'success', 3000, 'mdi mdi-emoticon-happy', 'top', 'center'); setTimeout(function () { - location.href = '/admin/article/index'; + location.href = '/admin/page/index'; }, 2000) } else lightyear.notify(res.msg, 'danger', 3000, 'mdi mdi-emoticon-happy', 'top', 'center'); }); diff --git a/app/admin/view/page/index.html b/app/admin/view/page/index.html index 0f16a31..73f9c7d 100644 --- a/app/admin/view/page/index.html +++ b/app/admin/view/page/index.html @@ -202,7 +202,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 +234,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/system_config/list.html b/app/admin/view/system_config/list.html index abb4263..3df9fb0 100644 --- a/app/admin/view/system_config/list.html +++ b/app/admin/view/system_config/list.html @@ -10,7 +10,14 @@
-

{$tab.name}

+
+

{$tab.name}

+
    +
  • + +
  • +
+