更新用户功能

This commit is contained in:
2020-03-28 16:34:06 +08:00
parent c7a28d9530
commit 89dbc43aea
10 changed files with 193 additions and 72 deletions

View File

@@ -9,7 +9,11 @@
namespace app\controller\admin;
use think\facade\Cache;
use app\model\Member;
use app\model\AuthGroup;
use app\model\AuthGroupAccess;
/**
* @title 用户管理
*/
@@ -34,15 +38,18 @@ class User extends Base {
*/
public function add(Member $member) {
if ($this->request->isPost()) {
$data = $this->request->param();
//创建注册用户
$result = $member->register($data['username'], $data['password'], $data['repassword'], $data['email'], false);
$result = $member->register($this->request);
if ($result) {
return $this->success('用户添加成功!', url('admin/user/index'));
return $this->success('用户添加成功!', url('/admin/user/index'));
} else {
return $this->error($model->getError());
}
} else {
$this->data = array(
'info' => [],
'keyList' => $member->addfield,
);
return $this->fetch('admin/public/edit');
}
}
@@ -51,26 +58,23 @@ class User extends Base {
* @title 修改用户
* @author huajie <banhuajie@163.com>
*/
public function edit() {
$model = model('Member');
public function edit(Member $member) {
if ($this->request->isPost()) {
$data = $this->request->post();
$reuslt = $model->editUser($data, true);
$reuslt = $member->editUser($this->request);
if (false !== $reuslt) {
return $this->success('修改成功!', url('admin/user/index'));
return $this->success('修改成功!', url('/admin/user/index'));
} else {
return $this->error($model->getError(), '');
return $this->error('修改失败');
}
} else {
$info = $this->getUserinfo();
$this->data = array(
'info' => $info,
'keyList' => $model->editfield,
'keyList' => $member->editfield,
);
return $this->fetch('public/edit');
return $this->fetch('admin/public/edit');
}
}
@@ -91,27 +95,28 @@ class User extends Base {
* @author colin <colin@tensent.cn>
*/
public function auth() {
$access = model('AuthGroupAccess');
$group = model('AuthGroup');
$uid = $this->request->param('id', 0, 'trim,intval');
if ($this->request->isPost()) {
$uid = input('uid', '', 'trim,intval');
$access->where(array('uid' => $uid))->delete();
$group_type = config('user_group_type');
foreach ($group_type as $key => $value) {
$group_id = input($key, '', 'trim,intval');
if ($group_id) {
$add = array(
'uid' => $uid,
'group_id' => $group_id,
);
$access->save($add);
$data = $this->request->post();
$config = Cache::get('system_config_data');
$group_type = isset($config['user_group_type']) ? $config['user_group_type'] : [];
$add = [];
foreach ($group_type as $value) {
if (isset($data[$value['key']]) && $data[$value['key']]) {
$add[] = ['uid' => $uid, 'group_id' => $data[$value['key']]];
}
}
return $this->success("设置成功!");
AuthGroupAccess::where('uid', $uid)->delete();
$result = (new AuthGroupAccess())->saveAll($add);
if (false !== $result) {
return $this->success("设置成功!");
}else{
return $this->error('设置失败!');
}
} else {
$uid = input('id', '', 'trim,intval');
$row = $group::select();
$auth = $access::where(array('uid' => $uid))->select();
$row = AuthGroup::select();
$auth = AuthGroupAccess::where(array('uid' => $uid))->select();
$auth_list = array();
foreach ($auth as $key => $value) {
@@ -120,13 +125,11 @@ class User extends Base {
foreach ($row as $key => $value) {
$list[$value['module']][] = $value;
}
$data = array(
$this->data = array(
'uid' => $uid,
'auth_list' => $auth_list,
'list' => $list,
);
$this->assign($data);
$this->setMeta("用户分组");
return $this->fetch();
}
}
@@ -139,7 +142,6 @@ class User extends Base {
* @author colin <colin@tensent.cn>
*/
private function getUserinfo($uid = null, $pass = null, $errormsg = null) {
$user = model('Member');
$uid = $uid ? $uid : input('id');
//如果无UID则修改当前用户
$uid = $uid ? $uid : session('user_auth.uid');
@@ -148,7 +150,7 @@ class User extends Base {
unset($map);
$map['password'] = $pass;
}
$list = $user::where($map)->field('uid,username,nickname,sex,email,qq,score,signature,status,salt')->find();
$list = Member::where($map)->field('uid,username,nickname,sex,email,qq,score,signature,status,salt')->find();
if (!$list) {
return $this->error($errormsg ? $errormsg : '不存在此用户!');
}
@@ -203,14 +205,15 @@ class User extends Base {
*/
public function editpwd() {
if ($this->request->isPost()) {
$user = model('Member');
$data = $this->request->post();
$data['salt'] = \xin\helper\Str::random(6);
$res = $user->editpw($data);
if ($res) {
return $this->success('修改密码成功!');
$reuslt = Member::update($data, ['uid' => $data['uid']]);
if (false !== $reuslt) {
return $this->success('修改成功!', url('/admin/user/index'));
} else {
return $this->error($user->getError());
return $this->error('修改失败');
}
} else {
return $this->fetch();