You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
271 lines
8.4 KiB
271 lines
8.4 KiB
<?php
|
|
|
|
namespace app\account\controller\admin;
|
|
|
|
use app\account\model\Nickname;
|
|
use app\auth\model\AuthGroup;
|
|
use app\auth\model\AuthGroupRule;
|
|
use app\auth\model\AuthRule;
|
|
use app\system\logic\Login;
|
|
use app\system\model\SystemLoginer;
|
|
use think\facade\View;
|
|
|
|
class Account extends Base
|
|
{
|
|
/**
|
|
* 子账号列表
|
|
* @return string
|
|
*/
|
|
public function account()
|
|
{
|
|
$search = input('get.');
|
|
autoSearch(['time', 'keyword'], $search);
|
|
$system_login_er_model = new SystemLoginer();
|
|
$where = [
|
|
['status', '>=', 0],
|
|
['rank', '>=', 1],
|
|
];
|
|
if ($search['time']) {
|
|
$time = explode('-', $search['time']);
|
|
$where[] = ['create_time', 'between time', [$time[0], $time[1]]];
|
|
}
|
|
if ($search['keyword']) {
|
|
$where[] = ['username', 'like', '%' . $search['keyword'] . '%'];
|
|
}
|
|
$dataList = $system_login_er_model
|
|
->with(['loginGroup'])->where($where)->order('id desc')
|
|
->paginate([
|
|
'list_rows' => 20,
|
|
'page' => array_key_exists("page", $search) ? (string)$search['page'] : "1",
|
|
'query' => $search
|
|
], false);
|
|
View::assign('search', $search);
|
|
View::assign('dataList', $dataList);
|
|
|
|
return View::fetch();
|
|
}
|
|
|
|
/**
|
|
* 子账号添加 2017-10-15
|
|
*/
|
|
public function accountAdd()
|
|
{
|
|
$system_loginer_model = new SystemLoginer();
|
|
if (request()->isPost()) {
|
|
$data = input('post.');
|
|
|
|
if ($data['password'] != $data['repassword']) {
|
|
return sendErrorMessage(1,'添加失败,密码和重复密码不一致!');
|
|
}
|
|
|
|
$is_username = $system_loginer_model->getOneData([['username', '=', $data['username']], ['id', 'not in', (string)$data['id']]]);
|
|
if (!empty($is_username)) {
|
|
return sendErrorMessage(1,'用户名重复,请更换用户名');
|
|
}
|
|
$data['password_real'] = $data['password'];
|
|
if (!$data['id']) {
|
|
$Login = new Login();
|
|
$loginerid = $Login->register($data['username'], $data['password']);
|
|
if ($loginerid > 0) { //注册成功
|
|
$my = $system_loginer_model->getOneData([['id','=', LID]]);
|
|
$userData = [
|
|
'id' => $loginerid,
|
|
'uid' => UID,
|
|
'pid' => LID,
|
|
'rank' => $my['rank'] + 1,
|
|
'register_time' => time(),
|
|
'register_ip' => getClientIp(1),
|
|
'role_id' => $data['role_id'],
|
|
'status' => 1
|
|
];
|
|
if (!empty($data['end_time'])) {
|
|
$userData['end_time'] = strtotime($data['end_time']);
|
|
}
|
|
$res = $system_loginer_model->dataUpdate($userData);
|
|
if (!$res) {
|
|
return sendErrorMessage();
|
|
}
|
|
return sendSuccessMessage();
|
|
} else {
|
|
return sendErrorMessage(1,'用户名重复,请更换用户名');
|
|
}
|
|
} else {
|
|
if (!empty($data['password'])) {
|
|
$arr = ['password' => $data['password']];
|
|
$Login = new Login();
|
|
$res1 = $Login->updateUserInfo($data['id'], false, $arr);
|
|
}
|
|
unset($data['password']);
|
|
if (!empty($data['end_time'])) {
|
|
$data['end_time'] = strtotime($data['end_time']);
|
|
} else {
|
|
unset($data['end_time']);
|
|
}
|
|
$res = $system_loginer_model->dataUpdate($data);
|
|
if (!$res) {
|
|
return sendErrorMessage();
|
|
}
|
|
return sendSuccessMessage();
|
|
}
|
|
} else {
|
|
$id = input('param.id', 0);
|
|
$data = $system_loginer_model->getOneData(['id' => $id]);
|
|
$auth_group_model = new AuthGroup();
|
|
$groupList = $auth_group_model->getAllData(['status' => 1]);
|
|
|
|
if (!empty($data['end_time'])) {
|
|
$data['end_time'] = date('Y-m-d H:i:s', $data['end_time']);
|
|
}
|
|
|
|
View::assign('data', $data);
|
|
View::assign('groupList', $groupList);
|
|
return View::fetch('accountadd');
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 子账号修改
|
|
*/
|
|
public function accountUpdate()
|
|
{
|
|
return $this->accountadd();
|
|
}
|
|
|
|
/**
|
|
* 子账号修改状态
|
|
* @return array|string
|
|
* @throws \think\Exception
|
|
*/
|
|
public function accountStatus()
|
|
{
|
|
$data = input('post.');
|
|
$system_loginer_model = new SystemLoginer();
|
|
//修改子账号ID
|
|
$res = $system_loginer_model->where('id', $data['id'])->update(['status' => $data['afterchange']]);
|
|
if ($res === false) {
|
|
return sendErrorMessage(1);
|
|
}
|
|
return sendSuccessMessage();
|
|
}
|
|
|
|
/**
|
|
* 角色列表
|
|
*
|
|
*/
|
|
public function role()
|
|
{
|
|
$search = input('get.');
|
|
autoSearch(['time', 'keyword'], $search);
|
|
View::assign('search', $search);
|
|
$where = [
|
|
'status' => 1,
|
|
];
|
|
$auth_group_model = new AuthGroup();
|
|
// dump(111);exit();
|
|
$page = array_key_exists("page", $search) ? (string)$search['page'] : "1";
|
|
$dataList = $auth_group_model
|
|
->where($where)->order('id asc')
|
|
->paginate(['list_rows' => 50, 'page' => $page], false)->each(function ($item, $key) {
|
|
return $item;
|
|
});
|
|
View::assign('dataList', $dataList);
|
|
|
|
return View::fetch();
|
|
}
|
|
|
|
/**
|
|
* 角色添加
|
|
*/
|
|
public function roleAdd()
|
|
{
|
|
$auth_group_model = new AuthGroup();
|
|
if (request()->isPost()) {
|
|
$data = input('post.');
|
|
$data['uid'] = UID;
|
|
//事务处理
|
|
$res = $auth_group_model->dataUpdate($data);
|
|
if (!$res) {
|
|
return sendErrorMessage(1);
|
|
}
|
|
return sendSuccessMessage();
|
|
} else {
|
|
$id = input('param.id', 0);
|
|
$data = $auth_group_model->getOneData(['id' => $id]);
|
|
View::assign('data', $data);
|
|
return View::fetch('roleadd');
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 角色修改 2017-10-15
|
|
*/
|
|
public function roleUpdate()
|
|
{
|
|
return $this->roleadd();
|
|
}
|
|
|
|
/**
|
|
* 删除角色
|
|
* @auth Alan
|
|
* @time 2019-03-11
|
|
* @return array|string
|
|
*/
|
|
public function roleDelete()
|
|
{
|
|
$id = input('post.id/d', 0);
|
|
//删除角色同时删除角色关联权限
|
|
$res = AuthGroup::destroy($id);
|
|
if ($res === false) {
|
|
return sendErrorMessage(1);
|
|
}
|
|
$loginer_model = new SystemLoginer();
|
|
$auth_group_rule_model = new AuthGroupRule();
|
|
|
|
$loginer_count = $loginer_model->where(['role_id'=>$id])->count();
|
|
if($loginer_count)
|
|
{
|
|
return sendErrorMessage(1,'该角色已赋予账号,不可删除');
|
|
}
|
|
$res = $auth_group_rule_model->where(['role_id' => $id])->delete();
|
|
if ($res === false) {
|
|
return sendErrorMessage(1);
|
|
}
|
|
|
|
return sendSuccessMessage();
|
|
}
|
|
|
|
/*
|
|
* 角色授权
|
|
*/
|
|
|
|
public function roleSetAuth()
|
|
{
|
|
$auth_group_model = new AuthGroup();
|
|
$auth_group_rule_model = new AuthGroupRule();
|
|
$auth_rule_model = new AuthRule();
|
|
if (request()->isPost()) {
|
|
$data = input('post.');
|
|
$rule_list = [];
|
|
if (!empty($data['authrule'])) {
|
|
$rule_list = $data['authrule'];
|
|
}
|
|
//事务处理
|
|
$res = $auth_group_rule_model->saveData($data['id'], $rule_list);
|
|
if (!$res) {
|
|
return sendErrorMessage(1);
|
|
}
|
|
return sendSuccessMessage();
|
|
} else {
|
|
$id = input('param.id');
|
|
$data = $auth_group_model->getOneData(['id' => $id]);
|
|
View::assign('data', $data);
|
|
$auth = $auth_rule_model->getLevelData();
|
|
View::assign('auth', $auth);
|
|
$ids = $auth_group_rule_model->getIds($id);
|
|
View::assign('rule_ids', $ids);
|
|
return View::fetch('rolesetauth');
|
|
}
|
|
}
|
|
|
|
}
|