// +---------------------------------------------------------------------- declare(strict_types=1); namespace addon\iot\controller\backend; use think\facade\View; use ywxapp\controller\BackendBase; use addon\iot\service\GroupService; /** * 设备分组控制器(后台全局分组管理) */ class Groups extends BackendBase { /** * 分组列表页(分组数据以 JSON 注入,前端 layui.table 本地渲染) */ public function group() { $list = GroupService::groups(0); View::assign('groupsJson', (string) json_encode($list, JSON_UNESCAPED_UNICODE | JSON_HEX_TAG | JSON_HEX_AMP | JSON_HEX_APOS | JSON_HEX_QUOT)); return View::fetch('admin/group'); } public function saveGroup() { try { $data = $this->request->post(); $data['member_id'] = 0; // 后台全局分组 GroupService::save($data); } catch (\Throwable $e) { $this->result->error('保存失败:' . $e->getMessage()); } $this->result->success('保存成功'); } public function deleteGroup() { $id = (int) input('post.id', 0); try { GroupService::remove($id, 0); } catch (\Throwable $e) { $this->result->error($e->getMessage()); } $this->result->success('已删除'); } }