mirror of https://github.com/1099438829/apeblog
parent
8cd129e663
commit
8c4117153a
|
|
@ -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));
|
||||
}
|
||||
}
|
||||
|
|
@ -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;
|
||||
}
|
||||
|
|
@ -134,7 +141,7 @@ class Document extends BaseModel
|
|||
} 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();
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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));
|
||||
}
|
||||
}
|
||||
File diff suppressed because one or more lines are too long
|
|
@ -208,7 +208,7 @@
|
|||
}
|
||||
</style>
|
||||
<script>
|
||||
$.get("{:url('/index/article/taglist')}",function(data,status){
|
||||
$.get("{:url('/index/index/taglist')}",function(data,status){
|
||||
TagCloud(
|
||||
".corepress-tag-container-tag1",
|
||||
data.data,
|
||||
|
|
|
|||
Loading…
Reference in New Issue