|
|
@ -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('删除失败'); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|