|
|
|
@ -89,6 +89,68 @@ class Article extends Controller |
|
|
|
|
return $this->renderError('添加失败'); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* @notes:编辑文章 |
|
|
|
|
* @return Json |
|
|
|
|
* @throws BaseException |
|
|
|
|
* @author: wanghousheng |
|
|
|
|
*/ |
|
|
|
|
public function edit(): Json |
|
|
|
|
{ |
|
|
|
|
if (!UserService::isStore()) { |
|
|
|
|
throwError("无权限", 403); |
|
|
|
|
} |
|
|
|
|
$articleId = intval($this->request->post('article_id')); |
|
|
|
|
if (!$articleId) { |
|
|
|
|
return $this->renderError('缺少必要参数'); |
|
|
|
|
} |
|
|
|
|
$title = $this->request->post('title'); |
|
|
|
|
if (!$title) { |
|
|
|
|
return $this->renderError('标题不能为空'); |
|
|
|
|
} |
|
|
|
|
$category_id = intval($this->request->post('category_id')); |
|
|
|
|
if (!$category_id) { |
|
|
|
|
return $this->renderError('分类不能为空'); |
|
|
|
|
} |
|
|
|
|
$image_id = intval($this->request->post('image_id')); |
|
|
|
|
if (!$image_id) { |
|
|
|
|
return $this->renderError('图片不能为空'); |
|
|
|
|
} |
|
|
|
|
$content = $this->request->post('content'); |
|
|
|
|
if (!$content) { |
|
|
|
|
return $this->renderError('内容不能为空'); |
|
|
|
|
} |
|
|
|
|
$sort = intval($this->request->post('sort', 100)); |
|
|
|
|
$status = intval($this->request->post('status', 1)); |
|
|
|
|
$data = compact('status', 'sort', 'content', 'image_id', 'category_id', 'title'); |
|
|
|
|
// 文章详情 |
|
|
|
|
$model = ArticleModel::detail($articleId); |
|
|
|
|
// 更新记录 |
|
|
|
|
if ($model->edit($data)) { |
|
|
|
|
return $this->renderSuccess('更新成功'); |
|
|
|
|
} |
|
|
|
|
return $this->renderError($model->getError() ?: '更新失败'); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* @notes:删除文章 |
|
|
|
|
* @return Json |
|
|
|
|
* @author: wanghousheng |
|
|
|
|
*/ |
|
|
|
|
public function delete(): Json |
|
|
|
|
{ |
|
|
|
|
$articleId = intval($this->request->post('article_id')); |
|
|
|
|
if (!$articleId) { |
|
|
|
|
return $this->renderError('缺少必要参数'); |
|
|
|
|
} |
|
|
|
|
// 文章详情 |
|
|
|
|
$model = ArticleModel::detail($articleId); |
|
|
|
|
if (!$model->setDelete()) { |
|
|
|
|
return $this->renderError($model->getError() ?: '删除失败'); |
|
|
|
|
} |
|
|
|
|
return $this->renderSuccess('删除成功'); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* @notes:添加分类 |
|
|
|
|
* @return Json |
|
|
|
|