* +---------------------------------------------------------------------- */ namespace app\adminapi\controller\v1\setting; use app\adminapi\controller\AuthController; use app\services\system\SystemRouteCateServices; use app\services\system\SystemRouteServices; use think\facade\App; use think\Request; /** * Class SystemRouteCate * @author 等风来 * @email 136327134@qq.com * @date 2023/4/6 * @package app\adminapi\controller\v1\setting */ class SystemRouteCate extends AuthController { /** * SystemRouteCate constructor. * @param App $app * @param SystemRouteCateServices $services */ public function __construct(App $app, SystemRouteCateServices $services) { parent::__construct($app); $this->services = $services; } /** * @return \think\Response * @author 等风来 * @email 136327134@qq.com * @date 2023/4/6 */ public function index() { return app('json')->success($this->services->getAllList()); } /** * @return \think\Response * @author 等风来 * @email 136327134@qq.com * @date 2023/4/6 */ public function create() { return app('json')->success($this->services->getFrom()); } /** * @param Request $request * @return \think\Response * @author 等风来 * @email 136327134@qq.com * @date 2023/4/6 */ public function save(Request $request) { $data = $request->postMore([ ['pid', 0], ['name', ''], ['sort', 0], ['app_name', ''], ]); if (!$data['name']) { return app('json')->fail('缺少分类名称'); } $data['add_time'] = time(); $res = $this->services->save($data); $path = $this->services->getPathValue($data['pid']); $path = $this->services->setPathValue($path, $res->id); $res->path = $path; $res->save(); return app('json')->success('保存成功'); } /** * @param $id * @return \think\Response * @author 等风来 * @email 136327134@qq.com * @date 2023/4/6 */ public function edit($id) { return app('json')->success($this->services->getFrom($id)); } /** * @param Request $request * @param $id * @return \think\Response * @author 等风来 * @email 136327134@qq.com * @date 2023/4/6 */ public function update(Request $request, $id) { $data = $request->postMore([ ['pid', 0], ['name', ''], ['sort', 0], ['app_name', ''], ]); if (!$data['name']) { return app('json')->fail('缺少分类名称'); } $pid = $this->services->value($id, 'pid'); if ($data['pid'] != $pid) { $path = $this->services->getPathValue($data['pid']); $data['path'] = $this->services->setPathValue($path, $id); } $this->services->update($id, $data); return app('json')->success('修改成功'); } /** * @param SystemRouteServices $service * @param $id * @return \think\Response * @author 等风来 * @email 136327134@qq.com * @date 2023/4/6 */ public function delete(SystemRouteServices $service, $id) { if (!$id) { return app('json')->fail('缺少参数'); } if ($service->count(['cate_id' => $id])) { return app('json')->fail('请先删除分类下的接口'); } $this->services->delete($id); return app('json')->success('删除成功'); } }