authService = new AuthService(); $this->departmentModel = new DepartmentModel(); } public function index() { return view(); } /** * @return \think\response\Json|\think\response\View * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\DbException * @throws \think\db\exception\ModelNotFoundException */ public function add() { $all_department = $this->departmentModel->findAllDepartment(); if ($this->request->isAjax()) { $params = $this->request->param(); $res = $this->authService->authGroupModel->save([ 'pid' => 0, 'name' => format_string($params['name'] ?? null), 'rules' => format_string($params['rule_ids'] ?? null), "reception_rules" => isset($params["reception_rules"]) ? join(',', $params['reception_rules']) : null, "data_rules" => isset($params["data_rules"]) ? join(',', $params['data_rules']) : null, "department_id" => format_string($params['department_id'] ?? null), 'describe' => format_string($params['describe'] ?? null), ]); return $this->ok($res); } View::assign([ "reception_rules" => fetchReceptionRules(), "all_department" => recursion($all_department, 0) ]); return view(); } /** * @return \think\response\Json|\think\response\View * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\DbException * @throws \think\db\exception\ModelNotFoundException */ public function edit() { $params = $this->request->param(); $id = $params['id']; $group = $this->authService->authGroupModel->findById($id); $all_department = $this->departmentModel->findAllDepartment(); if ($this->request->isAjax()) { $res = $this->authService->authGroupModel->where('id', $params['id'])->save([ 'pid' => 0, 'name' => $params['name'] ?? $group->name, 'rules' => !isset($params['rule_ids']) ? null : $params['rule_ids'], "reception_rules" => isset($params["reception_rules"]) ? join(',', $params['reception_rules']) : null, "data_rules" => isset($params["data_rules"]) ? join(',', $params['data_rules']) : null, "department_id" => format_string($params['department_id'] ?? null), 'describe' => $params['describe'] ?? $group->describe, 'update_time' => time() ]); return $this->ok($res); } $reception_rule_ids = $group->reception_rules ? explode(',',$group->reception_rules) : []; $reception_rules = array_merge([], fetchReceptionRules()); foreach ($reception_rules as &$item) $item['isChecked'] = in_array($item['id'], $reception_rule_ids); $data_rule_ids = $group->data_rules ? explode(',', $group->data_rules) : []; $data_rules = array_merge([], fetchReceptionRules()); foreach ($data_rules as &$item) $item['isChecked'] = in_array($item['id'], $data_rule_ids); View::assign([ 'group' => $group, "reception_rules" => $reception_rules, "data_rules" => $data_rules, "all_department" => recursion($all_department, 0) ]); return view(); } public function delete(\think\Request $request) { $params = $request->param(); if(!isset($params['ids'])) return $this->fail(lang("Please select the data you want to delete")); $this->authService->authGroupModel->deleteByIds(explode(',', $params['ids'])); return $this->ok(true); } public function findAllAuthGroups() { $groups = $this->authService->authGroupModel->fetchAllGroups()->toArray(); $format_groups = array_map(function ($data) { return [ 'id' => $data['id'], 'title' => $data['name'], 'field' => $data['name'], 'spread' => true, 'checked' => false, 'disabled' => $data['id'] == 1 ]; }, $groups); return $this->ok($format_groups); } }