diff --git a/app/api/controller/StoreKeeper.php b/app/api/controller/StoreKeeper.php index 96c5554a..ce257ac9 100644 --- a/app/api/controller/StoreKeeper.php +++ b/app/api/controller/StoreKeeper.php @@ -13,6 +13,7 @@ declare (strict_types=1); namespace app\api\controller; use app\api\service\User as UserService; +use app\store\model\article\Category as CategoryModel; use app\store\model\Express as ExpressModel; use app\store\model\store\Address as AddressModel; use app\store\model\store\shop\Clerk as ClerkModel; @@ -28,6 +29,7 @@ use app\store\model\Goods as GoodsModel; use app\store\model\Order as OrderModel; use app\store\model\OrderRefund as OrderRefundModel; use app\store\model\dealer\Order as DealerOrderModel; +use app\store\model\Article as ArticleModel; /** * 店主管理 @@ -366,4 +368,136 @@ class StoreKeeper extends Controller } + //文章管理 + + /** + * 文章分类列表 + * @return Json + * @throws \think\db\exception\DataNotFoundException + * @throws \think\db\exception\DbException + * @throws \think\db\exception\ModelNotFoundException + */ + public function articleCatList(): Json + { + $model = new CategoryModel; + $list = $model->getList(); + return $this->renderSuccess(compact('list')); + } + + /** + * 添加文章分类 + * @return Json + */ + public function articleCatAdd(): Json + { + // 新增记录 + $model = new CategoryModel; + if ($model->add($this->postForm())) { + return $this->renderSuccess('添加成功'); + } + return $this->renderError($model->getError() ?: '添加失败'); + } + + /** + * 编辑文章分类 + * @param int $categoryId + * @return Json + */ + public function articleCatEdit(int $categoryId): Json + { + // 分类详情 + $model = CategoryModel::detail($categoryId); + // 更新记录 + if ($model->edit($this->postForm())) { + return $this->renderSuccess('更新成功'); + } + return $this->renderError($model->getError() ?: '更新失败'); + } + + /** + * 删除文章分类 + * @param int $categoryId + * @return Json + */ + public function articleCatDelete(int $categoryId): Json + { + $model = CategoryModel::detail($categoryId); + if (!$model->remove($categoryId)) { + return $this->renderError($model->getError() ?: '删除失败'); + } + return $this->renderSuccess('删除成功'); + } + + /** + * 文章列表 + * @return Json + * @throws \think\db\exception\DbException + */ + public function articleList(): Json + { + $model = new ArticleModel; + $list = $model->getList($this->request->param()); + return $this->renderSuccess(compact('list')); + } + + + /** + * 文章详情 + * @param int $articleId + * @return Json + */ + public function articleDetail(int $articleId): Json + { + $detail = \app\store\model\Article::detail($articleId); + // 获取image (这里不能用with因为编辑页需要image对象) + !empty($detail) && $detail['image']; + return $this->renderSuccess(compact('detail')); + } + + /** + * 添加文章 + * @return Json + */ + public function articleAdd(): Json + { + // 新增记录 + $model = new ArticleModel; + if ($model->add($this->postForm())) { + return $this->renderSuccess('添加成功'); + } + return $this->renderError($model->getError() ?: '添加失败'); + } + + /** + * 更新文章 + * @param int $articleId + * @return Json + */ + public function articleEdit(int $articleId): Json + { + // 文章详情 + $model = ArticleModel::detail($articleId); + // 更新记录 + if ($model->edit($this->postForm())) { + return $this->renderSuccess('更新成功'); + } + return $this->renderError($model->getError() ?: '更新失败'); + } + + /** + * 删除文章 + * @param int $articleId + * @return Json + */ + public function articleDelete(int $articleId): Json + { + // 文章详情 + $model = ArticleModel::detail($articleId); + if (!$model->setDelete()) { + return $this->renderError($model->getError() ?: '删除失败'); + } + return $this->renderSuccess('删除成功'); + } + + } \ No newline at end of file