diff --git a/app/home/controller/Article.php b/app/home/controller/Article.php index 1661232..181b4c8 100644 --- a/app/home/controller/Article.php +++ b/app/home/controller/Article.php @@ -4,7 +4,7 @@ * @license https://opensource.org/licenses/GPL-2.0 * @link https://www.gougucms.com */ - + declare (strict_types = 1); namespace app\home\controller; @@ -12,7 +12,6 @@ namespace app\home\controller; use app\home\BaseController; use app\home\model\Article as ArticleList; use app\home\model\ArticleCate; -use app\home\model\Keywords; use app\home\validate\ArticleCateCheck; use app\home\validate\ArticleCheck; use think\exception\ValidateException; @@ -26,35 +25,28 @@ class Article extends BaseController if (request()->isAjax()) { $cate = Db::name('ArticleCate')->order('create_time asc')->select(); return to_assign(0, '', $cate); - } - else{ + } else { return view(); - } + } } - //文章分类添加 + //文章分类添加&编辑 public function cate_add() { - return view('', ['pid' => get_params('pid')]); - } - - //提交保存文章分类 - public function cate_post_submit() - { + $param = get_params(); if (request()->isAjax()) { - $param = get_params(); if (!empty($param['id']) && $param['id'] > 0) { $data[$param['field']] = $param['value']; $data['id'] = $param['id']; $data['update_time'] = time(); - if(!empty($data['title'])){ - try { - validate(ArticleCateCheck::class)->scene('edit')->check($data); - } catch (ValidateException $e) { - // 验证失败 输出错误信息 - return to_assign(1, $e->getError()); - } - } + if (!empty($data['title'])) { + try { + validate(ArticleCateCheck::class)->scene('edit')->check($data); + } catch (ValidateException $e) { + // 验证失败 输出错误信息 + return to_assign(1, $e->getError()); + } + } $res = ArticleCate::strict(false)->field(true)->update($data); if ($res) { add_log('edit', $data['id'], $data); @@ -75,9 +67,14 @@ class Article extends BaseController return to_assign(); } } + else{ + $pid = isset($param['pid']) ? $param['pid'] : 0; + View::assign('pid', $pid); + return view(); + } } - //删除文章分配 + //删除文章分类 public function cate_delete() { $id = get_params("id"); @@ -117,31 +114,17 @@ class Article extends BaseController ->order('a.create_time desc') ->paginate($rows, false, ['query' => $param]); return table_assign(0, '', $content); - } - else{ + } else { return view(); - } + } } //文章添加&&编辑 public function add() { - $id = empty(get_params('id')) ? 0 : get_params('id'); - View::assign('id', $id); - if ($id > 0) { - $article = (new ArticleList())->detail($id); - View::assign('article', $article); - return view('edit'); - } - return view(); - } - - //文章内容提交保存 - public function post_submit() - { + $param = get_params(); if (request()->isAjax()) { - $param = get_params(); - $DbRes=false; + $DbRes = false; if (!empty($param['id']) && $param['id'] > 0) { try { validate(ArticleCheck::class)->scene('edit')->check($param); @@ -149,32 +132,30 @@ class Article extends BaseController // 验证失败 输出错误信息 return to_assign(1, $e->getError()); } - $param['update_time'] = time(); - Db::startTrans(); + $param['update_time'] = time(); + Db::startTrans(); try { - $res = ArticleList::strict(false)->field(true)->update($param); - $aid = $param['id']; - if ($res) { + $res = ArticleList::strict(false)->field(true)->update($param); + $aid = $param['id']; + if ($res) { //关联关键字 - if (isset($param['keyword_names']) && $param['keyword_names']) { - Db::name('ArticleKeywords')->where(['aid'=>$aid])->delete(); - $keywordArray = explode(',', $param['keyword_names']); - $res_keyword = (new ArticleList())->insertKeyword($keywordArray,$aid); - } - else{ + if (isset($param['keyword_names']) && $param['keyword_names']) { + Db::name('ArticleKeywords')->where(['aid' => $aid])->delete(); + $keywordArray = explode(',', $param['keyword_names']); + $res_keyword = (new ArticleList())->insertKeyword($keywordArray, $aid); + } else { $res_keyword == true; } - if($res_keyword!== false){ + if ($res_keyword !== false) { add_log('edit', $param['id'], $param); Db::commit(); - $DbRes=true; + $DbRes = true; } - } else { - Db::rollback(); + } else { + Db::rollback(); } - } - catch (\Exception $e) { ##这里参数不能删除($e:错误信息) - Db::rollback(); + } catch (\Exception $e) { ##这里参数不能删除($e:错误信息) + Db::rollback(); } } else { try { @@ -186,38 +167,45 @@ class Article extends BaseController $param['create_time'] = time(); Db::startTrans(); try { - if(empty($param['desc'])){ + if (empty($param['desc'])) { $param['desc'] = get_desc_content($param['content'], 100); } $aid = ArticleList::strict(false)->field(true)->insertGetId($param); if ($aid) { //关联关键字 - if (isset($param['keyword_names']) && $param['keyword_names']) { - $keywordArray = explode(',', $param['keyword_names']); - $res_keyword = (new ArticleList())->insertKeyword($keywordArray,$aid); - } - else{ + if (isset($param['keyword_names']) && $param['keyword_names']) { + $keywordArray = explode(',', $param['keyword_names']); + $res_keyword = (new ArticleList())->insertKeyword($keywordArray, $aid); + } else { $res_keyword == true; } - if($res_keyword!== false){ + if ($res_keyword !== false) { add_log('add', $aid, $param); Db::commit(); - $DbRes=true; + $DbRes = true; } } else { - Db::rollback(); + Db::rollback(); } - } - catch (\Exception $e) { ##这里参数不能删除($e:错误信息) - Db::rollback(); + } catch (\Exception $e) { ##这里参数不能删除($e:错误信息) + Db::rollback(); } } - if($DbRes){ - return to_assign(); - } - else{ - return to_assign(1,'操作失败'); - } + if ($DbRes) { + return to_assign(); + } else { + return to_assign(1, '操作失败'); + } + } + else{ + $id = isset($param['id']) ? $param['id'] : 0; + View::assign('id', $id); + if ($id > 0) { + $article = (new ArticleList())->detail($id); + View::assign('article', $article); + return view('edit'); + } + return view(); } } diff --git a/app/home/controller/Note.php b/app/home/controller/Note.php index 27bdc61..fd3fdf4 100644 --- a/app/home/controller/Note.php +++ b/app/home/controller/Note.php @@ -32,12 +32,6 @@ class Note extends BaseController //分类添加 public function cate_add() - { - return view('', ['pid' => get_params('pid')]); - } - - //提交保存分类 - public function cate_post_submit() { if (request()->isAjax()) { $param = get_params(); @@ -72,6 +66,10 @@ class Note extends BaseController } return to_assign(); } + } else { + $pid = isset($param['pid']) ? $param['pid'] : 0; + View::assign('pid', $pid); + return view(); } } @@ -124,20 +122,8 @@ class Note extends BaseController //添加 public function add() { - $id = empty(get_params('id')) ? 0 : get_params('id'); - if ($id > 0) { - $note = Db::name('Note')->where(['id' => $id])->find(); - View::assign('note', $note); - } - View::assign('id', $id); - return view(); - } - - //提交添加 - public function post_submit() - { + $param = get_params(); if (request()->isAjax()) { - $param = get_params(); $param['start_time'] = isset($param['start_time']) ? strtotime(urldecode($param['start_time'])) : 0; $param['end_time'] = isset($param['end_time']) ? strtotime(urldecode($param['end_time'])) : 0; if (!empty($param['id']) && $param['id'] > 0) { @@ -169,6 +155,14 @@ class Note extends BaseController return to_assign(); } + } else { + $id = isset($param['id']) ? $param['id'] : 0; + if ($id > 0) { + $note = Db::name('Note')->where(['id' => $id])->find(); + View::assign('note', $note); + } + View::assign('id', $id); + return view(); } } diff --git a/app/home/view/article/add.html b/app/home/view/article/add.html index b6ab1b1..0bd9a57 100644 --- a/app/home/view/article/add.html +++ b/app/home/view/article/add.html @@ -35,10 +35,10 @@ - 首页显示 + 是否共享 - - + + 属性 @@ -101,54 +101,53 @@ {block name="script"} -{include file="common/layui" base='base' extend="['tagpicker']" callback="init" /} +{include file="common/layui" base="base" extend="['tagpicker']" callback="init" /} {include file="common/ueditor" id="container" name="content" width="776" height="500" toolbar="[]" /} {/block} \ No newline at end of file diff --git a/app/home/view/article/cate.html b/app/home/view/article/cate.html index 68f932b..14bf900 100644 --- a/app/home/view/article/cate.html +++ b/app/home/view/article/cate.html @@ -45,7 +45,6 @@ ,{field: 'sort', title: '排序', edit: "text", align:'center', style:'cursor: pointer;', width:80} ,{field:'title', edit:'text',width:240, title: '分类名称'} ,{field:'pid', title: '父级ID', edit:"text",width:80, align:'center'} - ,{field:'keywords', title: '关键词', edit:"text",width:200,} ,{field:'desc', title: '描述', edit:"text"} ,{width:100,title: '操作', align:'center' ,templet: function(d){ @@ -63,15 +62,15 @@ treeGrid.on('edit('+tableId+')', function(obj){ layer.confirm('确定要提交修改吗?', {icon: 3, title:'提示'}, function(index){ $.ajax({ - url:"{:url('home/article/cate_post_submit')}", + url:"{:url('home/article/cate_add')}", type:'post', data:{id:obj.data.id,field:obj.field,value:obj.value}, success:function(res){ layer.msg(res.msg); - if(res.code == 1){ + if(res.code == 0){ setTimeout(function(){ location.reload() - },2000) + },1200) } } }) diff --git a/app/home/view/article/cate_add.html b/app/home/view/article/cate_add.html index 31c298f..3d8ada7 100644 --- a/app/home/view/article/cate_add.html +++ b/app/home/view/article/cate_add.html @@ -17,20 +17,14 @@ - - 排序 - 关键词 - - - 描述 - +
@@ -44,38 +38,37 @@ {block name="script"} - - {include file="common/layui" base='base' extend="[]" callback="init" /} + }); + } + +{include file="common/layui" base='base' extend="[]" callback="init" /} {/block} \ No newline at end of file diff --git a/app/home/view/article/edit.html b/app/home/view/article/edit.html index 5d38e79..0a093b6 100644 --- a/app/home/view/article/edit.html +++ b/app/home/view/article/edit.html @@ -37,10 +37,10 @@ - 首页显示 + 是否共享 - - + + 属性 @@ -107,59 +107,58 @@ {block name="script"} -