From 37967a491eb8559fefbcbdd826f1064c4090f7f5 Mon Sep 17 00:00:00 2001 From: zhao Date: Tue, 25 Feb 2020 15:40:06 +0800 Subject: [PATCH] admin home --- app/admin/controller/Index.php | 54 ++++++++++++ app/index/controller/Article.php | 53 ++---------- app/index/controller/Comment.php | 4 +- public/static/admin/modules/console.js | 42 +++++----- view/admin/index/home.html | 110 ++++++++----------------- 5 files changed, 119 insertions(+), 144 deletions(-) diff --git a/app/admin/controller/Index.php b/app/admin/controller/Index.php index 01c5a21..52dce08 100644 --- a/app/admin/controller/Index.php +++ b/app/admin/controller/Index.php @@ -43,6 +43,60 @@ class Index extends AdminController View::assign(['sys'=>$sys,'day'=>$days,'hos'=>$hos,'mins'=>$mins]); return View::fetch(); } + // + public function forums() + { + $forumList = Db::name('article') + ->alias('a') + ->join('user u','a.user_id = u.id') + ->join('cate c','a.cate_id = c.id') + ->field('a.id as aid,title,name,catename,pv') + ->whereWeek('a.create_time') + ->order('a.create_time', 'desc') + ->paginate(10); + $res = []; + $count = $forumList->total(); + if($count){ + $res['code'] = 0; + $res['msg'] = ''; + $res['count'] = $count; + foreach($forumList as $k=>$v){ + $res['data'][]= ['id'=>$v['aid'],'title'=>$v['title'],'name'=>$v['name'],'catename'=>$v['catename'],'pv'=>$v['pv']]; + } + } else { + $res = ['code'=>-1,'msg'=>'本周还没有发帖!']; + } + return json($res); + } + + //帖子评论 + public function replys() + { + if(Request::isAjax()) { + + $replys = Db::name('comment') + ->alias('a') + ->join('user u','a.user_id = u.id') + ->join('article c','a.article_id = c.id') + ->field('a.content as content,title,c.id as cid,name') + ->whereWeek('a.create_time') + ->order('a.create_time', 'desc') + ->paginate(10); + + $count = $replys->total(); + $res = []; + if ($count) { + $res = ['code'=>0,'msg'=>'','count'=>$count]; + foreach($replys as $k => $v){ + $res['data'][] = ['content'=>$v['content'],'title'=>$v['title'],'cid'=>$v['cid'],'name'=>$v['name']]; + } + } else { + $res = ['code'=>-1,'msg'=>'本周还没评论']; + } + return json($res); + } + } + public function layout(){ diff --git a/app/index/controller/Article.php b/app/index/controller/Article.php index 86aeaf7..a35eee9 100644 --- a/app/index/controller/Article.php +++ b/app/index/controller/Article.php @@ -200,8 +200,7 @@ class Article extends BaseController $validate = new \app\common\validate\Article(); //调用验证器 $res = $validate->scene('Artadd')->check($data); //进行数据验证 - if(true !==$res){ - //echo ''; + if(true !==$res){ return $this->error($validate->getError()); } else { $article = new \app\common\model\Article(); @@ -240,47 +239,13 @@ class Article extends BaseController return json($res); } - //添加文章和编辑页富文本编辑器图片上传 - public function lay_img_upload() - { - $file = Request()->file('file'); - if(empty($file)){ - $result["code"] = "1"; - $result["msg"] = "请选择图片"; - $result['data']["src"] = ''; - }else{ - // 移动到框架应用根目录/public/uploads/ 目录下 - $info = $file->move('uploads/' ); - if($info){ - $infos = $info->getInfo(); - // 源文件名 - $name = $infos['name']; - - $name_path =str_replace('\\',"/",$info->getSaveName()); - //成功上传后 获取上传信息 - $result["code"] = '0'; - $result["msg"] = "上传成功"; - $result['data']["src"] = "/uploads/".$name_path; - $result['data']["title"] = $name; - }else{ - // 上传失败获取错误信息 - $result["code"] = "2"; - $result["msg"] = "上传出错"; - $result['data']["src"] =''; - } - } - - return json_encode($result); - - } - //文本编辑器图片上传 public function text_img_upload() { $file = request()->file('file'); try { validate(['file'=>'fileSize:2048|fileExt:jpg,png,gif']) - ->check(array($file)); + ->check(['file'=>$file]); $savename = \think\facade\Filesystem::disk('public')->putFile('article_pic',$file); } catch (ValidateException $e) { echo $e->getMessage(); @@ -305,26 +270,22 @@ class Article extends BaseController //文章置顶,状态 public function jieset(){ $data = Request::param(); - $article = ArticleModel::find($data['id']); + $article = ArticleModel::field('id,is_top,is_hot')->find($data['id']); if($data['field'] === 'top') { if($data['rank']==1){ $article->save(['is_top' => 1]); - $res['status'] = 0; - $res['msg'] ='置顶成功'; + $res = ['status'=>0,'msg'=>'置顶成功']; } else { $article->save(['is_top' => 0]); - $res['status'] = 0; - $res['msg'] ='已取消置顶'; + $res = ['status'=>0,'msg'=>'已取消置顶']; } } else { if($data['rank']==1){ $article->save(['is_hot' => 1]); - $res['status'] = 0; - $res['msg'] ='已设精贴'; + $res = ['status'=>0,'msg'=>'已设精贴']; } else { $article->save(['is_hot' => 0]); - $res['status'] = 0; - $res['msg'] ='精贴已取消'; + $res = ['status'=>0,'msg'=>'精贴已取消']; } } return json($res); diff --git a/app/index/controller/Comment.php b/app/index/controller/Comment.php index 71287ea..2b93acb 100644 --- a/app/index/controller/Comment.php +++ b/app/index/controller/Comment.php @@ -61,7 +61,7 @@ class Comment extends BaseController return json($res); } - //更新评论 + //更新评论 public function updateDa() { $this->isLogin(); @@ -103,7 +103,7 @@ class Comment extends BaseController } } else { - return $res=['msg' => '你已赞过了']; + return $res=['status'=>1,'msg' => '你已赞过了']; } } } \ No newline at end of file diff --git a/public/static/admin/modules/console.js b/public/static/admin/modules/console.js index 4f9bb49..3215b7e 100644 --- a/public/static/admin/modules/console.js +++ b/public/static/admin/modules/console.js @@ -188,32 +188,34 @@ layui.define(function(exports){ var $ = layui.$ ,table = layui.table; - //今日热搜 + //本周发贴 table.render({ elem: '#LAY-index-topSearch' - ,url: layui.setter.base + 'json/console/top-search.js' //模拟接口 - ,page: true - ,cols: [[ - {type: 'numbers', fixed: 'left'} - ,{field: 'keywords', title: '关键词', minWidth: 300, templet: '
{{ d.keywords }}
'} - ,{field: 'frequency', title: '搜索次数', minWidth: 120, sort: true} - ,{field: 'userNums', title: '用户数', sort: true} - ]] - ,skin: 'line' - }); - - //今日热贴 - table.render({ - elem: '#LAY-index-topCard' - ,url: layui.setter.base + 'json/console/top-card.js' //模拟接口 + ,url: '/admin/index/forums' //模拟接口 ,page: true ,cellMinWidth: 120 ,cols: [[ {type: 'numbers', fixed: 'left'} - ,{field: 'title', title: '标题', minWidth: 300, templet: '
{{ d.title }}
'} - ,{field: 'username', title: '发帖者'} - ,{field: 'channel', title: '类别'} - ,{field: 'crt', title: '点击率', sort: true} + ,{field: 'title', title: '标题', minWidth: 300, templet: '
{{ d.title }}
'} + ,{field: 'name', title: '发帖者'} + ,{field: 'catename', title: '类别'} + ,{field: 'pv', title: '点击率', sort: true} + ]] + ,skin: 'line' + }); + + //本周评论 + table.render({ + elem: '#LAY-index-topCard' + ,url: '/admin/index/replys' //模拟接口 + ,page: true + ,cellMinWidth: 120 + ,cols: [[ + {type: 'numbers', fixed: 'left'} + ,{field: 'content', title: '评论'} + ,{field: 'title', title: '帖子', minWidth: 300, templet: '
{{ d.title }}
'} + ,{field: 'name', title: '评论者'} + ]] ,skin: 'line' }); diff --git a/view/admin/index/home.html b/view/admin/index/home.html index eeb6fdb..09c5a35 100644 --- a/view/admin/index/home.html +++ b/view/admin/index/home.html @@ -14,49 +14,49 @@