AdminAction.class.php
3.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
<?php
Class AdminAction extends CommonAction{
private $tab;
public function __construct() {
parent::__construct();
$this->tab='Admin';
// $this->rotab='Role';
}
public function index()
{
$Admin=D($this->tab);
import('ORG.Util.Pages');
$map['id']=array('neq',1);
$count = $Admin->where($map)->count();
$Page = new Pages($count,20);
$field=array('id','username','tel','email','name','isshow','ltime','lip','addtime','updatatime');
$lists = $Admin->field($field)->where($map)->page($Page->nowPage.','.$Page->listRows)->order(array('id'=>'desc'))->select();
$show = $Page->show();
$this->assign('page',$show);
$this->assign('lists',$lists);
$this->display();
}
public function edit()
{
$Admin=D($this->tab);
$data=$Admin->where('id='.I('id'))->find();
if($this->isPost()){
//添加用户
if(!$Admin->create()){
$this->error($Admin->getError());
}else{
if(!$Admin->password){ //修改账号,如果没有输入密码则删除password
unset($Admin->password);
}
$lastid=$Admin->where('id='.I('id'))->save();
if($lastid>0){
$this->success('系统用户修改成功',U('Admin/index'));
}else{
$this->error('系统用户修改失败');
}
}
}else{
$this->assign('data',$data);
$this->display();
}
}
public function add()
{
$Admin=D($this->tab);
if($this->isPost()){
//添加用户
if(!$Admin->create()){
$this->error($Admin->getError());
}else{
$depth = $this->getDepth(); //获取depth=array('depth','pid')
$Admin->depth = $depth['depth'];
$Admin->pid = $depth['pid'];
$lastid=$Admin->add();
if($lastid>0){
$this->success('系统用户添加成功',U('Admin/index'));
}else{
$this->error('系统用户添加失败');
}
}
}else{
$this->display();
}
}
/**
* 获取当前登录账号的depth+id
* @return array('id','depth')
*/
private function getDepth(){
$m = M($this->tab);
$map['id'] = array('eq',cookie('ADMIN_KEY'));
$r = $m->field('id,depth')->where($map)->find();
$back['depth'] = $r['depth'].','.$r['id'];
$back['pid'] = $r['id'];
return $back;
}
public function delete()
{
$where['id']=I('id',0,'intval');
$Admin=D($this->tab);
$data=$Admin->where($where)->find();
if(!$data){
$this->error('信息有误!');
}
if($data['id'] == cookie('ADMIN_KEY')){
$this->error('不允许删除当前使用的管理员帐号');
}elseif($data['id'] == 1){
$this->error('该账号不允许删除!');
}else{
$count=$Admin->where($where)->delete();
if($count){
$this->delAuthAccess($data['id']);
$this->success('管理员删除成功',U('Admin/index'));
}else{
$this->error('管理员删除失败');
}
}
}
/**
* 删除会员时删除相应的角色分配
* @param int $uid 用户id
*/
private function delAuthAccess($uid){
if($uid){
$m = M('Authgroupaccess');
$map['uid'] = array('eq',$uid);
$r = $m->where($map)->delete();
}
}
/**
* 修改分组开启属性
**/
public function editattr()
{
$table=$this->_post('table');
$m=M($table);
$where['id']=array('eq',$this->_post('id'));
$data[$this->_post('f')]=$this->_post('status');
$count=$m->where($where)->data($data)->save();
if($count)
{
$msg['success']=true;
$msg['msg']='状态已修改';
}
else
{
$msg['success']=false;
$msg['msg']='状态修改失败';
}
echo json_encode($msg);
}
}
?>