mirror of
https://gitee.com/apiadmin/ApiAdmin.git
synced 2025-04-06 03:58:00 +08:00
modified 代码备份
This commit is contained in:
parent
2f07c37e21
commit
62e16b52dc
@ -8,6 +8,8 @@
|
|||||||
namespace app\admin\behavior;
|
namespace app\admin\behavior;
|
||||||
|
|
||||||
|
|
||||||
|
use think\Request;
|
||||||
|
|
||||||
class ApiPermission {
|
class ApiPermission {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -17,7 +19,9 @@ class ApiPermission {
|
|||||||
* @throws \think\exception\DbException
|
* @throws \think\exception\DbException
|
||||||
*/
|
*/
|
||||||
public function run() {
|
public function run() {
|
||||||
|
$request = Request::instance();
|
||||||
|
$route = $request->routeInfo();
|
||||||
|
$route = $route['route'];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -43,6 +43,21 @@ class Base extends Controller {
|
|||||||
return $return;
|
return $return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 将二维数组变成指定key
|
||||||
|
* @param $array
|
||||||
|
* @param $keyName
|
||||||
|
* @author zhaoxiang <zhaoxiang051405@gmail.com>
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
protected function buildArrByNewKey($array, $keyName = 'id') {
|
||||||
|
$list = array();
|
||||||
|
foreach ($array as $item) {
|
||||||
|
$list[$item[$keyName]] = $item;
|
||||||
|
}
|
||||||
|
return $list;
|
||||||
|
}
|
||||||
|
|
||||||
protected function debug($data) {
|
protected function debug($data) {
|
||||||
if ($data) {
|
if ($data) {
|
||||||
$this->debug[] = $data;
|
$this->debug[] = $data;
|
||||||
|
@ -15,6 +15,8 @@ class Menu extends Base {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取菜单列表
|
* 获取菜单列表
|
||||||
|
* @return array
|
||||||
|
* @throws \think\exception\DbException
|
||||||
* @author zhaoxiang <zhaoxiang051405@gmail.com>
|
* @author zhaoxiang <zhaoxiang051405@gmail.com>
|
||||||
*/
|
*/
|
||||||
public function index() {
|
public function index() {
|
||||||
@ -29,6 +31,7 @@ class Menu extends Base {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 新增菜单
|
* 新增菜单
|
||||||
|
* @return array
|
||||||
* @author zhaoxiang <zhaoxiang051405@gmail.com>
|
* @author zhaoxiang <zhaoxiang051405@gmail.com>
|
||||||
*/
|
*/
|
||||||
public function add() {
|
public function add() {
|
||||||
@ -43,6 +46,7 @@ class Menu extends Base {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 菜单状态编辑
|
* 菜单状态编辑
|
||||||
|
* @return array
|
||||||
* @author zhaoxiang <zhaoxiang051405@gmail.com>
|
* @author zhaoxiang <zhaoxiang051405@gmail.com>
|
||||||
*/
|
*/
|
||||||
public function changeStatus() {
|
public function changeStatus() {
|
||||||
@ -61,6 +65,7 @@ class Menu extends Base {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 编辑菜单
|
* 编辑菜单
|
||||||
|
* @return array
|
||||||
* @author zhaoxiang <zhaoxiang051405@gmail.com>
|
* @author zhaoxiang <zhaoxiang051405@gmail.com>
|
||||||
*/
|
*/
|
||||||
public function edit() {
|
public function edit() {
|
||||||
@ -73,6 +78,11 @@ class Menu extends Base {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 删除菜单
|
||||||
|
* @return array
|
||||||
|
* @author zhaoxiang <zhaoxiang051405@gmail.com>
|
||||||
|
*/
|
||||||
public function del() {
|
public function del() {
|
||||||
$id = $this->request->get('id');
|
$id = $this->request->get('id');
|
||||||
if (!$id) {
|
if (!$id) {
|
||||||
|
109
application/admin/controller/User.php
Normal file
109
application/admin/controller/User.php
Normal file
@ -0,0 +1,109 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @since 2018-02-06
|
||||||
|
* @author zhaoxiang <zhaoxiang051405@gmail.com>
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace app\admin\controller;
|
||||||
|
|
||||||
|
|
||||||
|
use app\model\ApiUser;
|
||||||
|
use app\model\ApiUserData;
|
||||||
|
|
||||||
|
class User extends Base {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取用户列表
|
||||||
|
* @return array
|
||||||
|
* @author zhaoxiang <zhaoxiang051405@gmail.com>
|
||||||
|
*/
|
||||||
|
public function index() {
|
||||||
|
$listInfo = ApiUser::all();
|
||||||
|
$userData = ApiUserData::all();
|
||||||
|
$userData = $this->buildArrByNewKey($userData, 'uid');
|
||||||
|
|
||||||
|
foreach ($listInfo as $key => $value) {
|
||||||
|
if ($userData) {
|
||||||
|
$listInfo[$key]['lastLoginIp'] = long2ip($userData[$value['id']]['lastLoginIp']);
|
||||||
|
$listInfo[$key]['loginTimes'] = $userData[$value['id']]['loginTimes'];
|
||||||
|
$listInfo[$key]['lastLoginTime'] = date('Y-m-d H:i:s', $userData[$value['id']]['lastLoginTime']);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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 = ApiMenu::update([
|
||||||
|
'id' => $id,
|
||||||
|
'hide' => $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([]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -31,6 +31,26 @@ return [
|
|||||||
'admin/Menu/del',
|
'admin/Menu/del',
|
||||||
['method' => 'get', 'after_behavior' => $afterBehavior]
|
['method' => 'get', 'after_behavior' => $afterBehavior]
|
||||||
],
|
],
|
||||||
|
'User/index' => [
|
||||||
|
'admin/User/index',
|
||||||
|
['method' => 'get', 'after_behavior' => $afterBehavior]
|
||||||
|
],
|
||||||
|
'User/changeStatus' => [
|
||||||
|
'admin/User/changeStatus',
|
||||||
|
['method' => 'get', 'after_behavior' => $afterBehavior]
|
||||||
|
],
|
||||||
|
'User/add' => [
|
||||||
|
'admin/User/add',
|
||||||
|
['method' => 'post', 'after_behavior' => $afterBehavior]
|
||||||
|
],
|
||||||
|
'User/edit' => [
|
||||||
|
'admin/User/edit',
|
||||||
|
['method' => 'post', 'after_behavior' => $afterBehavior]
|
||||||
|
],
|
||||||
|
'User/del' => [
|
||||||
|
'admin/User/del',
|
||||||
|
['method' => 'get', 'after_behavior' => $afterBehavior]
|
||||||
|
],
|
||||||
'__miss__' => ['admin/Miss/index'],
|
'__miss__' => ['admin/Miss/index'],
|
||||||
],
|
],
|
||||||
];
|
];
|
||||||
|
Loading…
x
Reference in New Issue
Block a user