diff --git a/app/api/controller/Index.php b/app/api/controller/Index.php index 3537969..5cabbc7 100644 --- a/app/api/controller/Index.php +++ b/app/api/controller/Index.php @@ -38,63 +38,4 @@ class Index extends AuthController $this->assign('cid', false); return $this->fetch(); } - - /** - * 留言页面 - * @param Request $request - * @return string - * @throws DataNotFoundException - * @throws DbException - * @throws ModelNotFoundException - * @author 木子的忧伤 - * @date 2021-10-17 1:03 - */ - public function msg(Request $request) - { - if (request()->isPost()) { - $data = Util::postMore([ - ['author', ''], - ['tel', ''], - ['email', ''], - ['content', ''], - ]); - $data['create_time'] = time(); - $messageFormValidate = new MessageFormValidate(); - if (!$messageFormValidate->check($data)) { - $this->error($messageFormValidate->getError()); - } - $res = MessageFormModel::create($data); - if ($res) { - $this->success('留言成功'); - } else { - $this->error('留言失败'); - } - } else { - //清除可能存在的栏目分类树id - cache(Data::CURR_CATEGORY_PATENT_ID, false); - //模板兼容性标签 - $this->assign('id', false); - $this->assign('cid', false); - return $this->fetch(); - } - } - - /** - * 标签列表 - * @return mixed - * @author 木子的忧伤 - * @date 2021-11-11 0:27 - */ - public function tagList() - { - $where = Util::postMore([ - ['name', ''], - ['document_id', ''], - ['start_time', ''], - ['end_time', ''], - ['page', 1], - ['limit', 10] - ]); - return app("json")->layui(TagModel::getList($where)); - } } \ No newline at end of file diff --git a/app/common/model/Document.php b/app/common/model/Document.php index 4e17e27..6f4ea73 100644 --- a/app/common/model/Document.php +++ b/app/common/model/Document.php @@ -3,14 +3,13 @@ namespace app\common\model; +use app\common\constant\Data; use app\common\model\Tag as TagModel; use think\db\exception\DataNotFoundException; use think\db\exception\DbException; -use app\common\constant\Data; use think\db\exception\ModelNotFoundException; use think\facade\Db; use think\facade\Log; -use think\Model; /** * Class Document @@ -33,7 +32,7 @@ class Document extends BaseModel public static function systemPage($where): array { $model = new self; - $model = $model->where("type", "=",$where['type']??Data::DOCUMENT_TYPE_ARTICLE); + $model = $model->where("type", "=", $where['type'] ?? Data::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")); @@ -42,8 +41,8 @@ class Document extends BaseModel $count = self::counts($model); if ($where['page'] && $where['limit']) $model = $model->page((int)$where['page'], (int)$where['limit']); $categoryList = DocumentCategory::column('title', 'id'); - $data = $model->select()->each(function ($item) use($categoryList) { - $item->category_title = $categoryList[$item->category_id]??""; + $data = $model->select()->each(function ($item) use ($categoryList) { + $item->category_title = $categoryList[$item->category_id] ?? ""; }); return compact('data', 'count'); } @@ -55,32 +54,32 @@ class Document extends BaseModel * @param string $status * @return array */ - public function getInfo($id, string $type= Data::DOCUMENT_TYPE_ARTICLE, $status = 1): array + public function getInfo($id, string $type = Data::DOCUMENT_TYPE_ARTICLE, $status = 1): array { - if (empty($id)){ + if (empty($id)) { return []; } $model = self::alias('a')->field("a.*,p.content"); - if (is_numeric($id)){ - $model->where("a.id",$id); - }else{ - $model->where("a.alias",$id); + 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); - switch ($type){ + if ($type !== '') $model->where("a.type", $type); + if ($status !== '') $model->where("a.status", $status); + switch ($type) { case Data::DOCUMENT_TYPE_ARTICLE: - $model->leftJoin('document_article p','a.id = p.id'); + $model->leftJoin('document_article p', 'a.id = p.id'); break; case Data::DOCUMENT_TYPE_PAGE: - $model->leftJoin('document_page p','a.id = p.id'); + $model->leftJoin('document_page p', 'a.id = p.id'); break; case Data::DOCUMENT_TYPE_PRODUCT: - $model->leftJoin('document_product p','a.id = p.id'); + $model->leftJoin('document_product p', 'a.id = p.id'); break; } $info = $model->find(); - if (!$info){ + if (!$info) { return []; } return $info->toArray(); @@ -94,10 +93,18 @@ class Document extends BaseModel * @throws DbException * @throws ModelNotFoundException */ - public function updateInfo($data, string $type=Data::DOCUMENT_TYPE_ARTICLE) + /** + * 更新文件信息 + * @param $dat + * @param string $type + * @throws DataNotFoundException + * @throws DbException + * @throws ModelNotFoundException + */ + public function updateInfo($data, string $type = Data::DOCUMENT_TYPE_ARTICLE) { try { - $content = !empty($data['content'])?$data['content']:''; + $content = !empty($data['content']) ? $data['content'] : ''; //判断摘要是否为空,为空则从内容摘取 $data['abstract'] = $data['abstract'] ?: mb_substr(strip_tags($content), 0, 100); //判断是否写了别名,没写则需要生成 @@ -108,8 +115,8 @@ class Document extends BaseModel if ($data['display']) $data['display'] = 1; if ($data['is_top']) $data['is_top'] = 1; //判断是否主键冲突 - $info = $this->where("alias",$data['alias'])->find(); - if ($info && (!empty($data['id']) && $info->id != $data['id'] )){ + $info = $this->where("alias", $data['alias'])->find(); + if ($info && (!empty($data['id']) && $info->id != $data['id'])) { self::setErrorInfo("别名已存在,请修改后重试"); return false; } @@ -129,12 +136,12 @@ class Document extends BaseModel } if (!empty($data['tags'])) { $tagModel = new TagModel(); - $tagModel->createTags($data['tags'], $id, $data['uid']); + $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); + Document::where('id', $data['id'])->update($data); if (!empty($content)) { switch ($type) { case Data::DOCUMENT_TYPE_ARTICLE: @@ -143,7 +150,6 @@ class Document extends BaseModel 'content' => $content ]; $model = new DocumentArticle(); - $model->save($updateData); break; case Data::DOCUMENT_TYPE_PAGE: $updateData = [ @@ -151,14 +157,20 @@ class Document extends BaseModel 'content' => $content ]; $model = new DocumentPage(); - $model->save($updateData); break; case Data::DOCUMENT_TYPE_PRODUCT; + $mode = new DocumentProduct(); break; default: //默认暂时不处理 break; } + $info = $model->find($data['id']); + if (!$info) { + $model->insert($updateData); + } else { + $model->update($updateData); + } } if (!empty($data['tags'])) { $tagModel = new TagModel(); diff --git a/app/common/model/Tag.php b/app/common/model/Tag.php index a6970f0..81f0b84 100644 --- a/app/common/model/Tag.php +++ b/app/common/model/Tag.php @@ -36,8 +36,7 @@ class Tag extends BaseModel if ($where['end_time'] != '') $model = $model->where("create_time", "<", strtotime($where['end_time'] . " 23:59:59")); $count = self::counts($model); if ($where['page'] && $where['limit']) $model = $model->page((int)$where['page'], (int)$where['limit']); - $data = $model->select()->each(function ($item) { - }); + $data = $model->select(); if ($data) $data = $data->toArray(); return compact('data', 'count'); } @@ -84,17 +83,18 @@ class Tag extends BaseModel public static function getList($where): array { $list = cache('index:tagList'); + $list = false; if ($list) { return json_decode($list, true); } else { - $tagList = self::systemPage($where); - $list = []; - foreach ($tagList['data'] as $tag) { - $list[] = [ - "text" => $tag['name'], - "href" => url("/index/article/tag?t=" . $tag['name'])->build() - ]; - } + $model = new self(); + if ($where['name'] != '') $model = $model->where("title|url", "like", "%$where[name]%"); + $model = $model->field('distinct name,count(1) as num')->order("num DESC")->group("name"); + if ($where['page'] && $where['limit']) $model = $model->page((int)$where['page'], (int)$where['limit']); + $list = $model->select()->each(function (&$tag) { + $tag->text = $tag['name']; + $tag->href = url("/index/article/tag?t=" . $tag['name'])->build(); + })->toArray(); if ($list) { cache('index:tagList', json_encode($list), 24 * 60 * 60); } diff --git a/app/index/controller/Index.php b/app/index/controller/Index.php index c26e97c..0af92b2 100644 --- a/app/index/controller/Index.php +++ b/app/index/controller/Index.php @@ -7,6 +7,7 @@ use app\common\constant\Data; use app\common\model\Document; use app\common\model\FriendLink as friendLinkModel; use app\common\model\MessageForm as MessageFormModel; +use app\common\model\Tag as TagModel; use app\common\validate\MessageForm as MessageformValidate; use app\Request; use think\db\exception\DataNotFoundException; @@ -170,4 +171,20 @@ class Index extends Base $template = substr($template, 0, strpos($template, '.')); return $this->fetch($template); } + + /** + * 标签列表 + * @return mixed + * @author 木子的忧伤 + * @date 2021-11-11 0:27 + */ + public function tagList() + { + $where = Util::postMore([ + ['name', ''], + ['page', 1], + ['limit', 10] + ]); + return app("json")->layui(TagModel::getList($where)); + } } \ No newline at end of file diff --git a/public/install/ape_blog.sql b/public/install/ape_blog.sql index 3ac883d..d9862eb 100644 --- a/public/install/ape_blog.sql +++ b/public/install/ape_blog.sql @@ -11,7 +11,7 @@ Target Server Version : 50726 File Encoding : 65001 - Date: 10/07/2022 22:13:47 + Date: 14/07/2022 00:12:43 */ SET NAMES utf8mb4; @@ -277,7 +277,7 @@ CREATE TABLE `ape_comment` ( `author` varchar(20) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL DEFAULT '' COMMENT '评论者姓名', `email` varchar(30) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL DEFAULT '' COMMENT '评论者邮箱', `url` varchar(40) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL DEFAULT '' COMMENT '评论者网站', - `content` varchar(200) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL DEFAULT '' COMMENT '评论者内容', + `content` varchar(200) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL DEFAULT '' COMMENT '评论者内容', `user_id` int(11) NOT NULL DEFAULT 0 COMMENT '评论者ID', `cover_path` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL DEFAULT '' COMMENT '评论头像地址', `pid` int(11) NOT NULL DEFAULT 0 COMMENT '评论谁', @@ -313,24 +313,25 @@ CREATE TABLE `ape_document` ( `display` tinyint(3) UNSIGNED NOT NULL DEFAULT 0 COMMENT '可见性', `view` int(10) UNSIGNED NOT NULL DEFAULT 0 COMMENT '浏览量', `tags` char(40) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL DEFAULT '' COMMENT '标识', - `abstract` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL DEFAULT '' COMMENT '摘要', - `keywords` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL DEFAULT '', - `description` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL DEFAULT '' COMMENT '描述', + `abstract` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL DEFAULT '' COMMENT '摘要', + `keywords` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL DEFAULT '', + `description` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL DEFAULT '' COMMENT '描述', `sort` int(10) NOT NULL DEFAULT 0 COMMENT '排序', `create_date` date NOT NULL COMMENT '创建日期', `create_time` int(10) UNSIGNED NOT NULL DEFAULT 0 COMMENT '创建时间', `update_time` int(10) UNSIGNED NOT NULL DEFAULT 0 COMMENT '更新时间', `status` tinyint(4) NOT NULL DEFAULT 0 COMMENT '数据状态', - `password` varchar(40) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL DEFAULT '' COMMENT '文章密码', + `password` varchar(40) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL DEFAULT '' COMMENT '文章密码', PRIMARY KEY (`id`) USING BTREE, UNIQUE INDEX `alias`(`alias`) USING BTREE, INDEX `idx_category_status`(`category_id`, `status`) USING BTREE, INDEX `idx_status_type_pid`(`status`, `uid`) USING BTREE -) ENGINE = InnoDB AUTO_INCREMENT = 1 CHARACTER SET = utf8mb4 COLLATE = utf8mb4_general_ci COMMENT = '文档模型基础表' ROW_FORMAT = DYNAMIC; +) ENGINE = InnoDB AUTO_INCREMENT = 2 CHARACTER SET = utf8mb4 COLLATE = utf8mb4_general_ci COMMENT = '文档模型基础表' ROW_FORMAT = DYNAMIC; -- ---------------------------- -- Records of ape_document -- ---------------------------- +INSERT INTO `ape_document` VALUES (1, 'about', 1, '超级管理员', '关于', 0, '/storage/image/20220710/4f392482c34a194fe8e7fb9b6da95ae9.png', 'page', 'article.html', 0, 0, 0, '', 1, 0, '', '源码云BLOG源码云博客是一款基于ThinkPHP6 + bootstrap+ MySql打造的,简单实用的开源免费的博客系统。各管理模块,操作简单,具有简约,易用,访问统计,内存占用低等特点,系统易', '', '', 99, '2022-07-10', 1657464554, 1657464554, 1, ''); -- ---------------------------- -- Table structure for ape_document_article @@ -338,7 +339,7 @@ CREATE TABLE `ape_document` ( DROP TABLE IF EXISTS `ape_document_article`; CREATE TABLE `ape_document_article` ( `id` int(10) UNSIGNED NOT NULL DEFAULT 0 COMMENT '文档ID', - `content` text CHARACTER SET utf8 COLLATE utf8_general_ci NULL COMMENT '文章内容', + `content` text CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL COMMENT '文章内容', PRIMARY KEY (`id`) USING BTREE ) ENGINE = InnoDB CHARACTER SET = utf8 COLLATE = utf8_general_ci COMMENT = '文档模型文章表' ROW_FORMAT = DYNAMIC; @@ -357,9 +358,9 @@ CREATE TABLE `ape_document_category` ( `icon` varchar(100) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL DEFAULT '' COMMENT '分类图标', `pid` int(10) NOT NULL DEFAULT 0 COMMENT '上级分类ID', `sort` int(10) UNSIGNED NOT NULL DEFAULT 0 COMMENT '排序(同级有效)', - `meta_title` varchar(50) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL DEFAULT '' COMMENT 'SEO的网页标题', - `keywords` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL DEFAULT '' COMMENT '关键字', - `description` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL DEFAULT '' COMMENT '描述', + `meta_title` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL DEFAULT '' COMMENT 'SEO的网页标题', + `keywords` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL DEFAULT '' COMMENT '关键字', + `description` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL DEFAULT '' COMMENT '描述', `status` tinyint(2) NOT NULL DEFAULT 1 COMMENT '是否显示', `template` varchar(50) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL DEFAULT '' COMMENT '分类模板', `view` int(10) NOT NULL DEFAULT 0 COMMENT '访问数', @@ -380,13 +381,14 @@ CREATE TABLE `ape_document_category` ( DROP TABLE IF EXISTS `ape_document_page`; CREATE TABLE `ape_document_page` ( `id` int(11) NOT NULL, - `content` text CHARACTER SET utf8 COLLATE utf8_general_ci NULL, + `content` text CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL, PRIMARY KEY (`id`) USING BTREE ) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_general_ci COMMENT = '分类内容表' ROW_FORMAT = DYNAMIC; -- ---------------------------- -- Records of ape_document_page -- ---------------------------- +INSERT INTO `ape_document_page` VALUES (1, '
系统后台集成了主流的通用功能,如:登录验证、系统配置、操作日志管理、用户(组)管理、用户(组)权限、功能管理(后台菜单管理)、导航设置、网站地图、轮播广告、TAG关键字管理、友情链接、文件上传、数据备份/还原、博客文章功能、用户管理、用户操作日志、用户注册/登录、博客归档、访问统计
支持模板机制等。更多的个性化功能可以基于当前博客系统便捷做二次开发。