mirror of https://github.com/1099438829/apeblog
修正文章删除和单页面
This commit is contained in:
parent
0450e84961
commit
0bd6676770
|
|
@ -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);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
|
|
|
|||
|
|
@ -12,12 +12,15 @@
|
|||
<div class="row">
|
||||
<div class="col-lg-12">
|
||||
<div class="card">
|
||||
<div class="card-body">
|
||||
<ul id="myTabs" class="nav nav-tabs" role="tablist">
|
||||
<li class="active"><a href="#home" id="home-tab" role="tab" data-toggle="tab">基本信息</a></li>
|
||||
<li class="tab-right"><a data-toggle="tooltip" data-original-title="返回" onclick="history.back(-1);return false;"><i class="mdi mdi-undo"></i></a></li>
|
||||
<div class="card-header">
|
||||
<h4>基本信息</h4>
|
||||
<ul class="card-actions">
|
||||
<li>
|
||||
<button type="button" data-toggle="tooltip" title="" data-original-title="返回" onclick="history.back(-1);return false;"><i class="mdi mdi-undo"></i></button>
|
||||
</li>
|
||||
</ul>
|
||||
<div id="myTabContent" class="tab-content">
|
||||
</div>
|
||||
<div class="card-body">
|
||||
<form action="#!" method="post" class="row add-form" onsubmit="return false;">
|
||||
<div class="form-group col-md-12">
|
||||
<label>页面名称</label>
|
||||
|
|
@ -99,7 +102,6 @@
|
|||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{include file="public/footer"/}
|
||||
<!--select2-->
|
||||
|
|
@ -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');
|
||||
});
|
||||
|
|
|
|||
|
|
@ -12,12 +12,15 @@
|
|||
<div class="row">
|
||||
<div class="col-lg-12">
|
||||
<div class="card">
|
||||
<div class="card-body">
|
||||
<ul id="myTabs" class="nav nav-tabs" role="tablist">
|
||||
<li class="active"><a href="#home" id="home-tab" role="tab" data-toggle="tab">基本信息</a></li>
|
||||
<li class="tab-right"><a data-toggle="tooltip" data-original-title="返回" onclick="history.back(-1);return false;"><i class="mdi mdi-undo"></i></a></li>
|
||||
<div class="card-header">
|
||||
<h4>基本信息</h4>
|
||||
<ul class="card-actions">
|
||||
<li>
|
||||
<button type="button" data-toggle="tooltip" title="" data-original-title="返回" onclick="history.back(-1);return false;"><i class="mdi mdi-undo"></i></button>
|
||||
</li>
|
||||
</ul>
|
||||
<div id="myTabContent" class="tab-content">
|
||||
</div>
|
||||
<div class="card-body">
|
||||
<form action="#!" method="post" class="row add-form" onsubmit="return false;">
|
||||
<div class="form-group col-md-12">
|
||||
<label>页面名称</label>
|
||||
|
|
@ -114,7 +117,6 @@
|
|||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{include file="public/footer"/}
|
||||
<!--select2-->
|
||||
|
|
@ -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');
|
||||
});
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
|
|
|
|||
|
|
@ -10,7 +10,14 @@
|
|||
<div class="row">
|
||||
<div class="col-lg-12">
|
||||
<div class="card">
|
||||
<div class="card-header"><h4>{$tab.name}</h4></div>
|
||||
<div class="card-header">
|
||||
<h4>{$tab.name}</h4>
|
||||
<ul class="card-actions">
|
||||
<li>
|
||||
<button type="button" data-toggle="tooltip" title="" data-original-title="返回" onclick="history.back(-1);return false;"><i class="mdi mdi-undo"></i></button>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
<div class="card-body">
|
||||
<div id="toolbar" class="toolbar-btn-action">
|
||||
<button id="btn_add" type="button" class="btn btn-primary m-r-5"
|
||||
|
|
|
|||
|
|
@ -33,7 +33,7 @@ class Document extends BaseModel
|
|||
public static function systemPage($where): array
|
||||
{
|
||||
$model = new self;
|
||||
$model = $model->where("type", "=",$where['type']?:self::DOCUMENT_TYPE_ARTICLE);
|
||||
$model = $model->where("type", "=",$where['type']??self::DOCUMENT_TYPE_ARTICLE);
|
||||
if ($where['title'] != '') $model = $model->where("title", "like", "%$where[title]%");
|
||||
if ($where['start_time'] != '') $model = $model->where("create_time", ">", strtotime($where['start_time'] . " 00:00:00"));
|
||||
if ($where['end_time'] != '') $model = $model->where("create_time", "<", strtotime($where['end_time'] . " 23:59:59"));
|
||||
|
|
|
|||
|
|
@ -13,9 +13,9 @@ return [
|
|||
// 磁盘类型
|
||||
'type' => 'local',
|
||||
// 磁盘路径
|
||||
'root' => app()->getRootPath() . 'public/storage',
|
||||
'root' => app()->getRootPath() . 'public/upload',
|
||||
// 磁盘路径对应的外部URL路径
|
||||
'url' => '/storage',
|
||||
'url' => '/upload',
|
||||
// 可见性
|
||||
'visibility' => 'public',
|
||||
],
|
||||
|
|
|
|||
Loading…
Reference in New Issue