getList($this->postData()); $roleModel = new Role(); // 角色列表 $roleList = $roleModel->getTreeData(); return $this->renderSuccess('', compact('list', 'roleList')); } /** * 新增信息 * @return \think\response\Json */ public function addInfo() { $model = new Role(); // 角色列表 $roleList = $model->getTreeData(); return $this->renderSuccess('', compact('roleList')); } /** * 新增 * @return \think\response\Json */ public function add() { $data = $this->postData(); $model = new UserModel(); $num = $model->getUserName(['user_name' => $data['user_name']]); if ($num > 0) { return $this->renderError('用户名已存在'); } if (!isset($data['role_id'])) { return $this->renderError('请选择所属角色'); } if ($data['confirm_password'] != $data['password']) { return $this->renderError('确认密码和登录密码不一致'); } $model = new UserModel(); if ($model->add($data)) { return $this->renderSuccess('添加成功'); } return $this->renderError($model->getError() ?:'添加失败'); } /** * 修改信息 * @param $operations_user_id * @return \think\response\Json */ public function editInfo($operations_user_id) { $info = UserModel::detail(['operations_user_id' => $operations_user_id], ['roles']); // 从关联的角色中提取role_id数组 $role_arr = []; if (isset($info['roles']) && !empty($info['roles'])) { $role_arr = array_column($info['roles']->toArray(), 'role_id'); } $model = new Role(); // 角色列表 $roleList = $model->getTreeData(); return $this->renderSuccess('', compact('info', 'roleList', 'role_arr')); } /** * 编辑 * @param $operations_user_id * @return \think\response\Json */ public function edit($operations_user_id) { $data = $this->postData(); if($this->request->isGet()){ return $this->editInfo($operations_user_id); } $model = new UserModel(); $num = $model->getUserName(['user_name' => $data['user_name']], $data['operations_user_id']); if ($num > 0) { return $this->renderError('用户名已存在'); } if (!isset($data['role_ids'])) { return $this->renderError('请选择所属角色'); } if (isset($data['password']) && !empty($data['password'])) { if (!isset($data['confirm_password'])) { return $this->renderError('请输入确认密码'); } else { if ($data['confirm_password'] != $data['password']) { return $this->renderError('确认密码和登录密码不一致'); } } } if (empty($data['password'])) { if (isset($data['confirm_password']) && !empty($data['confirm_password'])) { return $this->renderError('请输入登录密码'); } } $model=(new UserModel())->detail(['operations_user_id' => $operations_user_id]); // 更新记录 if ($model->edit($data, ['operations_user_id' => $data['operations_user_id']])) { return $this->renderSuccess('更新成功'); } return $this->renderError($model->getError()?:'更新失败'); } /** * 删除 */ public function delete($operations_user_id) { $model = new UserModel(); if ($model->del(['operations_user_id' => $operations_user_id])) { return $this->renderSuccess('删除成功'); } return $this->renderError('删除失败'); } /** * 获取角色菜单信息 */ public function getRoleList() { $user = $this->store['user']; $user_info = (new AuthUserModel())->find($user['operations_user_id']); $model = new AccessModel(); /*if ($user_info['is_super'] == 1) { $menus = $model->getList(); } else {*/ // 获取当前用户的角色集 $roleIds = (new \app\operations\model\auth\UserRole())->getRoleIds($user['operations_user_id']); // 根据已分配的权限 $accessIds = (new \app\operations\model\auth\RoleAccess())->getAccessIds($roleIds); // 获取当前角色所有权限链接 $menus_list = AccessModel::getAccessList($accessIds); // 转换为数组 $menus_list = $menus_list ? $menus_list->toArray() : []; // 格式化 $menus = $model->recursiveMenuArray($menus_list, 0); // 处理数组下标 $menus = array_values($model->foo($menus)); foreach ($menus as $key => $val) { if (isset($val['children'][0]['path']) && $val['redirect_name'] != $val['children'][0]['path']) { $menus[$key]['redirect_name'] = $menus[$key]['children'][0]['path']; } } //} return $this->renderSuccess('', compact('menus')); } /** * 获取用户信息 */ public function getUserInfo() { $store = session('jjjshop_operations'); $user = []; if (!empty($store)) { $user = $store['user']; } // 商城名称 $shop_name = SettingModel::getItem('store')['name']; //当前系统版本 $version = get_version(); return $this->renderSuccess('', compact('user', 'shop_name', 'version')); } }