增加文章归档功能

This commit is contained in:
liyukun 2022-06-01 10:23:46 +08:00
parent 981f218fd1
commit c6f0e8b484
11 changed files with 304 additions and 22 deletions

View File

@ -89,6 +89,7 @@ class Article extends AuthController
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;
@ -108,6 +109,7 @@ class Article extends AuthController
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);
@ -147,9 +149,10 @@ class Article extends AuthController
$res = true;
} catch (Exception $e) {
Log::error('文章修改失败:失败原因:' . $e->getMessage());
$error = $e->getMessage();
$res = false;
}
return $res ? app("json")->success("操作成功", 'code') : app("json")->fail("操作失败");
return $res ? app("json")->success("操作成功", 'code') : app("json")->fail("操作失败,错误原因:".$error);
}

View File

@ -59,7 +59,7 @@
<li class="col-xs-4 col-sm-3 col-md-2" id="pic-upload">
<input type="hidden" class="form-control" name="cover_path" id="cover_path"
value=""/>
<input type="file" id="file_cover_path" style="display: none;"
<input type="file" id="file_cover_path" accept="image/*" style="display: none;"
onchange="upload('cover_path')"/>
<a class="pic-add" href="#!" onclick="btnClick('cover_path')"
title="上传"></a>

View File

@ -63,7 +63,7 @@
<li class="col-xs-4 col-sm-3 col-md-2" id="pic-upload" style="display: none;">
<input type="hidden" class="form-control" name="cover_path" id="cover_path"
value="{$info.cover_path}">
<input type="file" id="file_cover_path" style="display: none;"
<input type="file" id="file_cover_path" accept="image/*" style="display: none;"
onchange="upload('cover_path')">
<a class="pic-add" href="#!" onclick="btnClick('cover_path')"
title="上传"></a>
@ -73,7 +73,7 @@
style="display: none;"></li>
<li class="col-xs-4 col-sm-3 col-md-2" id="pic-upload">
<input type="hidden" class="form-control" name="cover_path" id="cover_path">
<input type="file" id="file_cover_path" style="display: none;"
<input type="file" id="file_cover_path" accept="image/*" style="display: none;"
onchange="upload('cover_path')">
<a class="pic-add" href="#!" onclick="btnClick('cover_path')"
title="上传"></a>

View File

@ -129,8 +129,9 @@
field: 'operate',
title: '操作',
formatter: function (value, row, index) {
let html = '<a class="btn btn-xs btn-default btn-del" href="#!" title="删除" data-toggle="tooltip" onclick="delOne(' + row.id + ')"><i class="mdi mdi-window-close"></i></a>\n' +
let html =
'<a type="button" class="btn-edit btn btn-xs btn-default m-r-5" href="/admin/article/edit?id=' + row.id + '" title="编辑" data-toggle="tooltip"><i class="mdi mdi-pencil"></i></a>\n' +
'<a class="btn btn-xs btn-default btn-del" href="#!" title="删除" data-toggle="tooltip" onclick="delOne(' + row.id + ')"><i class="mdi mdi-window-close"></i></a>\n' +
'<a type="button" class="btn-edit btn btn-xs btn-default m-r-5" href="/admin/article/comment?id=' + row.id + '" title="查看评论" data-toggle="tooltip"><i class="mdi mdi-message-text"></i></a>\n';
return html;
},

View File

