|
@@ -0,0 +1,338 @@
|
|
|
+<?php
|
|
|
+namespace Admin\Controller;
|
|
|
+
|
|
|
+use Think\Controller;
|
|
|
+use Common\Controller\AuthController;
|
|
|
+use Think\Auth;
|
|
|
+
|
|
|
+class SysController extends AuthController
|
|
|
+{
|
|
|
+
|
|
|
+ /************************************管理员模块****************************************/
|
|
|
+
|
|
|
+ public function admin_list()
|
|
|
+ {
|
|
|
+ $admin_mod = new \Common\Model\AdminModel();
|
|
|
+ $page = $this->myGet('p', 0);
|
|
|
+ $field = '*';
|
|
|
+ $page_size = 20;
|
|
|
+ $val = I('val');
|
|
|
+ $auth = new Auth();
|
|
|
+ if ($val) {
|
|
|
+ $where['admin_username'] = array('like', "%" . $val . "%");
|
|
|
+ }
|
|
|
+ $where['admin_type'] = 1;
|
|
|
+ $admin_list = $admin_mod->x_get_list($where, $page, $page_size, $field, 'admin_id asc');
|
|
|
+ $count = $admin_mod->x_count($where);
|
|
|
+ $pager = $admin_mod->x_show($count, $page_size);
|
|
|
+ foreach ($admin_list as $k => $v) {
|
|
|
+ $group = $auth->getGroups($v['admin_id']);
|
|
|
+ $admin_list[$k]['group'] = $group[0]['title'];
|
|
|
+ }
|
|
|
+
|
|
|
+ $this->assign('pager', $pager);
|
|
|
+ $this->assign('admin_list', $admin_list);
|
|
|
+ $this->display();
|
|
|
+ }
|
|
|
+
|
|
|
+ public function admin_list_runedit()
|
|
|
+ {
|
|
|
+ if (IS_POST) {
|
|
|
+ $admin = M('admin');
|
|
|
+ $admin_access = M('auth_group_access');
|
|
|
+ $admin_pwd = I('admin_pwd') ? I('admin_pwd') : '';
|
|
|
+ //随机盐
|
|
|
+ $salt = rand_str(10);
|
|
|
+ $sldata = array(
|
|
|
+ 'admin_username' => I('post.admin_username'),
|
|
|
+ 'admin_email' => '',
|
|
|
+ 'admin_tel' => I('post.admin_tel'),
|
|
|
+ 'admin_open' => 1,
|
|
|
+ 'admin_realname' => I('post.admin_realname'),
|
|
|
+ 'admin_ip' => get_client_ip(),
|
|
|
+ 'admin_addtime' => time(),
|
|
|
+ );
|
|
|
+ if ($admin_pwd) {
|
|
|
+ $sldata['admin_pwd'] = md5($admin_pwd . $salt);
|
|
|
+ $sldata['admin_salt'] = $salt;
|
|
|
+ }
|
|
|
+ $admin_id = I('post.admin_id') ? intval(I('post.admin_id')) : false;
|
|
|
+ if (!$admin_id) {
|
|
|
+ $this->error('非法请求');
|
|
|
+ }
|
|
|
+ $result = $admin->where('admin_id=' . $admin_id)->save($sldata);
|
|
|
+ $accdata = array(
|
|
|
+ 'uid' => $admin_id,
|
|
|
+ 'group_id' => I('post.group_id'),
|
|
|
+ );
|
|
|
+ $admin_access->where('uid=' . $admin_id)->save($accdata);
|
|
|
+ $this->ajaxReturn(1);
|
|
|
+ } else {
|
|
|
+ $admin_mod = M('admin');
|
|
|
+ $admin_access_mod = M('auth_group_access');
|
|
|
+ $admin_id = I('admin_id');
|
|
|
+ $admin_data = $admin_mod->where('admin_id=' . $admin_id)->find();
|
|
|
+ $group_id = $admin_access_mod->where('uid=' . $admin_id)->getfield('group_id');
|
|
|
+ $admin_data['group_id'] = $group_id;
|
|
|
+ $auth_group = M('auth_group')->select();
|
|
|
+ $this->assign('auth_group', $auth_group);
|
|
|
+ $this->assign('admin_data', $admin_data);
|
|
|
+ $this->display('admin_list_edit');
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public function admin_list_runadd()
|
|
|
+ {
|
|
|
+ if (IS_POST) {
|
|
|
+ $admin = M('admin');
|
|
|
+ $admin_access = M('auth_group_access');
|
|
|
+ $admin_pwd = I('admin_pwd') ? I('admin_pwd') : '123456';
|
|
|
+ //随机盐
|
|
|
+ $salt = rand_str(10);
|
|
|
+ $sldata = array(
|
|
|
+ 'admin_username' => I('post.admin_username'),
|
|
|
+ 'admin_pwd' => md5($admin_pwd . $salt),
|
|
|
+ 'admin_salt' => $salt,
|
|
|
+ 'admin_email' => '',
|
|
|
+ 'admin_tel' => I('post.admin_tel'),
|
|
|
+ 'admin_open' => 1,
|
|
|
+ 'admin_realname' => I('post.admin_realname'),
|
|
|
+ 'admin_ip' => get_client_ip(),
|
|
|
+ 'admin_addtime' => time(),
|
|
|
+ );
|
|
|
+ $result = $admin->add($sldata);
|
|
|
+ $accdata = array(
|
|
|
+ 'uid' => $result,
|
|
|
+ 'group_id' => I('post.group_id'),
|
|
|
+ );
|
|
|
+ $flag = $admin_access->where($accdata)->find();
|
|
|
+ if (!$flag) {
|
|
|
+ $admin_access->add($accdata);
|
|
|
+ }
|
|
|
+ $this->ajaxReturn(1);
|
|
|
+ } else {
|
|
|
+ $auth_group = M('auth_group')->select();
|
|
|
+ $this->assign('auth_group', $auth_group);
|
|
|
+ $this->display('admin_list_add');
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public function admin_list_del()
|
|
|
+ {
|
|
|
+ $admin_id = I('admin_id');
|
|
|
+ if ($admin_id == 1) {
|
|
|
+ $this->error('管理员不可删除');
|
|
|
+ }
|
|
|
+ $res = M('admin')->where(array('admin_id' => I('admin_id')))->delete();
|
|
|
+ $res = M('auth_group_access')->where(array('uid' => I('admin_id')))->delete();
|
|
|
+ $this->ajaxReturn($res);
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ //用户组管理
|
|
|
+ public function admin_group()
|
|
|
+ {
|
|
|
+ $auth_group = M('auth_group')->select();
|
|
|
+ $this->assign('auth_group', $auth_group);
|
|
|
+ $this->display();
|
|
|
+ }
|
|
|
+
|
|
|
+ //添加用户组
|
|
|
+ public function admin_group_add()
|
|
|
+ {
|
|
|
+ if (!IS_POST) {
|
|
|
+ $this->display();
|
|
|
+ } else {
|
|
|
+ $sldata = array(
|
|
|
+ 'title' => I('title'),
|
|
|
+ 'status' => I('status'),
|
|
|
+ 'addtime' => time(),
|
|
|
+ );
|
|
|
+ $flag = M('auth_group')->add($sldata);
|
|
|
+ $this->success($flag);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ //删除用户组
|
|
|
+ public function admin_group_del()
|
|
|
+ {
|
|
|
+ $flag = M('auth_group')->where(array('id' => I('id')))->delete();
|
|
|
+ $this->ajaxReturn($flag);
|
|
|
+ }
|
|
|
+
|
|
|
+ public function admin_group_edit()
|
|
|
+ {
|
|
|
+ if (!IS_POST) {
|
|
|
+ $group = M('auth_group')->where(array('id' => I('id')))->find();
|
|
|
+ $this->assign('group', $group);
|
|
|
+ $this->display();
|
|
|
+ } else {
|
|
|
+ $sldata = array(
|
|
|
+ 'id' => I('id'),
|
|
|
+ 'title' => I('title'),
|
|
|
+ 'status' => I('status'),
|
|
|
+ );
|
|
|
+ $flag = M('auth_group')->save($sldata);
|
|
|
+ $this->ajaxReturn($flag);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public function admin_group_state()
|
|
|
+ {
|
|
|
+ $id = I('x');
|
|
|
+ $status = M('auth_group')->where(array('id' => $id))->getField('status');//判断当前状态情况
|
|
|
+ if ($status == 1) {
|
|
|
+ $statedata = array('status' => 0);
|
|
|
+ $auth_group = M('auth_group')->where(array('id' => $id))->setField($statedata);
|
|
|
+ $this->success('状态禁止', 1, 1);
|
|
|
+ } else {
|
|
|
+ $statedata = array('status' => 1);
|
|
|
+ $auth_group = M('auth_group')->where(array('id' => $id))->setField($statedata);
|
|
|
+ $this->success('状态开启', 1, 1);
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ public function admin_rule()
|
|
|
+ {
|
|
|
+ $nav = new \Org\Util\Leftnav;
|
|
|
+ $admin_rule = M('auth_rule')->order('sort')->select();
|
|
|
+ $arr = $nav::rule($admin_rule);
|
|
|
+ $this->assign('admin_rule', $arr);//权限列表
|
|
|
+ $this->display('Sys/admin_rule');
|
|
|
+ }
|
|
|
+
|
|
|
+ public function admin_rule_add()
|
|
|
+ {
|
|
|
+ if (IS_AJAX) {
|
|
|
+ $admin_rule = M('auth_rule');
|
|
|
+ I('name') ? trim(I('name')) : $this->error('控/方必填');
|
|
|
+ I('title') ? trim(I('name')) : $this->error('名称必填');
|
|
|
+ $sldata = array(
|
|
|
+ 'name' => I('name'),
|
|
|
+ 'title' => I('title'),
|
|
|
+ 'status' => I('status'),
|
|
|
+ 'sort' => I('sort'),
|
|
|
+ 'addtime' => time(),
|
|
|
+ 'pid' => I('pid'),
|
|
|
+ );
|
|
|
+ $flag = $admin_rule->add($sldata);
|
|
|
+ //$this->redirect('admin_rule');
|
|
|
+ $this->success('权限添加成功');
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public function admin_rule_state()
|
|
|
+ {
|
|
|
+ $id = I('x');
|
|
|
+ $statusone = M('auth_rule')->where(array('id' => $id))->getField('status');//判断当前状态情况
|
|
|
+ if ($statusone == 1) {
|
|
|
+ $statedata = array('status' => 0);
|
|
|
+ $auth_group = M('auth_rule')->where(array('id' => $id))->setField($statedata);
|
|
|
+ $this->success('状态禁止', 1, 1);
|
|
|
+ } else {
|
|
|
+ $statedata = array('status' => 1);
|
|
|
+ $auth_group = M('auth_rule')->where(array('id' => $id))->setField($statedata);
|
|
|
+ $this->success('状态开启', 1, 1);
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ public function ruleorder()
|
|
|
+ {
|
|
|
+ if (!IS_AJAX) {
|
|
|
+ $this->error('提交方式不正确', 0, 0);
|
|
|
+ } else {
|
|
|
+ $auth_rule = M('auth_rule');
|
|
|
+ foreach ($_POST as $id => $sort) {
|
|
|
+ $auth_rule->where(array('id' => $id))->setField('sort', $sort);
|
|
|
+ }
|
|
|
+ $this->success('排序更新成功', U('admin_rule'), 1);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public function admin_rule_edit()
|
|
|
+ {
|
|
|
+ if (IS_AJAX) {
|
|
|
+ $admin_rule = M('auth_rule');
|
|
|
+ $sldata = array(
|
|
|
+ 'id' => I('id'),
|
|
|
+ 'name' => I('name'),
|
|
|
+ 'title' => I('title'),
|
|
|
+ 'status' => I('status'),
|
|
|
+ 'is_show' => I('is_show'),
|
|
|
+ 'pid' => I('pid'),
|
|
|
+ );
|
|
|
+ $admin_rule->save($sldata);
|
|
|
+ $this->success('权限修改成功');
|
|
|
+ } else {
|
|
|
+ $nav = new \Org\Util\Leftnav;
|
|
|
+ $admin_rule = M('auth_rule')->order('sort')->select();
|
|
|
+ $arr = $nav::rule($admin_rule);
|
|
|
+ $this->assign('admin_rule', $arr);//权限列表
|
|
|
+ $admin_rule = M('auth_rule')->where(array('id' => I('id')))->find();
|
|
|
+ $this->assign('rule', $admin_rule);
|
|
|
+ $this->display('Sys/admin_rule_edit');
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public function admin_rule_runedit()
|
|
|
+ {
|
|
|
+ if (!IS_AJAX) {
|
|
|
+ $this->error('提交方式不正确', 0, 0);
|
|
|
+ } else {
|
|
|
+ $admin_rule = M('auth_rule');
|
|
|
+ $sldata = array(
|
|
|
+ 'id' => I('id'),
|
|
|
+ 'name' => I('name'),
|
|
|
+ 'title' => I('title'),
|
|
|
+ 'status' => I('status'),
|
|
|
+ 'css' => I('css'),
|
|
|
+ 'sort' => I('sort'),
|
|
|
+ );
|
|
|
+ $admin_rule->save($sldata);
|
|
|
+ $this->success('权限修改成功', U('admin_rule'), 1);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public function admin_rule_del()
|
|
|
+ {
|
|
|
+ $flag = M('auth_rule')->where(array('id' => I('id')))->delete();
|
|
|
+ $this->ajaxReturn($flag);
|
|
|
+ }
|
|
|
+
|
|
|
+ //三重权限配置
|
|
|
+ public function admin_group_access()
|
|
|
+ {
|
|
|
+ $admin_group = M('auth_group')->where(array('id' => I('id')))->find();
|
|
|
+ $m = M('auth_rule');
|
|
|
+ $data = $m->field('id,name,title')->where('pid=0')->select();
|
|
|
+ foreach ($data as $k => $v) {
|
|
|
+ $data[$k]['sub'] = $m->field('id,name,title')->where('pid=' . $v['id'])->select();
|
|
|
+ foreach ($data[$k]['sub'] as $kk => $vv) {
|
|
|
+ $data[$k]['sub'][$kk]['sub'] = $m->field('id,name,title')->where('pid=' . $vv['id'])->select();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ $this->assign('admin_group', $admin_group); // 顶级
|
|
|
+ $this->assign('data', $data); // 顶级
|
|
|
+ $this->display();
|
|
|
+ }
|
|
|
+
|
|
|
+ public function admin_group_runaccess()
|
|
|
+ {
|
|
|
+ $m = M('auth_group');
|
|
|
+ $new_rules = I('new_rules');
|
|
|
+ $imp_rules = implode(',', $new_rules) . ',';
|
|
|
+ $sldata = array(
|
|
|
+ 'id' => I('id'),
|
|
|
+ 'rules' => $imp_rules,
|
|
|
+ );
|
|
|
+ if ($m->save($sldata)) {
|
|
|
+ $this->success('权限配置成功', U('admin_group'));
|
|
|
+ //$this->redirect('admin_group');
|
|
|
+ } else {
|
|
|
+ $this->error('权限配置失败');
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|