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 @@