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