diff --git a/app/api/controller/Index.php b/app/api/controller/Index.php index 4e1f607..b26a00a 100644 --- a/app/api/controller/Index.php +++ b/app/api/controller/Index.php @@ -246,22 +246,53 @@ class Index extends BaseController $res['data'] = $list; return table_assign(0, '', $res); } - - //首页文章 + + //首页文章 public function get_article_list() { - $list = Db::name('Article') - ->field('a.id,a.title,a.create_time,a.read,c.title as cate_title') - ->alias('a') - ->join('article_cate c', 'a.article_cate_id = c.id') - ->where(['a.status' => 1]) - ->order('a.id desc') - ->limit(10) - ->select()->toArray(); - foreach ($list as $key => $val) { - $list[$key]['create_time'] = date('Y-m-d :H:i', $val['create_time']); - } - $res['data'] = $list; + $prefix = get_config('database.connections.mysql.prefix');//判断是否安装了文章模块 + $exist = Db::query('show tables like "'.$prefix.'article"'); + $res['data'] = []; + if($exist){ + $list = Db::name('Article') + ->field('a.id,a.title,a.create_time,a.read,c.title as cate_title') + ->alias('a') + ->join('article_cate c', 'a.cate_id = c.id') + ->where(['a.delete_time' => 0]) + ->order('a.id desc') + ->limit(10) + ->select()->toArray(); + foreach ($list as $key => $val) { + $list[$key]['create_time'] = date('Y-m-d :H:i', $val['create_time']); + } + $res['data'] = $list; + } + return table_assign(0, '', $res); + } + + + //首页项目 + public function get_project_list() + { + $prefix = get_config('database.connections.mysql.prefix');//判断是否安装了项目模块 + $exist = Db::query('show tables like "'.$prefix.'project"'); + $res['data'] = []; + if($exist){ + $list = Db::name('Project') + ->field('a.id,a.name,a.status,a.create_time,a.start_time,a.end_time,u.name as director_name') + ->alias('a') + ->join('Admin u', 'a.director_uid = u.id') + ->where([['a.delete_time','=',0]]) + ->order('a.id desc') + ->limit(10) + ->select()->toArray(); + foreach ($list as $key => $val) { + $list[$key]['create_time'] = date('Y-m-d :H:i', $val['create_time']); + $list[$key]['plan_time'] = date('Y-m-d', $list[$key]['start_time']) . ' 至 ' . date('Y-m-d', $list[$key]['end_time']); + $list[$key]['status_name'] = \app\project\model\Project::$Status[(int) $val['status']]; + } + $res['data'] = $list; + } return table_assign(0, '', $res); } @@ -361,6 +392,12 @@ class Index extends BaseController } } + //获取工作类型列表 + public function get_work_cate() + { + $cate = Db::name('WorkCate')->field('id,title')->where([['status', '=', 1]])->select(); + return to_assign(0, '', $cate); + } //获取审核类型 public function get_flow_cate($type=0) diff --git a/app/article/config/install.gouguoa b/app/article/config/install.gouguoa new file mode 100644 index 0000000..4e53ac8 --- /dev/null +++ b/app/article/config/install.gouguoa @@ -0,0 +1 @@ +勾股OA模块安装鉴定文件,请勿删除!!!!!此次模块标识为:article \ No newline at end of file diff --git a/app/article/config/install.sql b/app/article/config/install.sql new file mode 100644 index 0000000..bfc75aa --- /dev/null +++ b/app/article/config/install.sql @@ -0,0 +1,78 @@ +-- ---------------------------- +-- Table structure for oa_article_cate +-- ---------------------------- +DROP TABLE IF EXISTS `oa_article_cate`; +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 '分类标题', + `desc` varchar(1000) NULL DEFAULT '' COMMENT '描述', + `create_time` int(11) NOT NULL DEFAULT 0 COMMENT '添加时间', + `update_time` int(11) NOT NULL DEFAULT 0 COMMENT '修改时间', + PRIMARY KEY (`id`) USING BTREE +) ENGINE = InnoDB AUTO_INCREMENT = 1 CHARACTER SET = utf8mb4 COMMENT = '知识文章分类表'; + +-- ---------------------------- +-- Records of oa_article_cate +-- ---------------------------- +INSERT INTO `oa_article_cate` VALUES (1, 0, 0, '办公技巧', '', 1637984651, 0); +INSERT INTO `oa_article_cate` VALUES (2, 0, 0, '行业技能', '', 1637984739, 0); + +-- ---------------------------- +-- Table structure for oa_article +-- ---------------------------- +DROP TABLE IF EXISTS `oa_article`; +CREATE TABLE `oa_article` ( + `id` int(11) UNSIGNED NOT NULL AUTO_INCREMENT, + `title` varchar(255) NOT NULL DEFAULT '' COMMENT '知识文章标题', + `cate_id` int(11) NOT NULL DEFAULT 0 COMMENT '关联分类id', + `keywords` varchar(255) NULL DEFAULT '' COMMENT '关键字', + `desc` varchar(1000) NULL DEFAULT '' COMMENT '摘要', + `thumb` int(11) NOT NULL DEFAULT 0 COMMENT '缩略图id', + `uid` int(11) NOT NULL DEFAULT 0 COMMENT '作者', + `did` int(11) NOT NULL DEFAULT 0 COMMENT '部门', + `origin_url` varchar(255) NOT NULL DEFAULT '' COMMENT '来源地址', + `content` text NOT NULL COMMENT '文章内容', + `read` int(11) NOT NULL DEFAULT 0 COMMENT '阅读量', + `type` tinyint(2) NOT NULL DEFAULT 0 COMMENT '属性:1精华 2热门 3推荐', + `is_share` tinyint(1) NOT NULL DEFAULT 1 COMMENT '是否分享,0否,1是', + `status` int(1) NOT NULL DEFAULT 1 COMMENT '状态:1正常-1下架', + `sort` int(11) NOT NULL DEFAULT 0 COMMENT '排序', + `create_time` int(11) NOT NULL DEFAULT 0, + `update_time` int(11) NOT NULL DEFAULT 0, + `delete_time` int(11) NOT NULL DEFAULT 0, + PRIMARY KEY (`id`) USING BTREE +) ENGINE = InnoDB AUTO_INCREMENT = 1 CHARACTER SET = utf8mb4 COMMENT = '知识文章表'; + + +-- ---------------------------- +-- Records of oa_article +-- ---------------------------- +INSERT INTO `oa_article` VALUES (1, '勾股OA——简单实用的开源免费的企业办公系统框架', 2, '', '勾股办公是一款简单实用的开源免费的企业办公系统框架。系统集成了系统设置、人事管理模块、消息管理模块、日常办公、财务管理等基础模块。系统简约,易于功...', 1, 1, 1, '', '勾股办公是一款简单实用的开源免费的企业办公系统框架。系统集成了系统设置、人事管理模块、消息管理模块、日常办公、财务管理等基础模块。系统简约,易于功能扩展,方便二次开发,让开发者更专注于业务深度需求的开发,帮助开发者简单高效降低二次开发成本,通过二次开发之后可以用来做CRM,ERP,业务管理等系统。', 1, 2, 1, 1, 1, 1637985280, 1650817107, 0); +INSERT INTO `oa_article` VALUES (2, '勾股CMS——轻量级、高性能极速后台开发框架', 2, '', '勾股CMS是一套轻量级、高性能极速后台开发框架。通用型的后台权限管理框架,极低门槛、操作简单、开箱即用。系统易于功能扩展,代码维护,方便二次开发,让...', 0, 1, 1, '', '勾股CMS是一套轻量级、高性能极速后台开发框架。通用型的后台权限管理框架,极低门槛、操作简单、开箱即用。系统易于功能扩展,代码维护,方便二次开发,让开发者更专注于业务深度需求的开发,帮助开发者简单高效降低二次开发成本。', 0, 0, 1, 1, 0, 1650817085, 0, 0); +INSERT INTO `oa_article` VALUES (3, '勾股BLOG——简约,易用开源的个人博客系统', 2, '', '勾股BLOG是一款实用的开源免费的个人博客系统。集成了系统管理、基础数据、博客文章、博客动态、语雀知识库、用户管理、访问统计等功能。具有简约,易用,内存占用低等特点,可以用来做个人博客,工作室官网,自...', 0, 1, 1, '', '勾股BLOG是一款实用的开源免费的个人博客系统。集成了系统管理、基础数据、博客文章、博客动态、语雀知识库、用户管理、访问统计等功能。具有简约,易用,内存占用低等特点,可以用来做个人博客,工作室官网,自媒体官网等网站,二次开发之后也可以作为资讯、展品展示等网站。', 0, 0, 1, 1, 0, 1650817152, 0, 0); +INSERT INTO `oa_article` VALUES (4, '勾股DEV——研发管理与团队协作的工具软件', 2, '', '勾股DEV是一款专为IT行业研发团队打造的智能化项目管理与团队协作的工具软件,可以在线管理团队的工作、项目和任务,覆盖从需求提出到研发完成上线整个过程的项目协作。', 0, 1, 1, '', '勾股DEV是一款专为IT行业研发团队打造的智能化项目管理与团队协作的工具软件,可以在线管理团队的工作、项目和任务,覆盖从需求提出到研发完成上线整个过程的项目协作。', 0, 0, 1, 1, 0, 1650817189, 0, 0); + +-- ---------------------------- +-- Table structure for oa_article_keywords +-- ---------------------------- +DROP TABLE IF EXISTS `oa_article_keywords`; +CREATE TABLE `oa_article_keywords` ( + `id` int(11) UNSIGNED NOT NULL AUTO_INCREMENT, + `aid` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '知识文章ID', + `keywords_id` int(10) UNSIGNED NOT NULL DEFAULT 0 COMMENT '关联关键字id', + `status` tinyint(1) NOT NULL DEFAULT 1 COMMENT '状态:-1删除 0禁用 1启用', + `create_time` int(11) NOT NULL DEFAULT 0 COMMENT '创建时间', + PRIMARY KEY (`id`) USING BTREE, + INDEX `aid`(`aid`) USING BTREE, + INDEX `inid`(`keywords_id`) USING BTREE +) ENGINE = InnoDB AUTO_INCREMENT = 1 CHARACTER SET = utf8mb4 COMMENT = '知识文章关联表'; + +-- ---------------------------- +-- Records of oa_article_keywords +-- ---------------------------- +INSERT INTO `oa_article_keywords` VALUES (1, 1, 1, 1, 1638093082); +INSERT INTO `oa_article_keywords` VALUES (2, 2, 2, 1, 1638093082); +INSERT INTO `oa_article_keywords` VALUES (3, 3, 3, 3, 1638093082); +INSERT INTO `oa_article_keywords` VALUES (4, 4, 4, 4, 1638093082); \ No newline at end of file diff --git a/app/article/controller/Cate.php b/app/article/controller/Cate.php new file mode 100644 index 0000000..4923c66 --- /dev/null +++ b/app/article/controller/Cate.php @@ -0,0 +1,105 @@ +isAjax()) { + $cate = Db::name('ArticleCate')->order('create_time asc')->select(); + return to_assign(0, '', $cate); + } else { + return view(); + } + } + + //文章分类添加&编辑 + public function cate_add() + { + $param = get_params(); + if (request()->isAjax()) { + if (!empty($param['id']) && $param['id'] > 0) { + try { + validate(ArticleCateCheck::class)->scene('edit')->check($param); + } catch (ValidateException $e) { + // 验证失败 输出错误信息 + return to_assign(1, $e->getError()); + } + $note_array = admin_article_cate_son($param['id']); + if (in_array($param['pid'], $note_array)) { + return to_assign(1, '父级分类不能是该分类本身或其子分类'); + } else { + $param['update_time'] = time(); + $res = Db::name('ArticleCate')->strict(false)->field(true)->update($param); + if($res){ + add_log('edit', $param['id'], $param); + return to_assign(); + } + } + } else { + try { + validate(ArticleCateCheck::class)->scene('add')->check($param); + } catch (ValidateException $e) { + // 验证失败 输出错误信息 + return to_assign(1, $e->getError()); + } + $param['create_time'] = time(); + $insertId = Db::name('ArticleCate')->strict(false)->field(true)->insertGetId($param); + if ($insertId) { + add_log('add', $insertId, $param); + } + return to_assign(); + } + } else { + $id = isset($param['id']) ? $param['id'] : 0; + $pid = isset($param['pid']) ? $param['pid'] : 0; + $cate = Db::name('ArticleCate')->order('id desc')->select()->toArray(); + $cates = set_recursion($cate); + if ($id > 0) { + $detail = Db::name('ArticleCate')->where(['id' => $id])->find(); + View::assign('detail', $detail); + } + View::assign('id', $id); + View::assign('pid', $pid); + View::assign('cates', $cates); + return view(); + } + } + + //删除文章分类 + public function cate_delete() + { + $id = get_params("id"); + $cate_count = Db::name('ArticleCate')->where(["pid" => $id])->count(); + if ($cate_count > 0) { + return to_assign(1, "该分类下还有子分类,无法删除"); + } + $content_count = Db::name('Article')->where(["article_cate_id" => $id])->count(); + if ($content_count > 0) { + return to_assign(1, "该分类下还有文章,无法删除"); + } + if (Db::name('ArticleCate')->delete($id) !== false) { + add_log('delete', $id); + return to_assign(0, "删除分类成功"); + } else { + return to_assign(1, "删除失败"); + } + } + + +} diff --git a/app/article/controller/Index.php b/app/article/controller/Index.php index 21f8a6d..be4718b 100644 --- a/app/article/controller/Index.php +++ b/app/article/controller/Index.php @@ -26,16 +26,16 @@ class Index extends BaseController if (!empty($param['keywords'])) { $where[] = ['a.id|a.title|a.keywords|a.desc|a.content|c.title', 'like', '%' . $param['keywords'] . '%']; } - if (!empty($param['article_cate_id'])) { - $where[] = ['a.article_cate_id', '=', $param['article_cate_id']]; + if (!empty($param['cate_id'])) { + $where[] = ['a.cate_id', '=', $param['cate_id']]; } - $where[] = ['a.status', '>=', 0]; + $where[] = ['a.delete_time', '=', 0]; $where[] = ['a.is_share', '=', 1]; $rows = empty($param['limit']) ? get_config('app . page_size') : $param['limit']; $content = ArticleList::where($where) - ->field('a.*,c.id as cate_id,a.id as id,c.title as cate_title,a.title as title,d.title as department,u.name as user') + ->field('a.*,a.id as id,c.title as cate_title,a.title as title,d.title as department,u.name as user') ->alias('a') - ->join('article_cate c', 'a.article_cate_id = c.id') + ->join('article_cate c', 'a.cate_id = c.id') ->join('admin u', 'a.uid = u.id','LEFT') ->join('department d', 'a.did = d.id','LEFT') ->order('a.create_time desc') @@ -54,16 +54,16 @@ class Index extends BaseController if (!empty($param['keywords'])) { $where[] = ['a.id|a.title|a.keywords|a.desc|a.content|c.title', 'like', '%' . $param['keywords'] . '%']; } - if (!empty($param['article_cate_id'])) { - $where[] = ['a.article_cate_id', '=', $param['article_cate_id']]; + if (!empty($param['cate_id'])) { + $where[] = ['a.cate_id', '=', $param['cate_id']]; } - $where[] = ['a.status', '>=', 0]; + $where[] = ['a.delete_time', '=', 0]; $where[] = ['a.uid', '=', $this->uid]; $rows = empty($param['limit']) ? get_config('app . page_size') : $param['limit']; $content = ArticleList::where($where) - ->field('a.*,c.id as cate_id,a.id as id,c.title as cate_title,a.title as title') + ->field('a.*,a.id as id,c.title as cate_title,a.title as title') ->alias('a') - ->join('article_cate c', 'a.article_cate_id = c.id') + ->join('article_cate c', 'a.cate_id = c.id') ->order('a.create_time desc') ->paginate($rows, false, ['query' => $param]); return table_assign(0, '', $content); @@ -168,7 +168,7 @@ class Index extends BaseController { $id = get_params("id"); $detail = (new ArticleList())->detail($id); - $detail['cate_title'] = Db::name('ArticleCate')->where(['id' => $detail['article_cate_id']])->value('title'); + $detail['cate_title'] = Db::name('ArticleCate')->where(['id' => $detail['cate_id']])->value('title'); // read 字段加 1 Db::name('article')->where('id', $id)->inc('read')->update(); View::assign('detail', $detail); @@ -178,9 +178,8 @@ class Index extends BaseController public function delete() { $id = get_params("id"); - $data['status'] = '-1'; $data['id'] = $id; - $data['update_time'] = time(); + $data['delete_time'] = time(); if (Db::name('Article')->update($data) !== false) { add_log('delete', $id); return to_assign(0, "删除成功"); diff --git a/app/home/validate/ArticleCateCheck.php b/app/article/validate/ArticleCateCheck.php similarity index 94% rename from app/home/validate/ArticleCateCheck.php rename to app/article/validate/ArticleCateCheck.php index 8be166f..8168d57 100644 --- a/app/home/validate/ArticleCateCheck.php +++ b/app/article/validate/ArticleCateCheck.php @@ -5,7 +5,7 @@ * @link https://www.gougucms.com */ -namespace app\home\validate; +namespace app\article\validate; use think\Validate; diff --git a/app/article/validate/ArticleCheck.php b/app/article/validate/ArticleCheck.php index 676929e..2699786 100644 --- a/app/article/validate/ArticleCheck.php +++ b/app/article/validate/ArticleCheck.php @@ -15,20 +15,18 @@ class ArticleCheck extends Validate 'title' => 'require|unique:article', 'content' => 'require', 'id' => 'require', - 'article_cate_id' => 'require', - 'status' => 'require', + 'cate_id' => 'require', ]; protected $message = [ 'title.require' => '标题不能为空', 'title.unique' => '同样的文章标题已经存在', - 'article_cate_id.require' => '所属分类为必选', + 'cate_id.require' => '所属分类为必选', 'id.require' => '缺少更新条件', - 'status.require' => '状态为必选', ]; protected $scene = [ - 'add' => ['title', 'article_cate_id', 'content', 'status'], - 'edit' => ['title', 'article_cate_id', 'content', 'id', 'status'], + 'add' => ['title', 'cate_id', 'content'], + 'edit' => ['title', 'cate_id', 'content', 'id'], ]; } diff --git a/app/home/view/cate/article_cate.html b/app/article/view/cate/cate.html similarity index 89% rename from app/home/view/cate/article_cate.html rename to app/article/view/cate/cate.html index 0dc9345..d3eef73 100644 --- a/app/home/view/cate/article_cate.html +++ b/app/article/view/cate/cate.html @@ -25,7 +25,7 @@ id:'treeTable' ,elem: '#treeTable' ,idField:'id' - ,url: "/home/cate/article_cate" + ,url: "/article/cate/cate" ,cellMinWidth: 100 ,treeId:'id'//树形id字段名称 ,treeUpId:'pid'//树形父id字段名称 @@ -48,18 +48,18 @@ //表头工具栏事件 $('.add-menu').on('click', function(){ - tool.side("/home/cate/article_cate_add"); + tool.side("/article/cate/cate_add"); return; }); //操作按钮 treeGrid.on('tool(treeTable)', function (obj) { if (obj.event === 'add') { - tool.side('/home/cate/article_cate_add?pid='+obj.data.id); + tool.side('/article/cate/cate_add?pid='+obj.data.id); return; } if (obj.event === 'edit') { - tool.side('/home/cate/article_cate_add?id='+obj.data.id); + tool.side('/article/cate/cate_add?id='+obj.data.id); return; } if (obj.event === 'del') { @@ -70,7 +70,7 @@ obj.del(); } } - tool.delete("/home/cate/article_cate_delete", { id: obj.data.id }, callback); + tool.delete("/article/cate/cate_delete", { id: obj.data.id }, callback); layer.close(index); }); } diff --git a/app/home/view/cate/article_cate_add.html b/app/article/view/cate/cate_add.html similarity index 97% rename from app/home/view/cate/article_cate_add.html rename to app/article/view/cate/cate_add.html index 49d2ee3..a0dd7cb 100644 --- a/app/home/view/cate/article_cate_add.html +++ b/app/article/view/cate/cate_add.html @@ -81,7 +81,7 @@ }, 1000); } } - tool.post("/home/cate/article_cate_add", data.field, callback); + tool.post("/article/cate/cate_add", data.field, callback); return false; }); } diff --git a/app/article/view/index/add.html b/app/article/view/index/add.html index 2c5966c..2887764 100644 --- a/app/article/view/index/add.html +++ b/app/article/view/index/add.html @@ -10,7 +10,7 @@ class="layui-input">