mirror of
https://gitee.com/apiadmin/ApiAdmin.git
synced 2025-04-06 03:58:00 +08:00
modified 新增组获取
This commit is contained in:
parent
12f5139a09
commit
b34d8e6723
112
application/admin/controller/Auth.php
Normal file
112
application/admin/controller/Auth.php
Normal file
@ -0,0 +1,112 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @since 2018-02-06
|
||||||
|
* @author zhaoxiang <zhaoxiang051405@gmail.com>
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace app\admin\controller;
|
||||||
|
|
||||||
|
|
||||||
|
use app\model\ApiAuthGroup;
|
||||||
|
use app\model\ApiUser;
|
||||||
|
use app\util\ReturnCode;
|
||||||
|
|
||||||
|
class Auth extends Base {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取权限组列表
|
||||||
|
* @return array
|
||||||
|
* @throws \think\db\exception\DataNotFoundException
|
||||||
|
* @throws \think\db\exception\ModelNotFoundException
|
||||||
|
* @throws \think\exception\DbException
|
||||||
|
* @author zhaoxiang <zhaoxiang051405@gmail.com>
|
||||||
|
*/
|
||||||
|
public function index() {
|
||||||
|
|
||||||
|
$limit = $this->request->get('size', config('apiAdmin.ADMIN_LIST_DEFAULT'));
|
||||||
|
$start = $limit * ($this->request->get('page', 1) - 1);
|
||||||
|
|
||||||
|
$where = [];
|
||||||
|
|
||||||
|
$listModel = (new ApiAuthGroup())->where($where);
|
||||||
|
$listInfo = $listModel->limit($start, $limit)->select();
|
||||||
|
$count = $listModel->count();
|
||||||
|
$listInfo = $this->buildArrFromObj($listInfo);
|
||||||
|
|
||||||
|
return $this->buildSuccess([
|
||||||
|
'list' => $listInfo,
|
||||||
|
'count' => $count
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 新增用户 等待组权限
|
||||||
|
* @return array
|
||||||
|
* @author zhaoxiang <zhaoxiang051405@gmail.com>
|
||||||
|
*/
|
||||||
|
public function add() {
|
||||||
|
$postData = $this->request->post();
|
||||||
|
$res = ApiMenu::create($postData);
|
||||||
|
if ($res === false) {
|
||||||
|
return $this->buildFailed(ReturnCode::DB_SAVE_ERROR, '操作失败');
|
||||||
|
} else {
|
||||||
|
return $this->buildSuccess([]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 用户状态编辑
|
||||||
|
* @return array
|
||||||
|
* @author zhaoxiang <zhaoxiang051405@gmail.com>
|
||||||
|
*/
|
||||||
|
public function changeStatus() {
|
||||||
|
$id = $this->request->get('id');
|
||||||
|
$status = $this->request->get('status');
|
||||||
|
$res = ApiUser::update([
|
||||||
|
'id' => $id,
|
||||||
|
'status' => $status
|
||||||
|
]);
|
||||||
|
if ($res === false) {
|
||||||
|
return $this->buildFailed(ReturnCode::DB_SAVE_ERROR, '操作失败');
|
||||||
|
} else {
|
||||||
|
return $this->buildSuccess([]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 编辑用户
|
||||||
|
* @return array
|
||||||
|
* @author zhaoxiang <zhaoxiang051405@gmail.com>
|
||||||
|
*/
|
||||||
|
public function edit() {
|
||||||
|
$postData = $this->request->post();
|
||||||
|
$res = ApiMenu::update($postData);
|
||||||
|
if ($res === false) {
|
||||||
|
return $this->buildFailed(ReturnCode::DB_SAVE_ERROR, '操作失败');
|
||||||
|
} else {
|
||||||
|
return $this->buildSuccess([]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 删除用户
|
||||||
|
* @return array
|
||||||
|
* @author zhaoxiang <zhaoxiang051405@gmail.com>
|
||||||
|
*/
|
||||||
|
public function del() {
|
||||||
|
$id = $this->request->get('id');
|
||||||
|
if (!$id) {
|
||||||
|
return $this->buildFailed(ReturnCode::EMPTY_PARAMS, '缺少必要参数');
|
||||||
|
}
|
||||||
|
$childNum = ApiMenu::where(['fid' => $id])->count();
|
||||||
|
if ($childNum) {
|
||||||
|
return $this->buildFailed(ReturnCode::INVALID, '当前菜单存在子菜单,不可以被删除!');
|
||||||
|
} else {
|
||||||
|
ApiMenu::destroy($id);
|
||||||
|
|
||||||
|
return $this->buildSuccess([]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -52,7 +52,7 @@ class User extends Base {
|
|||||||
$listInfo = $this->buildArrFromObj($listInfo);
|
$listInfo = $this->buildArrFromObj($listInfo);
|
||||||
$idArr = array_column($listInfo, 'id');
|
$idArr = array_column($listInfo, 'id');
|
||||||
|
|
||||||
$userData = ApiUserData::all(function($query) use($idArr) {
|
$userData = ApiUserData::all(function($query) use ($idArr) {
|
||||||
$query->whereIn('uid', $idArr);
|
$query->whereIn('uid', $idArr);
|
||||||
});
|
});
|
||||||
$userData = $this->buildArrFromObj($userData);
|
$userData = $this->buildArrFromObj($userData);
|
||||||
|
@ -51,6 +51,26 @@ return [
|
|||||||
'admin/User/del',
|
'admin/User/del',
|
||||||
['method' => 'get', 'after_behavior' => $afterBehavior]
|
['method' => 'get', 'after_behavior' => $afterBehavior]
|
||||||
],
|
],
|
||||||
|
'Auth/index' => [
|
||||||
|
'admin/Auth/index',
|
||||||
|
['method' => 'get', 'after_behavior' => $afterBehavior]
|
||||||
|
],
|
||||||
|
'Auth/changeStatus' => [
|
||||||
|
'admin/Auth/changeStatus',
|
||||||
|
['method' => 'get', 'after_behavior' => $afterBehavior]
|
||||||
|
],
|
||||||
|
'Auth/add' => [
|
||||||
|
'admin/Auth/add',
|
||||||
|
['method' => 'post', 'after_behavior' => $afterBehavior]
|
||||||
|
],
|
||||||
|
'Auth/edit' => [
|
||||||
|
'admin/Auth/edit',
|
||||||
|
['method' => 'post', 'after_behavior' => $afterBehavior]
|
||||||
|
],
|
||||||
|
'Auth/del' => [
|
||||||
|
'admin/Auth/del',
|
||||||
|
['method' => 'get', 'after_behavior' => $afterBehavior]
|
||||||
|
],
|
||||||
'__miss__' => ['admin/Miss/index'],
|
'__miss__' => ['admin/Miss/index'],
|
||||||
],
|
],
|
||||||
];
|
];
|
||||||
|
17
application/model/ApiAuthGroup.php
Normal file
17
application/model/ApiAuthGroup.php
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @since 2018-02-08
|
||||||
|
* @author zhaoxiang <zhaoxiang051405@gmail.com>
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace app\model;
|
||||||
|
|
||||||
|
|
||||||
|
class ApiAuthGroup extends Base {
|
||||||
|
|
||||||
|
public function rules() {
|
||||||
|
return $this->hasMany('ApiAuthRule', 'groupId', 'id');
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
13
application/model/ApiAuthGroupAccess.php
Normal file
13
application/model/ApiAuthGroupAccess.php
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @since 2018-02-08
|
||||||
|
* @author zhaoxiang <zhaoxiang051405@gmail.com>
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace app\model;
|
||||||
|
|
||||||
|
|
||||||
|
class ApiAuthGroupAccess extends Base {
|
||||||
|
|
||||||
|
}
|
13
application/model/ApiAuthRule.php
Normal file
13
application/model/ApiAuthRule.php
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @since 2018-02-08
|
||||||
|
* @author zhaoxiang <zhaoxiang051405@gmail.com>
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace app\model;
|
||||||
|
|
||||||
|
|
||||||
|
class ApiAuthRule extends Base {
|
||||||
|
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user