diff --git a/app/admin/controller/Article.php b/app/admin/controller/Article.php index 9bc6116..793ce4b 100644 --- a/app/admin/controller/Article.php +++ b/app/admin/controller/Article.php @@ -4,6 +4,7 @@ namespace app\admin\controller; use app\common\model\Document as aModel; use app\common\model\DocumentCategory as cModel; +use app\common\model\DocumentPage; use app\common\model\Tag as TagModel; use app\common\model\DocumentArticle; use app\common\model\Comment as CommentModel; @@ -208,7 +209,11 @@ class Article extends AuthController ['id', ''] ]); if ($where['id'] == '') { - return $this->error('数据不存在'); + $this->error('数据不存在'); + } + $info = (new DocumentArticle())->getInfo($where["id"]); + if (empty($info)) { + $this->error('数据不存在'); } $category = cModel::systemPage($where); $category = get_tree_list($category); diff --git a/app/admin/controller/Page.php b/app/admin/controller/Page.php index de3bb8d..d4ba6f8 100644 --- a/app/admin/controller/Page.php +++ b/app/admin/controller/Page.php @@ -4,6 +4,7 @@ namespace app\admin\controller; use app\common\model\Document as aModel; use app\common\model\DocumentCategory as cModel; +use app\common\model\DocumentPage; use app\common\model\Tag as TagModel; use app\common\model\DocumentArticle; use app\common\model\Comment as CommentModel; @@ -52,6 +53,7 @@ class Page extends AuthController ['page', 1], ['limit', 20], ]); + $where["type"] = aModel::DOCUMENT_TYPE_PAGE; return app("json")->layui(aModel::systemPage($where)); } @@ -173,7 +175,6 @@ class Page extends AuthController /** * 新增文章 - * @param $category_id * @return string * @throws DataNotFoundException * @throws DbException @@ -181,44 +182,57 @@ class Page extends AuthController * @author 李玉坤 * @date 2021-03-10 14:46 */ - public function add($category_id = '') + public function add() { - $where = [ - 'name' => '', - 'status' => '' - ]; + // 获取页面模板列表 + $themeList = []; + $themeDir = public_path('template').system_config('web_template').'/pc/page'; + if ($dh = opendir($themeDir)) { + while (($file = readdir($dh)) !== false) { - $this->assign("category", $category); - $this->assign("category_id", $category_id); + if ( $file != "." && $file != "..") { + $themeList[] = $file; + } + } + closedir($dh); + } + $this->assign("themeList", $themeList); return $this->fetch(); } /** * 编辑页 - * @return string - * @throws \Exception - * @author 李玉坤 - * @date 2021-02-20 17:00 + * @return string|void + * @throws DataNotFoundException + * @throws DbException + * @throws ModelNotFoundException */ public function edit() { $where = Util::postMore([ - ['name', ''], ['id', ''] ]); if ($where['id'] == '') { - return $this->error('数据不存在'); + $this->error('数据不存在'); } - $category = cModel::systemPage($where); - $category = get_tree_list($category); - $info = aModel::get($where['id']); - $content = DocumentArticle::get($where['id']); - if ($content) { - $info->content = $content->content; - } else { - $info->content = ''; + $info = (new DocumentPage())->getInfo($where["id"]); + if (empty($info)) { + $this->error('数据不存在'); } - $this->assign("category", $category); + // 获取页面模板列表 + $themeList = []; + $themeDir = public_path('template/'); + $defaultTheme = system_config('web_template'); + if ($dh = opendir($themeDir.'/'.$defaultTheme.'/pc/page')) { + if ((is_dir($themeDir . "/" . $file)) && $file != "." && $file != "..") { + while (($file = readdir($dh)) !== false) { + $pageList[] = $file; + } + } + + closedir($dh); + } + $this->assign("themeList", $themeList); $this->assign("info", $info); return $this->fetch(); } diff --git a/app/admin/view/article/add.html b/app/admin/view/article/add.html index 6083161..7701688 100644 --- a/app/admin/view/article/add.html +++ b/app/admin/view/article/add.html @@ -17,20 +17,18 @@
  • 基本信息
  • 文章设置
  • 返 回
  • + onclick="history.back(-1);return false;">
    - +
    - +
    @@ -38,9 +36,7 @@
    diff --git a/app/admin/view/article/edit.html b/app/admin/view/article/edit.html index da5691d..d46ff60 100644 --- a/app/admin/view/article/edit.html +++ b/app/admin/view/article/edit.html @@ -17,7 +17,7 @@
  • 基本信息
  • 文章设置
  • 返 回
  • + onclick="history.back(-1);return false;">
    diff --git a/app/admin/view/category/add.html b/app/admin/view/category/add.html index 1e15b5f..c29a590 100644 --- a/app/admin/view/category/add.html +++ b/app/admin/view/category/add.html @@ -17,7 +17,7 @@
  • 基本信息
  • SEO设置
  • 返 回
  • + onclick="history.back(-1);return false;">
    diff --git a/app/admin/view/category/edit.html b/app/admin/view/category/edit.html index 3d702aa..c7a3da3 100644 --- a/app/admin/view/category/edit.html +++ b/app/admin/view/category/edit.html @@ -17,7 +17,7 @@
  • 基本信息
  • SEO设置
  • 返 回
  • + onclick="history.back(-1);return false;">
    diff --git a/app/admin/view/page/add.html b/app/admin/view/page/add.html index 0cad34a..7cb647b 100644 --- a/app/admin/view/page/add.html +++ b/app/admin/view/page/add.html @@ -15,7 +15,7 @@
    @@ -23,36 +23,29 @@
    -
    +
    -
    +
    - +
    + +
    -
    +
    +
    + + +
    -
    - - -
    -
    - - -
    -
    - - -
    -
    - - -
    @@ -70,6 +63,20 @@
    +
    + + +
    +
    + + +
    +
    + + +
    - - - 文章评论管理 - {:system_config('title')}后台管理系统 - {include file="public/header" /} - - -
    -
    -
    -
    -
    -

    搜索

    -
      -
    • - -
    • -
    -
    -
    - -
    - -
    -
    - -
    -
    -
    -
    - -
    -
    - -
    -
    -
    -
    - -
    -
    - -
    -
    -
    -
    - -
    - - ~ - -
    -
    - - -
    -
    -
    -
    -
    -
    - -
    -
    -
    -
    -
    -
    -
    -
    -{include file="public/footer"/} - - - \ No newline at end of file diff --git a/app/admin/view/page/edit.html b/app/admin/view/page/edit.html index da5691d..1dcb163 100644 --- a/app/admin/view/page/edit.html +++ b/app/admin/view/page/edit.html @@ -15,148 +15,102 @@
    -
    -
    -
    - - - -
    -
    - - -
    -
    - -
    - + +
    + + +
    +
    +
    +
    + +
    + +
    +
    +
    + + +
    +
    + +
    -
    - - +
    +
    + +
    +
      + {notempty name="info.cover_path"} +
    • +
      + {$info.cover_path|basename} +
      + +
      +
      +
    • + + {else /} + +
    • + + + +
    • + {/notempty} +
    -
    - -
    -
      - {notempty name="info.cover_path"} -
    • -
      - {$info.cover_path|basename} -
      - -
      -
      -
    • - - {else /} - -
    • - - - -
    • - {/notempty} -
    -
    -
    -
    - - -
    -
    - - -
    -
    - - -
    -
    - -
    - -
    -
    -
    -
    -
    推荐
    -
    - -
    -
    -
    -
    热门
    -
    - -
    -
    -
    -
    置顶
    -
    - -
    -
    -
    - - -
    -
    - - -
    -
    - - -
    -
    - - -
    -
    - -
    -
    -
    +
    +
    + + +
    +
    + + +
    +
    + + +
    +
    + + +
    +
    + + +
    +
    + + +
    +
    + +
    +
    diff --git a/app/common/model/Document.php b/app/common/model/Document.php index 2231e26..f0364c1 100644 --- a/app/common/model/Document.php +++ b/app/common/model/Document.php @@ -15,6 +15,11 @@ use think\db\exception\ModelNotFoundException; */ class Document extends BaseModel { + //文档类型 + const DOCUMENT_TYPE_ARTICLE = "article"; + const DOCUMENT_TYPE_PAGE = "page"; + const DOCUMENT_TYPE_CATEGORY = "product"; + /** * 列表 * @param $where @@ -28,6 +33,7 @@ class Document extends BaseModel public static function systemPage($where): array { $model = new self; + $model = $model->where("type", "=",$where['type']?:self::DOCUMENT_TYPE_ARTICLE); if ($where['title'] != '') $model = $model->where("title", "like", "%$where[title]%"); if ($where['start_time'] != '') $model = $model->where("create_time", ">", strtotime($where['start_time'] . " 00:00:00")); if ($where['end_time'] != '') $model = $model->where("create_time", "<", strtotime($where['end_time'] . " 23:59:59")); diff --git a/app/common/model/DocumentArticle.php b/app/common/model/DocumentArticle.php index b1d6872..9e2f8a7 100644 --- a/app/common/model/DocumentArticle.php +++ b/app/common/model/DocumentArticle.php @@ -4,6 +4,7 @@ namespace app\common\model; +use app\common\model\Document as aModel; use think\db\exception\DataNotFoundException; use think\db\exception\DbException; use think\db\exception\ModelNotFoundException; @@ -16,23 +17,19 @@ use think\db\exception\ModelNotFoundException; */ class DocumentArticle extends BaseModel { - /** - * 列表 - * @param $where - * @return array - * @throws DataNotFoundException - * @throws DbException - * @throws ModelNotFoundException - * @author 李玉坤 - * @date 2021-02-15 23:24 - */ - public static function systemPage($where): array + public function getInfo($id) { - $model = new self; - $count = self::counts($model); - if ($where['page'] && $where['limit']) $model = $model->page((int)$where['page'], (int)$where['limit']); - $data = $model->select(); - if ($data) $data = $data->toArray(); - return compact('data', 'count'); + if (empty($id)){ + return []; + } + $info = aModel::alias('a') + ->leftJoin('document_article p','a.id = p.id') + ->where("a.id",$id) + ->where("a.type",Document::DOCUMENT_TYPE_PAGE) + ->find(); + if (!$info){ + return []; + } + return $info->toArray(); } } \ No newline at end of file diff --git a/app/common/model/DocumentPage.php b/app/common/model/DocumentPage.php new file mode 100644 index 0000000..a3c47bd --- /dev/null +++ b/app/common/model/DocumentPage.php @@ -0,0 +1,36 @@ +leftJoin('document_page p','a.id = p.id') + ->where("a.id",$id) + ->where("a.type",Document::DOCUMENT_TYPE_PAGE) + ->find(); + if (!$info){ + return []; + } + return $info->toArray(); + } + +} \ No newline at end of file diff --git a/app/index/controller/Article.php b/app/index/controller/Article.php index 7e27e08..1c53d8f 100644 --- a/app/index/controller/Article.php +++ b/app/index/controller/Article.php @@ -118,7 +118,11 @@ class Article extends Base } //获取该文章 $documentModel = new Document(); - $article = $documentModel->where('status', 1)->where('id|alias', $id)->find(); + if (is_numeric($id)){ + $article = $documentModel->where('status', 1)->where('id', $id)->find(); + }else{ + $article = $documentModel->where('status', 1)->where('alias', $id)->find(); + } if (!$article) { $this->error('文章不存在或已删除!'); }