优化知识模块

This commit is contained in:
hdm 2021-11-18 00:05:13 +08:00
parent 56ad54fb6f
commit a7b65c0d5f
11 changed files with 195 additions and 224 deletions

View File

@ -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();
}
}

View File

@ -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();
}
}

View File

@ -35,10 +35,10 @@
<td>
<input type="text" name="sort" value="0" placeholder="请输入排序,数字" autocomplete="off" class="layui-input">
</td>
<td class="layui-td-gray2">首页显示</td>
<td class="layui-td-gray2">是否共享</td>
<td>
<input type="radio" name="is_home" value="1" title="是" checked>
<input type="radio" name="is_home" value="0" title="否">
<input type="radio" name="is_share" value="1" title="是" checked>
<input type="radio" name="is_share" value="0" title="否">
</td>
<td class="layui-td-gray2">属性</td>
<td>
@ -101,54 +101,53 @@
<!-- 脚本 -->
{block name="script"}
<script>
function init(layui) {
function init(layui) {
var form = layui.form
, layer = layui.layer
, tagspicker = layui.tagpicker
, upload = layui.upload;
var tags = new tagspicker({
'url': "{:url('home/api/get_keyword_cate')}",
'target': 'keyword_name',
'tag_ids': 'keyword_id',
'tag_tags': 'keyword_name',
'height': 500,
'isDiy': 1
'url': "{:url('home/api/get_keyword_cate')}",
'target': 'keyword_name',
'tag_ids': 'keyword_id',
'tag_tags': 'keyword_name',
'height': 500,
'isDiy': 1
});
//封面上传
var uploadInst = upload.render({
elem: '#test1'
, url: "{:url('home/api/upload')}",
, done: function (res) {
//如果上传失败
if (res.code == 1) {
return layer.msg('上传失败');
}
//上传成功
$('#demo1 input').attr('value', res.data.id);
$('#demo1 img').attr('src', res.data.filepath);
}
elem: '#test1'
, url: "{:url('home/api/upload')}"
, done: function (res) {
//如果上传失败
if (res.code == 1) {
return layer.msg('上传失败');
}
//上传成功
$('#demo1 input').attr('value', res.data.id);
$('#demo1 img').attr('src', res.data.filepath);
}
});
//监听提交
form.on('submit(webform)', function (data) {
$.ajax({
url: "{:url('home/article/post_submit')}",
type: 'post',
data: data.field,
success: function (e) {
if (e.code == 0) {
layer.confirm('保存成功,返回列表页吗?', { icon: 3, title: '提示' }, function (index) {
history.back(-1);
layer.close(index);
});
} else {
layer.msg(e.msg);
}
}
})
return false;
$.ajax({
url: "{:url('home/article/add')}",
type: 'post',
data: data.field,
success: function (e) {
if (e.code == 0) {
layer.confirm('保存成功,返回列表页吗?', { icon: 3, title: '提示' }, function (index) {
window.location.href="{:url('home/article/index')}";
});
} else {
layer.msg(e.msg);
}
}
})
return false;
});
//监听返回
$('.body-content').on('click', '[lay-event="back"]', function () {
@ -159,7 +158,7 @@
}
</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}
<!-- /脚本 -->

View File

@ -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)
}
}
})

View File

