From 19c801c92d732df3b3278c51028e5a74daa6db7a Mon Sep 17 00:00:00 2001 From: liyukun <1099438829@qq.com> Date: Mon, 11 Apr 2022 18:37:11 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=AD=A3=E5=88=AB=E5=90=8D=E9=97=AE?= =?UTF-8?q?=E9=A2=98=E5=AF=BC=E8=87=B4=E7=9A=84bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/admin/controller/Article.php | 3 +++ app/admin/controller/Category.php | 8 ++++---- app/admin/view/article/add.html | 5 +++++ app/admin/view/article/edit.html | 5 +++++ app/common.php | 19 +++++++++++++++++++ app/common/constant/Data.php | 2 +- 6 files changed, 37 insertions(+), 5 deletions(-) diff --git a/app/admin/controller/Article.php b/app/admin/controller/Article.php index 4934f17..1a3d4d3 100644 --- a/app/admin/controller/Article.php +++ b/app/admin/controller/Article.php @@ -68,6 +68,7 @@ class Article extends AuthController ['id', ''], ['author', ''], ['title', ''], + ['alias', ''], ['category_id', ''], ['type', 'article'], ['abstract', ''], @@ -97,6 +98,8 @@ class Article extends AuthController } //判断摘要是否为空,为空则从内容摘取 $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; diff --git a/app/admin/controller/Category.php b/app/admin/controller/Category.php index 046c404..5172361 100644 --- a/app/admin/controller/Category.php +++ b/app/admin/controller/Category.php @@ -72,9 +72,11 @@ class Category extends AuthController ]); 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 == "") { - $content = $data['content']; - unset($data['content']); $model = new aModel(); $id = $model->insert($data, true); $data = [ @@ -84,8 +86,6 @@ class Category extends AuthController $model = new DocumentCategoryContent(); $res = $model->save($data); } else { - $content = $data['content']; - unset($data['content']); $res = aModel::update($data, ['id' => $id]); if ($res) { $res = DocumentCategoryContent::update(['content' => $content], ['id' => $id]); diff --git a/app/admin/view/article/add.html b/app/admin/view/article/add.html index 90e346b..b97c365 100644 --- a/app/admin/view/article/add.html +++ b/app/admin/view/article/add.html @@ -27,6 +27,11 @@ +
+ + +
diff --git a/app/admin/view/article/edit.html b/app/admin/view/article/edit.html index 68e68d9..2700539 100644 --- a/app/admin/view/article/edit.html +++ b/app/admin/view/article/edit.html @@ -27,6 +27,11 @@
+
+ + +
diff --git a/app/common.php b/app/common.php index c1e92ea..6ee07f7 100644 --- a/app/common.php +++ b/app/common.php @@ -163,3 +163,22 @@ if (!function_exists('file_cdn')) { return (config("app.cdn_url")?:$server_url = server_url()) . $path; } } + +if (!function_exists('get_rand_str')) { + /** + * 生成随机字符串 + * @param $length + * @return string + * @author 李玉坤 + * @date 2022-04-11 18:26 + */ + function get_rand_str($length){ + //字符组合 + $str = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890'; + $randStr = str_shuffle($str);//打乱字符串 + $randstr= substr($randStr,0,$length);//substr(string,start,length);返回字符串的一部分 + $randstr = md5($randstr.time()); + $randstr = substr($randstr,5,$length); + return $randstr; + } +} \ No newline at end of file diff --git a/app/common/constant/Data.php b/app/common/constant/Data.php index abe7874..589b98f 100644 --- a/app/common/constant/Data.php +++ b/app/common/constant/Data.php @@ -12,7 +12,7 @@ class Data //缓存数据key const DATA_FRIEND_LINK = 'data_friend_link'; //友链 const DATA_DOCUMENT_CATEGORY_LIST = 'data_document_category_list'; //文章分类 - const CURR_CATEGORY_PATENT_ID = 'curr_category_patent_id'; //当前分类腹肌id + const CURR_CATEGORY_PATENT_ID = 'curr_category_patent_id'; //当前分类父级id const DATA_SYSTEM_CONFIG = 'data_system_config'; //系统配置 const DATA_ADVERT = 'data_advert'; //广告