|
@@ -3,7 +3,8 @@
|
|
|
|
|
|
namespace app\admin\controller;
|
|
|
|
|
|
-
|
|
|
+use app\admin\validate\Category as CategoryValidate;
|
|
|
+use app\common\business\Category as CategoryBusiness;
|
|
|
use think\facade\View;
|
|
|
|
|
|
class Category extends AdminBase
|
|
@@ -25,4 +26,31 @@ class Category extends AdminBase
|
|
|
{
|
|
|
return View::fetch();
|
|
|
}
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 新增
|
|
|
+ * @return \think\response\Json
|
|
|
+ */
|
|
|
+ public function save()
|
|
|
+ {
|
|
|
+ $pid = input("param.pid", 0, "intval");
|
|
|
+ $name = input("param.name", '', "trim");
|
|
|
+
|
|
|
+ // 参数校验
|
|
|
+ $data = [
|
|
|
+ 'pid' => $pid,
|
|
|
+ 'name' => $name
|
|
|
+ ];
|
|
|
+ $validate = new CategoryValidate();
|
|
|
+ if (!$validate->check($data)) {
|
|
|
+ return show(config('status.error'), $validate->getError());
|
|
|
+ }
|
|
|
+
|
|
|
+ try {
|
|
|
+ $result = (new CategoryBusiness)->add($data);
|
|
|
+ } catch (\Exception $e) {
|
|
|
+ return show(config('status.error'), $e->getMessage());
|
|
|
+ }
|
|
|
+ return show(config('status.success'), 'OK');
|
|
|
+ }
|
|
|
}
|