@ -17,20 +17,14 @@
<td>
<input type="text" name="title" lay-verify="required" autocomplete="off" placeholder="请输入分类名称" lay-reqText="请输入分类名称" class="layui-input">
</td>
</tr>
<tr>
<td class="layui-td-gray2">排序</td>
<td>
<input type="text" name="sort" placeholder="请输入排序,数字" value="0" autocomplete="off" class="layui-input">
</td>
<td class="layui-td-gray2">关键词</td>
<td>
<input type="text" name="keywords" placeholder="请输入关键词,用“,”隔开,可空" autocomplete="off" class="layui-input">
</td>
</tr>
<tr>
<td class="layui-td-gray2">描述</td>
<td colspan="3"><textarea name="desc" placeholder="请输入描述,可空" class="layui-textarea"></textarea></td>
<td colspan="5"><textarea name="desc" placeholder="请输入描述,可空" class="layui-textarea"></textarea></td>
</tr>
</table>
<div style="padding: 10px 0">
@ -44,38 +38,37 @@
<!-- 脚本 -->
{block name="script"}
<script>
function init(layui){
var form = layui.form
,layer = layui.layer;
<script>
function init(layui){
var form = layui.form
,layer = layui.layer;
//监听提交
form.on('submit(webform)', function(data){
//监听提交
form.on('submit(webform)', function(data){
$.ajax({
url:"{:url('home/article/cate_post_submit')}",
type:'post',
data:data.field,
success:function(e){
if(e.code==0){
layer.confirm('保存成功,返回列表页吗?', {icon: 3, title:'提示'}, function(index){
history.back(-1);
layer.close(index);
});
}else{
layer.msg(e.msg);
url:"{:url('home/article/cate_add')}",
type:'post',
data:data.field,
success:function(e){
if(e.code==0){
layer.confirm('保存成功,返回列表页吗?', {icon: 3, title:'提示'}, function(index){
history.back(-1);
layer.close(index);
});
}else{
layer.msg(e.msg);
}
}
}
})
return false;
});
//监听返回
$('.body-content').on('click','[lay-event="back"]',function () {
});
//监听返回
$('.body-content').on('click','[lay-event="back"]',function () {
history.back(-1);
return false;
});
}
</script>
{include file="common/layui" base='base' extend="[]" callback="init" /}
});
}
</script>
{include file="common/layui" base='base' extend="[]" callback="init" /}
{/block}
<!-- /脚本 -->

View File

@ -37,10 +37,10 @@
<input type="text" name="sort" placeholder="请输入排序,数字" autocomplete="off" class="layui-input"
value="{$article.sort}">
</td>
<td class="layui-td-gray2">首页显示</td>
<td class="layui-td-gray2">是否共享</td>
<td>
<input type="radio" name="is_home" value="1" title="是" {eq name="$article.is_home" value="1" }checked{/eq}>
<input type="radio" name="is_home" value="0" title="否" {eq name="$article.is_home" value="0" }checked{/eq}>
<input type="radio" name="is_share" value="1" title="是" {eq name="$article.is_share" value="1" }checked{/eq}>
<input type="radio" name="is_share" value="0" title="否" {eq name="$article.is_share" value="0" }checked{/eq}>
</td>
<td class="layui-td-gray2">属性</td>
<td>
@ -107,59 +107,58 @@
<!-- 脚本 -->
{block name="script"}
<script>
function init(layui) {
var form = layui.form
, layer = layui.layer
, tagspicker = layui.tagpicker
, upload = layui.upload;
function init(layui) {
var form = layui.form
, layer = layui.layer
, tagspicker = layui.tagpicker
, upload = layui.upload;
var tags = new tagspicker({
'url': "{:url('home/api/get_keyword_cate')}",
'target': 'keyword_name',
'tag_ids': 'keyword_id',
'tag_tags': 'keyword_name',
'height': 500,
'isDiy': 1
});
var tags = new tagspicker({
'url': "{:url('home/api/get_keyword_cate')}",
'target': 'keyword_name',
'tag_ids': 'keyword_id',
'tag_tags': 'keyword_name',
'height': 500,
'isDiy': 1
});
//封面上传
var uploadInst = upload.render({
elem: '#test1'
, url: "{:url('home/api/upload')}",
, done: function (res) {
//如果上传失败
if (res.code == 1) {
return layer.msg('上传失败');
}
//上传成功
$('#demo1 input').attr('value', res.data.id);
$('#demo1 img').attr('src', res.data.filepath);
}
elem: '#test1'
, url: "{:url('home/api/upload')}"
, done: function (res) {
//如果上传失败
if (res.code == 1) {
return layer.msg('上传失败');
}
//上传成功
$('#demo1 input').attr('value', res.data.id);
$('#demo1 img').attr('src', res.data.filepath);
}
});
//监听提交
form.on('submit(webform)', function (data) {
$.ajax({
url: "{:url('home/api/post_submit')}",
type: 'post',
data: data.field,
success: function (e) {
if (e.code == 0) {
layer.confirm('保存成功,返回列表页吗?', { icon: 3, title: '提示' }, function (index) {
history.back(-1);
layer.close(index);
});
} else {
layer.msg(e.msg);
}
}
})
return false;
$.ajax({
url: "{:url('home/article/add')}",
type: 'post',
data: data.field,
success: function (e) {
if (e.code == 0) {
layer.confirm('保存成功,返回列表页吗?', { icon: 3, title: '提示' }, function (index) {
window.location.href="{:url('home/article/index')}";
});
} else {
layer.msg(e.msg);
}
}
})
return false;
});
//监听返回
$('.body-content').on('click', '[lay-event="back"]', function () {
history.back(-1);
return false;
history.back(-1);
return false;
});
}

View File

@ -22,8 +22,8 @@
<script type="text/html" id="status">
<i class="layui-icon {{# if(d.status == 1){ }}layui-icon-ok{{# } else { }}layui-icon-close{{# } }}"></i>
</script>
<script type="text/html" id="is_home">
<i class="layui-icon {{# if(d.is_home == 1){ }}layui-icon-ok{{# } else { }}layui-icon-close{{# } }}"></i>
<script type="text/html" id="is_share">
<i class="layui-icon {{# if(d.is_share == 1){ }}layui-icon-ok{{# } else { }}layui-icon-close{{# } }}"></i>
</script>
<script type="text/html" id="toolbarDemo">
<div class="layui-btn-container">
@ -79,8 +79,8 @@
width: 66
}, {
field: 'is_home',
title: '首页显示',
toolbar: '#is_home',
title: '首页共享',
toolbar: '#is_share',
align: 'center',
width: 90
}, {

View File

@ -98,7 +98,7 @@ function init(layui) {
//监听提交
form.on('submit(webform)', function (data) {
$.ajax({
url: "{:url('home/note/post_submit')}",
url: "{:url('home/note/add')}",
type: 'post',
data: data.field,
success: function (e) {

View File

@ -61,7 +61,7 @@
treeGrid.on('edit('+tableId+')', function(obj){
layer.confirm('确定要提交修改吗?', {icon: 3, title:'提示'}, function(index){
$.ajax({
url:"{:url('home/note/cate_post_submit')}",
url:"{:url('home/note/cate_add')}",
type:'post',
data:{id:obj.data.id,field:obj.field,value:obj.value},
success:function(res){

View File

@ -42,7 +42,7 @@
//监听提交
form.on('submit(webform)', function(data){
$.ajax({
url:"{:url('home/note/cate_post_submit')}",
url:"{:url('home/note/cate_add')}",
type:'post',
data:data.field,
success:function(e){

View File

@ -361,8 +361,7 @@ CREATE TABLE `oa_article_cate` (
`id` int(11) UNSIGNED NOT NULL AUTO_INCREMENT,
`pid` int(11) NOT NULL DEFAULT 0 COMMENT '父类ID',
`sort` int(5) NOT NULL DEFAULT 0 COMMENT '排序',
`title` varchar(255) NOT NULL DEFAULT '' COMMENT '标题',
`keywords` varchar(255) NULL DEFAULT '' COMMENT '关键字',
`title` varchar(255) NOT NULL DEFAULT '' COMMENT '分类标题',
`desc` varchar(1000) NULL DEFAULT '' COMMENT '描述',
`create_time` int(11) NOT NULL DEFAULT 0 COMMENT '添加时间',
`update_time` int(11) NOT NULL DEFAULT 0 COMMENT '修改时间',