From e6a07b68c06a621d591ea5e06eaefa80b6552604 Mon Sep 17 00:00:00 2001 From: hdm Date: Mon, 12 Apr 2021 21:28:00 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=B7=B2=E7=9F=A5bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/admin/common.php | 8 +++ app/admin/controller/Api.php | 68 +++++++++++++++++++++- app/admin/controller/Article.php | 92 ++++++++++++++++++++---------- app/admin/model/AdminLog.php | 4 ++ app/admin/model/Keywords.php | 18 ++++++ app/admin/view/admin/log_list.html | 2 +- app/common.php | 18 ++++++ public/static/admin/css/common.css | 1 + 8 files changed, 178 insertions(+), 33 deletions(-) create mode 100644 app/admin/model/Keywords.php diff --git a/app/admin/common.php b/app/admin/common.php index e706fde..05f81aa 100644 --- a/app/admin/common.php +++ b/app/admin/common.php @@ -173,6 +173,14 @@ function get_keywords() $keywords = \think\facade\Db::name('keywords')->where(['status' => 1])->order('create_time asc')->select(); return $keywords; } + +//读取话题列表 +function get_topics() +{ + $topics = \think\facade\Db::name('topics')->where(['status' => 1])->order('create_time asc')->select(); + return $topics; +} + //读取文章分类列表 function get_article_cate() { diff --git a/app/admin/controller/Api.php b/app/admin/controller/Api.php index 785b887..43b4936 100644 --- a/app/admin/controller/Api.php +++ b/app/admin/controller/Api.php @@ -117,6 +117,13 @@ class Api extends BaseController $keyword = get_keywords(); return to_assign(1, '', $keyword); } + + //获取话题 + public function get_topics_cate() + { + $topic = get_topics(); + return to_assign(1, '', $topic); + } //清空缓存 public function cache_clear() @@ -264,7 +271,7 @@ class Api extends BaseController ->limit(10) ->select()->toArray(); foreach($list as $key=>$val){ - $list[$key]['create_time']=date('Y-m-d :h:m:s',$val['create_time']); + $list[$key]['create_time']=date('Y-m-d :H:i',$val['create_time']); } $res['data']=$list; return table_assign(1, '', $res); @@ -276,6 +283,7 @@ class Api extends BaseController return view('admin/log_list'); } + //获取系统操作日志 public function get_log_list() { $param=get_params(); @@ -283,5 +291,63 @@ class Api extends BaseController $content = $log->get_log_list($param); return table_assign(0,'',$content); } + + + //回复咨询 + public function set_reply() + { + $param=get_params(); + $data = []; + if(isset($param['cid']) && $param['cid']){ + $data['cid'] = $param['cid']; + $data['uid'] = 0; + $data['create_time'] =time(); + $data['content'] = $param['content']; + $res = Db::name('ConsultationReply')->strict(false)->field(true)->insertGetId($data); + } + if(isset($param['rid']) && $param['rid']){ + $data['id'] = $param['rid']; + $data['update_time'] =time(); + if(isset($param['status']) && $param['status']){ + $data['status'] = $param['status']; + } + else{ + $data['content'] = $param['content']; + } + $res = Db::name('ConsultationReply')->strict(false)->field(true)->update($data); + } + if($res){ + return to_assign(); + } + else{ + return to_assign(0,'操作失败,请重试'); + } + + } + + //评论动态 + public function set_comment() + { + $param=get_params(); + $data = []; + if(isset($param['rid']) && $param['rid']){ + $data['id'] = $param['rid']; + $data['update_time'] =time(); + if(isset($param['status']) && $param['status']){ + $data['status'] = $param['status']; + } + else{ + $data['content'] = $param['content']; + } + $res = Db::name('DynamicComment')->strict(false)->field(true)->update($data); + } + if($res){ + return to_assign(); + } + else{ + return to_assign(0,'操作失败,请重试'); + } + + } } diff --git a/app/admin/controller/Article.php b/app/admin/controller/Article.php index a56470b..dfc9a6c 100644 --- a/app/admin/controller/Article.php +++ b/app/admin/controller/Article.php @@ -6,6 +6,7 @@ namespace app\admin\controller; use app\admin\BaseController; use app\admin\model\Article as ArticleList; use app\admin\model\ArticleCate; +use app\admin\model\Keywords; use app\admin\validate\ArticleCateCheck; use app\admin\validate\ArticleCheck; use think\exception\ValidateException; @@ -19,20 +20,20 @@ class Article extends BaseController return view(); } - //列表 + //文章分类列表 public function cate_list() { $cate = Db::name('ArticleCate')->order('create_time asc')->select(); return to_assign(0, '', $cate); } - //添加 + //文章分类添加 public function cate_add() { return view('', ['pid' => get_params('pid')]); } - //提交添加 + //提交保存文章分类 public function cate_post_submit() { if (request()->isAjax()) { @@ -71,7 +72,7 @@ class Article extends BaseController } } - //删除 + //删除文章分配 public function cate_delete() { $id = get_params("id"); @@ -96,7 +97,7 @@ class Article extends BaseController return view(); } - //列表 + //文章列表 public function get_list() { $param = get_params(); @@ -118,7 +119,7 @@ class Article extends BaseController return table_assign(1, '', $content); } - //添加 + //文章添加&&编辑 public function add() { $id = empty(get_params('id')) ? 0 : get_params('id'); @@ -131,11 +132,12 @@ class Article extends BaseController return view(); } - //提交添加 + //文章内容提交保存 public function post_submit() { if (request()->isAjax()) { $param = get_params(); + $DbRes=false; if (!empty($param['id']) && $param['id'] > 0) { try { validate(ArticleCheck::class)->scene('edit')->check($param); @@ -144,12 +146,37 @@ class Article extends BaseController return to_assign(0, $e->getError()); } $param['update_time'] = time(); - $res = ArticleList::strict(false)->field(true)->update($param); - if ($res) { - add_log('edit', $param['id'], $param); + + Db::startTrans(); + try { + $res = ArticleList::strict(false)->field(true)->update($param); + $aid = $param['id']; + if ($res) { + Db::name('ArticleKeywords')->where(['aid'=>$aid])->delete(); + if (isset($param['keyword_names']) && $param['keyword_names']) { + $keywordArray = explode(',', $param['keyword_names']); + foreach ($keywordArray as $key => $value) { + if (!$value) { + continue; + } + $data = []; + $data['aid'] = $aid; + $keywords_id = (new Keywords())->increase($value); + $data['keywords_id'] = $keywords_id; + $data['create_time'] = time(); + Db::name('ArticleKeywords')->strict(false)->field(true)->insertGetId($data); + } + } + add_log('edit', $param['id'], $param); + Db::commit(); + $DbRes=true; + } else { + Db::rollback(); + } + } + catch (\Exception $e) { ##这里参数不能删除($e:错误信息) + Db::rollback(); } - - return to_assign(); } else { try { validate(ArticleCheck::class)->scene('add')->check($param); @@ -163,37 +190,40 @@ class Article extends BaseController $aid = ArticleList::strict(false)->field(true)->insertGetId($param); if ($aid) { if (isset($param['keyword_names']) && $param['keyword_names']) { - $uidArray = explode(',', $param['keyword_names']); - foreach ($uidArray as $key => $value) { - if (!$value) { - continue; - } - $data = []; - $data['aid'] = $aid; - $newKeyword['title'] = $value; - $keywords_id = Db::name('Keywords')->insertGetId($newKeyword); - $data['keywords_id'] = $keywords_id; - $data['create_time'] = time(); - Db::name('ArticleKeywords')->strict(false)->field(true)->insertGetId($data); - } - } - if ($aid) { - add_log('add', $aid, $param); + $keywordArray = explode(',', $param['keyword_names']); + foreach ($keywordArray as $key => $value) { + if (!$value) { + continue; + } + $data = []; + $data['aid'] = $aid; + $keywords_id = (new Keywords())->increase($value); + $data['keywords_id'] = $keywords_id; + $data['create_time'] = time(); + Db::name('ArticleKeywords')->strict(false)->field(true)->insertGetId($data); + } } + add_log('add', $aid, $param); Db::commit(); - return to_assign(); + $DbRes=true; } else { - return to_assign(0, '添加失败'); + Db::rollback(); } } catch (\Exception $e) { ##这里参数不能删除($e:错误信息) Db::rollback(); } } + if($DbRes){ + return to_assign(); + } + else{ + return to_assign(0,'操作失败'); + } } } - //删除 + //删除文章 public function delete() { $id = get_params("id"); diff --git a/app/admin/model/AdminLog.php b/app/admin/model/AdminLog.php index 4cbf860..f6cb22b 100644 --- a/app/admin/model/AdminLog.php +++ b/app/admin/model/AdminLog.php @@ -49,6 +49,10 @@ class AdminLog extends Model 'Article/delete' => '文章', 'Api/upload' => '附件', 'Login/login_submit' => '系统', + 'Consultation/post_submit' => '咨询', + 'Consultation/delete' => '咨询', + 'Dynamic/post_submit' => '动态', + 'Dynamic/delete' => '动态', ]; if (!empty($type_array[$type])) { return $type_array[$type]; diff --git a/app/admin/model/Keywords.php b/app/admin/model/Keywords.php new file mode 100644 index 0000000..d79814d --- /dev/null +++ b/app/admin/model/Keywords.php @@ -0,0 +1,18 @@ +where('title',$keywords)->find(); + if( $is_exist ){ + $res = $is_exist['id']; + }else{ + $res = $this->strict(false)->field(true)->insertGetId(['title' => $keywords,'create_time' => time()]); + } + return $res; + } +} \ No newline at end of file diff --git a/app/admin/view/admin/log_list.html b/app/admin/view/admin/log_list.html index 45142a1..8d2b6ca 100644 --- a/app/admin/view/admin/log_list.html +++ b/app/admin/view/admin/log_list.html @@ -12,7 +12,7 @@ {/block} {block name="body"} -
+
最新动态
    diff --git a/app/common.php b/app/common.php index 4d121cd..9556933 100644 --- a/app/common.php +++ b/app/common.php @@ -152,6 +152,24 @@ function table_assign($code = 0, $msg = '请求成功', $data = [], $httpCode = throw new \think\exception\HttpResponseException($response); } +/** + * 时间戳格式化 + * @param int $time + * @param string $format 默认'Y-m-d H:i',x代表毫秒 + * @return string 完整的时间显示 + */ +function time_format($time = NULL, $format = 'Y-m-d H:i:s') +{ + $usec = $time = $time === null ? '' : $time; + if (strpos($time, '.')!==false) { + list($usec, $sec) = explode(".", $time); + } else { + $sec = 0; + } + + return $time != '' ? str_replace('x', $sec, date($format, intval($usec))) : ''; +} + /** * 间隔时间段格式化 * @param int $time 时间戳 diff --git a/public/static/admin/css/common.css b/public/static/admin/css/common.css index 6836820..fa5b12a 100644 --- a/public/static/admin/css/common.css +++ b/public/static/admin/css/common.css @@ -64,6 +64,7 @@ .layui-td-gray font,.layui-td-gray2 font,.layui-td-gray3 font{color:#FF6347; margin-left: 3px;} .main-body{padding:10px;padding-bottom: 0;min-width: 800px;} .body-content{padding:10px;background-color:#fff;box-shadow: 0 1px 2px 0 rgba(0,0,0,.05);} + .body-form-btn{padding:10px 0;} .span-color--1{color:#999999;} .span-color-0{color:#5FB878;} .span-color-1{color:#FF6347;}