@ -15,6 +15,7 @@ class Data
const CURR_CATEGORY_PATENT_ID = 'curr_category_patent_id'; //当前分类父级id
const DATA_SYSTEM_CONFIG = 'data_system_config'; //系统配置
const DATA_ADVERT = 'data_advert'; //广告
const DATA_ARCHIVE = "data_archive"; //文章归档
//广告位
const ADVERT_NAV_LIST = [

View File

@ -23,6 +23,7 @@ class Ape extends TagLib
'comment' => ['attr' => 'typeId,void,type,pageSize,orderBy', 'close' => 1],
'relevant' => ['attr' => 'id,model,void,row', 'close' => 1],
'tags' => ['attr' => 'tags,void', 'close' => 1],
'archive' => ['attr' => 'type,format,void', 'close' => 1],
];
@ -162,8 +163,8 @@ class Ape extends TagLib
$cid = isset($tag['cid']) ? $tag['cid'] : '$cid';
$void = isset($tag['void']) ? $tag['void'] : 'field';
$none = isset($tag['none']) ? $tag['none'] : '没有了';
$parse = '<?php ';
$parse .= '$__LIST__ =[];array_push($__LIST__,' . "tpl_get_prenext(\"$get\",$cid,\"$none\"));";
$parse .= ' ?>';
$parse .= '{volist name="__LIST__" id="' . $void . '"}';
@ -254,9 +255,9 @@ class Ape extends TagLib
$void = isset($tag['void']) ? $tag['void'] : 'field';
$parse = '<?php ';
$parse .= '$__TAG_LIST__ =' . "tpl_get_tags_list($tags);";
$parse .= '$__LIST__ =' . "tpl_get_tags_list($tags);";
$parse .= ' ?>';
$parse .= '{volist name="$__TAG_LIST__" id="' . $void . '"}';
$parse .= '{volist name="$__LIST__" id="' . $void . '"}';
$parse .= $content;
$parse .= '{/volist}';
return $parse;
@ -316,4 +317,27 @@ class Ape extends TagLib
$parse .= '{/volist}';
return $parse;
}
/**
* 文章归档
* @param $tag
* @param $content
* @return bool|string
*/
public function tagArchive($tag, $content)
{
if (empty($tag['type'])) {
return false;
}
$format = $tag['format']?:"Y-m";
$void = isset($tag['void']) ? $tag['void'] : 'field';
$parse = '<?php ';
$parse .= '$__LIST__ =' . "tpl_get_archive_list(\"$tag[type]\",\"$format\");";
$parse .= ' ?>';
$parse .= '{volist name="$__LIST__" id="' . $void . '"}';
$parse .= $content;
$parse .= '{/volist}';
return $parse;
}
}

View File

@ -591,15 +591,52 @@ function tpl_get_advert($type, $row)
} else {
$advertList = Db::name('advert')->where('status', 1)->order('sort desc')->limit($row)->select();
}
//处理文件cdn信息
foreach ($advertList as $key => &$item) {
if (empty($item['cover_path'])){
unset($advertList[$key]);
}
$item['cover_path'] = file_cdn($item['cover_path']);
}
cache(Data::DATA_ADVERT . '_' . $type, $advertList);
}
$advertListTemp = [];
foreach ($advertList as $key => $item) {
if ($item['cover_path']) {
array_push($advertListTemp, $item);
return $advertList;
}
/**
* 文档归档
* @ 格式 tpl_get_archive_list("month","Y-m") tpl_get_archive_list("month","Y年-m月")....
* @param $type
* @param $format
* @return mixed
* @author 李玉坤
* @date 2022-06-01 10:06
*/
function tpl_get_archive_list($type,$format){
$list = cache(Data::DATA_ARCHIVE . '_' . $type);
$list = null;
if ($list === null) {
switch ($type){
case "month":
$dateFormat = "LEFT(create_date,7)";
break;
case "day":
$dateFormat = "create_date";
break;
case "year":
$dateFormat = "LEFT(create_date,4)";
break;
default:
$dateFormat = "create_date";
break;
}
$list = $documentListModel = (new Document())->group($dateFormat)->column("count(*) as count,create_date");
foreach ($list as $key => &$item) {
$item['create_date'] = date($format,strtotime($item['create_date']));
}
cache(Data::DATA_ADVERT . '_' . $type, $list);
}
return $advertListTemp;
return $list;
}
if (!function_exists('web_config')) {

File diff suppressed because one or more lines are too long

Binary file not shown.

After

Width:  |  Height:  |  Size: 124 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.6 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.8 MiB