diff --git a/app/admin/controller/Article.php b/app/admin/controller/Article.php index efbdb73..0db71b5 100644 --- a/app/admin/controller/Article.php +++ b/app/admin/controller/Article.php @@ -2,9 +2,8 @@ namespace app\admin\controller; -use app\admin\model\Document; -use app\admin\model\DocumentArticle; -use app\admin\model\DocumentProduct; +use app\admin\model\Document as aModel; +use app\admin\model\DocumentCategory as cModel; use app\Request; use app\admin\services\UtilService as Util; @@ -17,7 +16,7 @@ use app\admin\services\UtilService as Util; class Article extends AuthController { /** - * 账号列表 + * 文章管理主页 * @return string * @throws \Exception */ @@ -46,7 +45,7 @@ class Article extends AuthController ['page',1], ['limit',20], ]); - return app("json")->layui(Document::systemPage($where)); + return app("json")->layui(aModel::systemPage($where)); } /** @@ -85,7 +84,7 @@ class Article extends AuthController $saveData[$key] = $value; } } - return Document::update($saveData,['id'=>$id]) ? app("json")->success("操作成功") : app("json")->fail("操作失败"); + return aModel::update($saveData,['id'=>$id]) ? app("json")->success("操作成功") : app("json")->fail("操作失败"); } /** @@ -100,7 +99,33 @@ class Article extends AuthController if (!$id) return app("json")->fail("参数有误,Id为空!"); $where = Util::postMore([['field',''],['value','']]); if ($where['field'] == '' || $where['value'] =='') return app("json")->fail("参数有误!"); - return Document::update([$where['field']=>$where['value']],['id'=>$id]) ? app("json")->success("操作成功") : app("json")->fail("操作失败"); + return aModel::update([$where['field']=>$where['value']],['id'=>$id]) ? app("json")->success("操作成功") : app("json")->fail("操作失败"); + } + + /** + * 新增页 + * @return string + * @throws \Exception + */ + public function add() + { + $this->assign("category",cModel::selectByType(2)); + return $this->fetch(); + } + + /** + * 编辑页 + * @return string + * @throws \Exception + * @author 李玉坤 + * @date 2021-02-20 17:00 + */ + public function edit(Request $request) + { + $this->assign("category",CModel::selectByType(2)); + $this->assign("info",aModel::get($request->param(['id']))); + return $this->fetch(); + } } \ No newline at end of file diff --git a/app/admin/model/DocumentCategory.php b/app/admin/model/DocumentCategory.php index 51426f3..fbab14a 100644 --- a/app/admin/model/DocumentCategory.php +++ b/app/admin/model/DocumentCategory.php @@ -35,4 +35,24 @@ class DocumentCategory extends BaseModel $data = $model->select(); return $data->toArray() ?: []; } + + /** + * 查询分类选择类型 + * @param int $type + * @param array $ids + * @return array + * @throws \think\db\exception\DataNotFoundException + * @throws \think\db\exception\DbException + * @throws \think\db\exception\ModelNotFoundException + */ + public static function selectByType(int $type = 0,array $ids = []) + { + $model = new self; + if (!empty($ids)) $model = $model->where("id","not in", $ids); + if ($type != 0) $model = $model->where("type",$type); + $model = $model->where("status",1); + $model = $model->field("id,name"); + $data = $model->select(); + return $data ? $data->toArray() : []; + } } \ No newline at end of file diff --git a/app/admin/view/article/add.html b/app/admin/view/article/add.html new file mode 100644 index 0000000..00dabbc --- /dev/null +++ b/app/admin/view/article/add.html @@ -0,0 +1,231 @@ + + +
+ + +