修正词云

修正文章编辑
This commit is contained in:
muzi_ys 2022-07-14 00:13:21 +08:00
parent 8cd129e663
commit 8c4117153a
6 changed files with 95 additions and 114 deletions

View File

@ -38,63 +38,4 @@ class Index extends AuthController
$this->assign('cid', false); $this->assign('cid', false);
return $this->fetch(); 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));
}
} }

View File

@ -3,14 +3,13 @@
namespace app\common\model; namespace app\common\model;
use app\common\constant\Data;
use app\common\model\Tag as TagModel; use app\common\model\Tag as TagModel;
use think\db\exception\DataNotFoundException; use think\db\exception\DataNotFoundException;
use think\db\exception\DbException; use think\db\exception\DbException;
use app\common\constant\Data;
use think\db\exception\ModelNotFoundException; use think\db\exception\ModelNotFoundException;
use think\facade\Db; use think\facade\Db;
use think\facade\Log; use think\facade\Log;
use think\Model;
/** /**
* Class Document * Class Document
@ -33,7 +32,7 @@ class Document extends BaseModel
public static function systemPage($where): array public static function systemPage($where): array
{ {
$model = new self; $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['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['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")); 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); $count = self::counts($model);
if ($where['page'] && $where['limit']) $model = $model->page((int)$where['page'], (int)$where['limit']); if ($where['page'] && $where['limit']) $model = $model->page((int)$where['page'], (int)$where['limit']);
$categoryList = DocumentCategory::column('title', 'id'); $categoryList = DocumentCategory::column('title', 'id');
$data = $model->select()->each(function ($item) use($categoryList) { $data = $model->select()->each(function ($item) use ($categoryList) {
$item->category_title = $categoryList[$item->category_id]??""; $item->category_title = $categoryList[$item->category_id] ?? "";
}); });
return compact('data', 'count'); return compact('data', 'count');
} }
@ -55,32 +54,32 @@ class Document extends BaseModel
* @param string $status * @param string $status
* @return array * @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 []; return [];
} }
$model = self::alias('a')->field("a.*,p.content"); $model = self::alias('a')->field("a.*,p.content");
if (is_numeric($id)){ if (is_numeric($id)) {
$model->where("a.id",$id); $model->where("a.id", $id);
}else{ } else {
$model->where("a.alias",$id); $model->where("a.alias", $id);
} }
if ($type !=='') $model->where("a.type",$type); if ($type !== '') $model->where("a.type", $type);
if ($status !=='')$model->where("a.status",$status); if ($status !== '') $model->where("a.status", $status);
switch ($type){ switch ($type) {
case Data::DOCUMENT_TYPE_ARTICLE: case Data::DOCUMENT_TYPE_ARTICLE:
$model->leftJoin('document_article p','a.id = p.id'); $model->leftJoin('document_article p', 'a.id = p.id');
break; break;
case Data::DOCUMENT_TYPE_PAGE: case Data::DOCUMENT_TYPE_PAGE:
$model->leftJoin('document_page p','a.id = p.id'); $model->leftJoin('document_page p', 'a.id = p.id');
break; break;
case Data::DOCUMENT_TYPE_PRODUCT: case Data::DOCUMENT_TYPE_PRODUCT:
$model->leftJoin('document_product p','a.id = p.id'); $model->leftJoin('document_product p', 'a.id = p.id');
break; break;
} }
$info = $model->find(); $info = $model->find();
if (!$info){ if (!$info) {
return []; return [];
} }
return $info->toArray(); return $info->toArray();
@ -94,10 +93,18 @@ class Document extends BaseModel
* @throws DbException * @throws DbException
* @throws ModelNotFoundException * @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 { try {
$content = !empty($data['content'])?$data['content']:''; $content = !empty($data['content']) ? $data['content'] : '';
//判断摘要是否为空,为空则从内容摘取 //判断摘要是否为空,为空则从内容摘取
$data['abstract'] = $data['abstract'] ?: mb_substr(strip_tags($content), 0, 100); $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['display']) $data['display'] = 1;
if ($data['is_top']) $data['is_top'] = 1; if ($data['is_top']) $data['is_top'] = 1;
//判断是否主键冲突 //判断是否主键冲突
$info = $this->where("alias",$data['alias'])->find(); $info = $this->where("alias", $data['alias'])->find();
if ($info && (!empty($data['id']) && $info->id != $data['id'] )){ if ($info && (!empty($data['id']) && $info->id != $data['id'])) {
self::setErrorInfo("别名已存在,请修改后重试"); self::setErrorInfo("别名已存在,请修改后重试");
return false; return false;
} }
@ -129,12 +136,12 @@ class Document extends BaseModel
} }
if (!empty($data['tags'])) { if (!empty($data['tags'])) {
$tagModel = new TagModel(); $tagModel = new TagModel();
$tagModel->createTags($data['tags'], $id, $data['uid']); $tagModel->createTags($data['tags'], $id, $data['uid']);
} }
} else { } else {
$ainfo = Document::get($data['id']); $ainfo = Document::get($data['id']);
if (!$ainfo) return app("json")->fail("数据不存在"); if (!$ainfo) return app("json")->fail("数据不存在");
Document::where('id', $data['id'])->save($data); Document::where('id', $data['id'])->update($data);
if (!empty($content)) { if (!empty($content)) {
switch ($type) { switch ($type) {
case Data::DOCUMENT_TYPE_ARTICLE: case Data::DOCUMENT_TYPE_ARTICLE:
@ -143,7 +150,6 @@ class Document extends BaseModel
'content' => $content 'content' => $content
]; ];
$model = new DocumentArticle(); $model = new DocumentArticle();
$model->save($updateData);
break; break;
case Data::DOCUMENT_TYPE_PAGE: case Data::DOCUMENT_TYPE_PAGE:
$updateData = [ $updateData = [
@ -151,14 +157,20 @@ class Document extends BaseModel
'content' => $content 'content' => $content
]; ];
$model = new DocumentPage(); $model = new DocumentPage();
$model->save($updateData);
break; break;
case Data::DOCUMENT_TYPE_PRODUCT; case Data::DOCUMENT_TYPE_PRODUCT;
$mode = new DocumentProduct();
break; break;
default: default:
//默认暂时不处理 //默认暂时不处理
break; break;
} }
$info = $model->find($data['id']);
if (!$info) {
$model->insert($updateData);
} else {
$model->update($updateData);
}
} }
if (!empty($data['tags'])) { if (!empty($data['tags'])) {
$tagModel = new TagModel(); $tagModel = new TagModel();

View File

@ -36,8 +36,7 @@ class Tag extends BaseModel
if ($where['end_time'] != '') $model = $model->where("create_time", "<", strtotime($where['end_time'] . " 23:59:59")); if ($where['end_time'] != '') $model = $model->where("create_time", "<", strtotime($where['end_time'] . " 23:59:59"));
$count = self::counts($model); $count = self::counts($model);
if ($where['page'] && $where['limit']) $model = $model->page((int)$where['page'], (int)$where['limit']); 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(); if ($data) $data = $data->toArray();
return compact('data', 'count'); return compact('data', 'count');
} }
@ -84,17 +83,18 @@ class Tag extends BaseModel
public static function getList($where): array public static function getList($where): array
{ {
$list = cache('index:tagList'); $list = cache('index:tagList');
$list = false;
if ($list) { if ($list) {
return json_decode($list, true); return json_decode($list, true);
} else { } else {
$tagList = self::systemPage($where); $model = new self();
$list = []; if ($where['name'] != '') $model = $model->where("title|url", "like", "%$where[name]%");
foreach ($tagList['data'] as $tag) { $model = $model->field('distinct name,count(1) as num')->order("num DESC")->group("name");
$list[] = [ if ($where['page'] && $where['limit']) $model = $model->page((int)$where['page'], (int)$where['limit']);
"text" => $tag['name'], $list = $model->select()->each(function (&$tag) {
"href" => url("/index/article/tag?t=" . $tag['name'])->build() $tag->text = $tag['name'];
]; $tag->href = url("/index/article/tag?t=" . $tag['name'])->build();
} })->toArray();
if ($list) { if ($list) {
cache('index:tagList', json_encode($list), 24 * 60 * 60); cache('index:tagList', json_encode($list), 24 * 60 * 60);
} }

View File

@ -7,6 +7,7 @@ use app\common\constant\Data;
use app\common\model\Document; use app\common\model\Document;
use app\common\model\FriendLink as friendLinkModel; use app\common\model\FriendLink as friendLinkModel;
use app\common\model\MessageForm as MessageFormModel; use app\common\model\MessageForm as MessageFormModel;
use app\common\model\Tag as TagModel;
use app\common\validate\MessageForm as MessageformValidate; use app\common\validate\MessageForm as MessageformValidate;
use app\Request; use app\Request;
use think\db\exception\DataNotFoundException; use think\db\exception\DataNotFoundException;
@ -170,4 +171,20 @@ class Index extends Base
$template = substr($template, 0, strpos($template, '.')); $template = substr($template, 0, strpos($template, '.'));
return $this->fetch($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));
}
} }

File diff suppressed because one or more lines are too long

View File

@ -208,7 +208,7 @@
} }
</style> </style>
<script> <script>
$.get("{:url('/index/article/taglist')}",function(data,status){ $.get("{:url('/index/index/taglist')}",function(data,status){
TagCloud( TagCloud(
".corepress-tag-container-tag1", ".corepress-tag-container-tag1",
data.data, data.data,