149 lines
4.3 KiB
PHP
149 lines
4.3 KiB
PHP
<?php
|
||
// +------------------------------------------------+
|
||
// |http://www.cjango.com |
|
||
// +------------------------------------------------+
|
||
// | 修复BUG不是一朝一夕的事情,等我喝醉了再说吧! |
|
||
// +------------------------------------------------+
|
||
// | Author: 小陈叔叔 <Jason.Chen> |
|
||
// +------------------------------------------------+
|
||
namespace app\system\controller;
|
||
|
||
use app\common\model\Auth as AuthModel;
|
||
use app\common\model\Member as MemberModel;
|
||
use app\common\service\Auth as AuthService;
|
||
use think\Request;
|
||
|
||
class Auth extends _Init
|
||
{
|
||
/**
|
||
* 授权列表
|
||
* @return [type] [description]
|
||
*/
|
||
public function index()
|
||
{
|
||
$map['status'] = ['egt', 0];
|
||
|
||
$this->list = AuthModel::where($map)->paginate();
|
||
return $this->fetch();
|
||
}
|
||
/**
|
||
* 添加授权分组
|
||
* @param Request $request 要添加的分组数据
|
||
*/
|
||
public function add(Request $request)
|
||
{
|
||
if (IS_POST) {
|
||
$data = $request->post();
|
||
$result = AuthService::add($data);
|
||
return $this->back($result);
|
||
} else {
|
||
return $this->fetch();
|
||
}
|
||
}
|
||
/**
|
||
* 编辑授权分组
|
||
* @param [type] $id 授权分组id
|
||
* @return [type] [description]
|
||
*/
|
||
public function edit(Request $request, $id)
|
||
{
|
||
if (IS_POST) {
|
||
$data = $request->post();
|
||
$result = AuthService::edit($data);
|
||
return $this->back($result);
|
||
} else {
|
||
$this->info = AuthModel::get($id);
|
||
return $this->fetch('add');
|
||
}
|
||
}
|
||
|
||
/**
|
||
* 删除分组
|
||
* @param [type] $id 授权分组 id
|
||
* @return [type] [description]
|
||
*/
|
||
public function del($id)
|
||
{
|
||
$result = AuthService::del($id);
|
||
return $this->back($result);
|
||
}
|
||
|
||
/**
|
||
* 设置分组状态 正常 和 禁用
|
||
* @param [type] $id 授权分组 id
|
||
* @param [type] $status 成功 还是 失败 失败返回失败的信息
|
||
* @return [type] [description]
|
||
*/
|
||
public function status($id, $status)
|
||
{
|
||
$result = AuthService::status($id, $status);
|
||
return $this->back($result);
|
||
}
|
||
|
||
/**
|
||
* 菜单授权
|
||
* @param [type] $id 授权分组id
|
||
* @return [type] [description]
|
||
*/
|
||
public function menu(Request $request, $id)
|
||
{
|
||
if (IS_POST) {
|
||
$rules = $request->post('rules/a');
|
||
$result = AuthService::setAuthRuels($id, $rules);
|
||
return $this->back($result);
|
||
} else {
|
||
$this->assign('node_list', AuthService::getAuthRules($id));
|
||
return $this->fetch();
|
||
}
|
||
}
|
||
|
||
/**
|
||
* 用户授权页面
|
||
* @param Request $request 提交的信息
|
||
* @param [type] $id 分组id
|
||
* @return [type] 用户列表
|
||
*/
|
||
public function user(Request $request, $id)
|
||
{
|
||
$authed = AuthService::getAuthedUids($id);
|
||
|
||
if (IS_POST) {
|
||
$username = $request->post('username');
|
||
$list = MemberModel::field('id,username')->whereOr(function ($query) use ($username) {
|
||
$query->whereOr('id', $username)->whereOr('username', 'like', "%{$username}%");
|
||
})->where('status', 1)->where('id', 'notin', $authed)->limit(10)->select();
|
||
foreach ($list as $key => &$value) {
|
||
$value['nickname'] = $value->info->nickname;
|
||
}
|
||
return $this->success('', '', $list);
|
||
} else {
|
||
$this->list = MemberModel::where('status', 1)->where('id', 'in', $authed)->paginate();
|
||
return $this->fetch();
|
||
}
|
||
}
|
||
|
||
/**
|
||
* 把用户移除分组
|
||
* @param [type] $id 分组id
|
||
* @param [type] $uid 用户id
|
||
* @return [type] 返回结果
|
||
*/
|
||
public function remove($id, $uid)
|
||
{
|
||
$result = AuthService::removeAuthUser($id, $uid);
|
||
return $this->back($result);
|
||
}
|
||
|
||
/**
|
||
* 设置用户授权
|
||
* @param [type] $id 分组id
|
||
* @param [type] $uid 用户ids
|
||
* @return [type] [description]
|
||
*/
|
||
public function insert($id, $uid)
|
||
{
|
||
$result = AuthService::setAuthUser($id, $uid);
|
||
return $this->back($result);
|
||
}
|
||
}
|