帖子附件下载及显示

This commit is contained in:
taoser 2020-12-14 14:53:33 +08:00
parent 18df4bda7e
commit 7666402809
7 changed files with 27 additions and 22 deletions

View File

@ -90,7 +90,7 @@ class Article extends Model
{
$artTop = Cache::get('arttop');
if (!$artTop) {
$artTop = $this::field('id,title,title_color,cate_id,user_id,create_time,is_top,jie,pv')->where(['is_top' => 1, 'status' => 1, 'delete_time' => 0])->with([
$artTop = $this::field('id,title,title_color,cate_id,user_id,create_time,is_top,pv,jie,upzip')->where(['is_top' => 1, 'status' => 1, 'delete_time' => 0])->with([
'cate' => function ($query) {
$query->where('delete_time', 0)->field('id,catename,ename');
},
@ -115,7 +115,7 @@ class Article extends Model
{
$artList = Cache::get('artlist');
if(!$artList){
$artList = $this::field('id,title,title_color,cate_id,user_id,create_time,is_hot,jie,pv')
$artList = $this::field('id,title,title_color,cate_id,user_id,create_time,is_hot,pv,jie,upzip')
->with([
'cate' => function($query){
$query->where('delete_time',0)->field('id,catename,ename');
@ -162,7 +162,7 @@ class Article extends Model
$article = Cache::get('article_'.$id);
if(!$article){
//查询文章
$article = $this::field('id,title,content,status,cate_id,user_id,is_top,is_hot,is_reply,pv,jie,upzip,tags,title_color,create_time')->where('status',1)->with([
$article = $this::field('id,title,content,status,cate_id,user_id,is_top,is_hot,is_reply,pv,jie,upzip,downloads,tags,title_color,create_time')->where('status',1)->with([
'cate' => function($query){
$query->where('delete_time',0)->field('id,catename,ename');
},
@ -203,7 +203,7 @@ class Article extends Model
switch ($type) {
//查询文章,15个分1页
case 'jie':
$artList = $this::field('id,title,title_color,cate_id,user_id,create_time,is_top,is_hot,jie,pv')->with([
$artList = $this::field('id,title,title_color,cate_id,user_id,create_time,is_top,is_hot,pv,jie,upzip')->with([
'cate' => function($query){
$query->where('delete_time',0)->field('id,catename,ename');
},
@ -219,7 +219,7 @@ class Article extends Model
break;
case 'hot':
$artList = $this::field('id,title,title_color,cate_id,user_id,create_time,is_top,is_hot,jie,pv')->with([
$artList = $this::field('id,title,title_color,cate_id,user_id,create_time,is_top,is_hot,pv,jie,upzip')->with([
'cate' => function($query){
$query->where('delete_time',0)->field('id,catename,ename');
},
@ -235,7 +235,7 @@ class Article extends Model
break;
case 'top':
$artList = $this::field('id,title,title_color,cate_id,user_id,create_time,is_top,is_hot,jie,pv')->with([
$artList = $this::field('id,title,title_color,cate_id,user_id,create_time,is_top,is_hot,pv,jie,upzip')->with([
'cate' => function($query){
$query->where('delete_time',0)->field('id,catename,ename');
},
@ -251,7 +251,7 @@ class Article extends Model
break;
default:
$artList = $this::field('id,title,title_color,cate_id,user_id,create_time,is_top,is_hot,jie,pv')->with([
$artList = $this::field('id,title,title_color,cate_id,user_id,create_time,is_top,is_hot,pv,jie,upzip')->with([
'cate' => function($query){
$query->where('delete_time',0)->field('id,catename,ename');
},

View File

@ -288,6 +288,9 @@ class Article extends BaseController
{
$zipdir = Db::name('article')->where('id',$id)->value('upzip');
$zip = substr($zipdir,1);
Db::name('article')->cache(true)->where('id',$id)->inc('downloads')->update();
//删除缓存显示下载后数据
Cache::delete('article_'.$id);
return download($zip,'my');
}

View File

@ -61,6 +61,7 @@ CREATE TABLE `tao_article` (
`pv` int(11) NOT NULL DEFAULT '0' COMMENT '浏览量',
`jie` enum('1','0') NOT NULL DEFAULT '0' COMMENT '0未结1已结',
`upzip` varchar(70) DEFAULT NULL COMMENT '文章附件',
`downloads` int(5) NOT NULL DEFAULT '0' COMMENT '下载量',
`tags` varchar(255) DEFAULT NULL COMMENT 'tag',
`read_type` tinyint(1) NOT NULL DEFAULT '0' COMMENT '阅读权限0开放1回复可读2密码可读3私密',
`art_pass` varchar(6) DEFAULT NULL COMMENT '文章加密密码',
@ -77,7 +78,7 @@ CREATE TABLE `tao_article` (
-- ----------------------------
-- Records of tao_article
-- ----------------------------
INSERT INTO `tao_article` VALUES ('1', 'Fly Template 社区模版', '[quote]\r\n 你们认为layui官方Fly Template 社区模版怎么样?\r\n[/quote]\r\n你喜欢吗\r\n很多人都说比较喜欢我个人认为不错的这个板子非常喜欢我看到有一些人做了开发可惜的是都没有很好的维护有的漏洞比较多不完善很美好的一个板子但没有长久 的更新,非常的可惜。\r\n如果用别人的不好用那我就做一个出来吧。喜欢的人多关注适当时候放出来大家一起用。\r\n关于详情页的内容解析\r\n该模板自带一个特定语法的编辑器当你把内容存储到数据库后在页面读取后浏览会发现诸如“表情、代码、图片”等无法解析这是因为需要对该内容进行一次转义通常来说这是在服务端完成的但鉴于简单化你还可以直接在前端去解析在模板的detail.html中我们已经把相关的代码写好了你只需打开注释即可在代码的最下面。当然如果觉得编辑器无法满足你的需求你也可以把该编辑器换成别的HTML编辑器或MarkDown编辑器。', '1', '1', '1', '0', '0', '1', '12', '0', null, null, '0', null, null, null, '1546698225', '1577772362', '0');
INSERT INTO `tao_article` VALUES ('1', 'Fly Template 社区模版', '[quote]\r\n 你们认为layui官方Fly Template 社区模版怎么样?\r\n[/quote]\r\n你喜欢吗\r\n很多人都说比较喜欢我个人认为不错的这个板子非常喜欢我看到有一些人做了开发可惜的是都没有很好的维护有的漏洞比较多不完善很美好的一个板子但没有长久 的更新,非常的可惜。\r\n如果用别人的不好用那我就做一个出来吧。喜欢的人多关注适当时候放出来大家一起用。\r\n关于详情页的内容解析\r\n该模板自带一个特定语法的编辑器当你把内容存储到数据库后在页面读取后浏览会发现诸如“表情、代码、图片”等无法解析这是因为需要对该内容进行一次转义通常来说这是在服务端完成的但鉴于简单化你还可以直接在前端去解析在模板的detail.html中我们已经把相关的代码写好了你只需打开注释即可在代码的最下面。当然如果觉得编辑器无法满足你的需求你也可以把该编辑器换成别的HTML编辑器或MarkDown编辑器。', '1', '1', '1', '0', '0', '1', '12', '0', null, '0', null, '0', null, null, null, '1546698225', '1577772362', '0');
-- ----------------------------
-- Table structure for tao_auth_group

View File

@ -29,14 +29,15 @@
<i class="iconfont icon-renzheng" title="认证信息XXX"></i>
-->
{if($art.user.vip > 0)}
<i class="layui-badge fly-badge-vip">VIP{$art.user.vip}</i>
<i class="layui-badge fly-badge-vip">vip{$art.user.vip}</i>
{/if}
</a>
<span>{$art.create_time|date='Y-m-d'}</span>
<span class="layui-hide-xs" title="人气"><i class="iconfont" title="人气">&#xe60b;</i> {$art.pv}</span>
<span class="layui-hide-xs" title="浏览"><i class="iconfont" title="浏览">&#xe60b;</i> {$art.pv}</span>
{if ($art.jie == 1)}<span class="layui-badge fly-badge-accept layui-hide-xs">{:lang('end')}</span>{/if}
<span class="fly-list-nums">
{notempty name="$art.upzip"}<i class="layui-icon layui-icon-file" style="font-size: 15px; color: #393D49;" title="附件"></i>{/notempty}
<i class="iconfont icon-pinglun1" title="回答"></i> {$art.comments_count}
</span>
</div>

View File

@ -45,7 +45,7 @@
<span class="fly-list-nums">
<a href="#comment"><i class="iconfont" title="{:lang('reply')}">&#xe60c;</i> {$comments->count()} </a>
<i class="iconfont" title="人气">&#xe60b;</i> {$pv}
<i class="iconfont" title="浏览">&#xe60b;</i> {$pv}
</span>
</div>
<div class="detail-about">
@ -58,7 +58,7 @@
<cite>{$article.user.nickname ?: $article.user.name}</cite>
<i class="iconfont icon-renzheng" title="认证信息:{{ rows.user.approve }}"></i>
{if($article.user.vip > 0)}
<i class="layui-badge fly-badge-vip">VIP{$article.user.vip}</i>
<i class="layui-badge fly-badge-vip">vip{$article.user.vip}</i>
{/if}
</a>
<span>{$article.create_time|date='Y-m-d H:d'}</span>
@ -74,7 +74,7 @@
{notempty name="$article.upzip"}
<div class="layui-inline">
<label ">{:lang('enclosure')}</label>
<button type="button" class="layui-btn" id="zip-download"><i class="layui-icon layui-icon-download-circle"></i>{:lang('download files')}</button>
<button type="button" class="layui-btn" id="zip-download"><i class="layui-icon layui-icon-download-circle"></i>{:lang('download files')}: {$article.downloads}次</button>
</div>
{/notempty}
</div>

View File

@ -14,15 +14,15 @@
<i class="iconfont icon-renzheng" title="认证信息XXX"></i>
-->
{if($art.user.vip > 0)}
<i class="layui-badge fly-badge-vip">VIP{$art.user.vip}</i>
<i class="layui-badge fly-badge-vip">vip{$art.user.vip}</i>
{/if}
</a>
<span>{$art.create_time|date='Y-m-d'}</span>
<span class="layui-hide-xs" title="人气"><i class="iconfont" title="人气">&#xe60b;</i> {$art.pv}</span>
<span class="layui-hide-xs" title="浏览"><i class="iconfont" title="浏览">&#xe60b;</i> {$art.pv}</span>
{if ($art.jie == 1)}<span class="layui-badge fly-badge-accept layui-hide-xs">{:lang('end')}</span>{/if}
<span class="fly-list-nums">
<span class="fly-list-nums">
{notempty name="$art.upzip"}<i class="layui-icon layui-icon-file" style="font-size: 15px; color: #393D49;" title="附件"></i>{/notempty}
<i class="iconfont icon-pinglun1" title="回答"></i>{$art.comments_count}
</span>
</div>

View File

@ -12,14 +12,14 @@
<cite>{$top.user.nickname ?: $top.user.name}</cite>
<!--i class="iconfont icon-renzheng" title="认证信息XXX"></i-->
{if($top.user.vip > 0)}
<i class="layui-badge fly-badge-vip">VIP{$top.user.vip}</i>
<i class="layui-badge fly-badge-vip">vip{$top.user.vip}</i>
{/if}
</a>
<span>{$top.create_time|date='Y-m-d'}</span>
<span class=" layui-hide-xs" title="人气"><i class="iconfont" title="人气">&#xe60b;</i> {$top.pv}</span>
<span class=" layui-hide-xs" title="浏览"> <i class="iconfont" title="浏览">&#xe60b;</i> {$top.pv} </span>
{if ($top.jie == 1)}<span class="layui-badge fly-badge-accept layui-hide-xs">{:lang('end')}</span>{/if}
<span class="fly-list-nums">
<span class="fly-list-nums">
{notempty name="$top.upzip"}<i class="layui-icon layui-icon-file" style="font-size: 15px; color: #393D49;" title="附件"></i>{/notempty}
<i class="iconfont icon-pinglun1" title="回答"></i> {$top.comments_count}
</span>
</div>