pull/1/head
wanghousheng 10 months ago
parent 861aa9519d
commit 6f5d5d2b84
  1. 2
      app/common/model/ServerCategory.php
  2. 40
      app/store/controller/Server.php
  3. 5
      app/store/model/ServerCategory.php

@ -29,7 +29,7 @@ class ServerCategory extends BaseModel
* @notes:分类详情 * @notes:分类详情
* @param $where * @param $where
* @param array $with * @param array $with
* @return ServerCategory|array|null * @return static|array|null
* @author: wanghousheng * @author: wanghousheng
*/ */
public static function detail($where, array $with = []) public static function detail($where, array $with = [])

@ -38,18 +38,12 @@ class Server extends Controller
*/ */
public function addCategory(): Json public function addCategory(): Json
{ {
$name = $this->request->post('name'); $data = $this->postForm();
if (!$name) { if (!$data) {
return $this->renderError('名称不能为空'); return $this->renderError('缺少必要参数');
}
$image_id = intval($this->request->post('image_id'));
if (!$image_id) {
return $this->renderError('图片不能为空');
} }
$status = intval($this->request->post('status'));
$sort = intval($this->request->post('sort'));
$model = new ServerCategory(); $model = new ServerCategory();
if ($model->add(compact('image_id', 'name', 'status', 'sort'))) { if ($model->add($data)) {
return $this->renderSuccess('添加成功'); return $this->renderSuccess('添加成功');
} }
return $this->renderError($model->getError() ?: '添加失败'); return $this->renderError($model->getError() ?: '添加失败');
@ -63,21 +57,23 @@ class Server extends Controller
*/ */
public function editCategory(int $categoryId) public function editCategory(int $categoryId)
{ {
$name = $this->request->post('name'); $data = $this->postForm();
if (!$name) { if (!$data) {
return $this->renderError('名称不能为空'); return $this->renderError('缺少必要参数');
} }
$image_id = intval($this->request->post('image_id')); $model = ServerCategory::detail($categoryId);
if (!$image_id) { if ($model->edit($data)) {
return $this->renderError('图片不能为空');
}
$status = intval($this->request->post('status'));
$sort = intval($this->request->post('sort'));
$category_id = $categoryId;
$model = new ServerCategory();
if ($model->edit(compact('image_id', 'name', 'status', 'sort', 'category_id'))) {
return $this->renderSuccess('编辑成功'); return $this->renderSuccess('编辑成功');
} }
return $this->renderError($model->getError() ?: '编辑失败'); return $this->renderError($model->getError() ?: '编辑失败');
} }
public function deleteCategory(int $categoryId)
{
$model = ServerCategory::detail($categoryId);
if ($model->remove()) {
return $this->renderSuccess('删除成功');
}
return $this->renderError('删除失败');
}
} }

@ -4,6 +4,11 @@ namespace app\store\model;
use app\common\model\ServerCategory as ServerCategoryModel; use app\common\model\ServerCategory as ServerCategoryModel;
/**
* 服务分类模型
* Class ServerCategory
* @package app\store\model
*/
class ServerCategory extends ServerCategoryModel class ServerCategory extends ServerCategoryModel
{ {
/** /**

Loading…
Cancel
Save