调整管理员详情
This commit is contained in:
parent
8976b59d1f
commit
f9355e7df5
@ -22,6 +22,17 @@ class ExceptionHandler extends Handler
|
||||
return \response(self::convertToHtml($exception));
|
||||
} elseif ($exception instanceof ErrorException) {
|
||||
return response($exception->getMessage(), 401);
|
||||
} elseif ($exception instanceof \Exception) {
|
||||
$isDebug = config('app.debug');
|
||||
$error = [
|
||||
'code' => $isDebug ? $exception->getCode() : 500,
|
||||
'msg' => $isDebug ? $exception->getMessage() : '服务器内部错误',
|
||||
];
|
||||
if ($isDebug) {
|
||||
$error['file'] = $exception->getFile();
|
||||
$error['line'] = $exception->getLine();
|
||||
}
|
||||
return response(json_encode($error, JSON_UNESCAPED_UNICODE));
|
||||
}
|
||||
// 非json请求则返回一个页面
|
||||
return new Response(200, [], $exception->getMessage());
|
||||
|
@ -56,6 +56,8 @@ class LoginController extends BaseAdminController
|
||||
ApiDoc\Title('退出登录'),
|
||||
ApiDoc\url('/store/login/logout'),
|
||||
ApiDoc\Method('POST'),
|
||||
ApiDoc\NotHeaders(),
|
||||
ApiDoc\Header(name: "token", type: "string", require: true, desc: "token"),
|
||||
ApiDoc\ResponseSuccess("data", type: "array"),
|
||||
]
|
||||
public function logout()
|
||||
|
@ -26,26 +26,31 @@ use hg\apidoc\annotation as ApiDoc;
|
||||
* Class AdminController
|
||||
* @package app\store\controller\auth
|
||||
*/
|
||||
#[ApiDoc\NotParse()]
|
||||
#[ApiDoc\title('管理员信息')]
|
||||
class AdminController extends BaseAdminController
|
||||
{
|
||||
|
||||
/**
|
||||
* @notes 查看管理员列表
|
||||
* @author 乔峰
|
||||
* @date 2021/12/29 9:55
|
||||
*/
|
||||
#[
|
||||
ApiDoc\Title("查看管理员列表"),
|
||||
ApiDoc\url('/store/auth/admin/lists'),
|
||||
ApiDoc\Method('GET'),
|
||||
ApiDoc\NotHeaders(),
|
||||
ApiDoc\Header(name: "token", type: "string", require: true, desc: "token"),
|
||||
ApiDoc\ResponseSuccess("data", type: "array"),
|
||||
]
|
||||
public function lists()
|
||||
{
|
||||
return $this->dataLists(new AdminLists());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 添加管理员
|
||||
* @author 乔峰
|
||||
* @date 2021/12/29 10:21
|
||||
*/
|
||||
#[
|
||||
ApiDoc\Title("添加管理员"),
|
||||
ApiDoc\url('/store/auth/admin/add'),
|
||||
ApiDoc\Method('GET'),
|
||||
ApiDoc\NotHeaders(),
|
||||
ApiDoc\Header(name: "token", type: "string", require: true, desc: "token"),
|
||||
ApiDoc\ResponseSuccess("data", type: "array"),
|
||||
]
|
||||
public function add()
|
||||
{
|
||||
$params = (new AdminValidate())->post()->goCheck('add');
|
||||
@ -56,12 +61,14 @@ class AdminController extends BaseAdminController
|
||||
return $this->fail(AdminLogic::getError());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 编辑管理员
|
||||
* @author 乔峰
|
||||
* @date 2021/12/29 11:03
|
||||
*/
|
||||
#[
|
||||
ApiDoc\Title("编辑管理员"),
|
||||
ApiDoc\url('/store/auth/admin/edit'),
|
||||
ApiDoc\Method('GET'),
|
||||
ApiDoc\NotHeaders(),
|
||||
ApiDoc\Header(name: "token", type: "string", require: true, desc: "token"),
|
||||
ApiDoc\ResponseSuccess("data", type: "array"),
|
||||
]
|
||||
public function edit()
|
||||
{
|
||||
$params = (new AdminValidate())->post()->goCheck('edit');
|
||||
@ -72,12 +79,14 @@ class AdminController extends BaseAdminController
|
||||
return $this->fail(AdminLogic::getError());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 删除管理员
|
||||
* @author 乔峰
|
||||
* @date 2021/12/29 11:03
|
||||
*/
|
||||
#[
|
||||
ApiDoc\Title("删除管理员"),
|
||||
ApiDoc\url('/store/auth/admin/delete'),
|
||||
ApiDoc\Method('GET'),
|
||||
ApiDoc\NotHeaders(),
|
||||
ApiDoc\Header(name: "token", type: "string", require: true, desc: "token"),
|
||||
ApiDoc\ResponseSuccess("data", type: "array"),
|
||||
]
|
||||
public function delete()
|
||||
{
|
||||
$params = (new AdminValidate())->post()->goCheck('delete');
|
||||
@ -88,12 +97,14 @@ class AdminController extends BaseAdminController
|
||||
return $this->fail(AdminLogic::getError());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 查看管理员详情
|
||||
* @author 乔峰
|
||||
* @date 2021/12/29 11:07
|
||||
*/
|
||||
#[
|
||||
ApiDoc\Title("查看管理员详情"),
|
||||
ApiDoc\url('/store/auth/admin/detail'),
|
||||
ApiDoc\Method('GET'),
|
||||
ApiDoc\NotHeaders(),
|
||||
ApiDoc\Header(name: "token", type: "string", require: true, desc: "token"),
|
||||
ApiDoc\ResponseSuccess("data", type: "array"),
|
||||
]
|
||||
public function detail()
|
||||
{
|
||||
$params = (new AdminValidate())->goCheck('detail');
|
||||
@ -101,24 +112,28 @@ class AdminController extends BaseAdminController
|
||||
return $this->data($result);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 获取当前管理员信息
|
||||
* @author 乔峰
|
||||
* @date 2021/12/31 10:53
|
||||
*/
|
||||
#[
|
||||
ApiDoc\Title("获取当前管理员信息"),
|
||||
ApiDoc\url('/store/auth/admin/mySelf'),
|
||||
ApiDoc\Method('GET'),
|
||||
ApiDoc\NotHeaders(),
|
||||
ApiDoc\Header(name: "token", type: "string", require: true, desc: "token"),
|
||||
ApiDoc\ResponseSuccess("data", type: "array"),
|
||||
]
|
||||
public function mySelf()
|
||||
{
|
||||
$result = AdminLogic::detail(['id' => $this->adminId], 'auth');
|
||||
return $this->data($result);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 编辑超级管理员信息
|
||||
* @author 乔峰
|
||||
* @date 2022/4/8 17:54
|
||||
*/
|
||||
#[
|
||||
ApiDoc\Title("编辑超级管理员信息"),
|
||||
ApiDoc\url('/store/auth/admin/editSelf'),
|
||||
ApiDoc\Method('GET'),
|
||||
ApiDoc\NotHeaders(),
|
||||
ApiDoc\Header(name: "token", type: "string", require: true, desc: "token"),
|
||||
ApiDoc\ResponseSuccess("data", type: "array"),
|
||||
]
|
||||
public function editSelf()
|
||||
{
|
||||
$params = (new editSelfValidate())->post()->goCheck('', ['admin_id' => $this->adminId]);
|
||||
|
@ -23,6 +23,7 @@ use app\common\model\auth\AdminJobs;
|
||||
use app\common\model\auth\AdminRole;
|
||||
use app\common\model\auth\AdminSession;
|
||||
use app\common\cache\AdminTokenCache;
|
||||
use app\common\model\system_store\SystemStoreStaff;
|
||||
use app\common\service\FileService;
|
||||
use Webman\Config;
|
||||
use think\facade\Db;
|
||||
@ -223,9 +224,8 @@ class AdminLogic extends BaseLogic
|
||||
*/
|
||||
public static function detail($params, $action = 'detail'): array
|
||||
{
|
||||
$admin = Admin::field([
|
||||
'id', 'account', 'name', 'disable', 'root',
|
||||
'multipoint_login', 'avatar',
|
||||
$admin = SystemStoreStaff::field([
|
||||
'id', 'account', 'staff_name', 'avatar', 'is_admin', 'is_manager'
|
||||
])->findOrEmpty($params['id'])->toArray();
|
||||
|
||||
if ($action == 'detail') {
|
||||
|
@ -54,7 +54,7 @@ class AuthLogic
|
||||
*/
|
||||
public static function getBtnAuthByRoleId($admin)
|
||||
{
|
||||
if ($admin['root']) {
|
||||
if ($admin['is_admin'] || $admin['is_manager']) {
|
||||
return ['*'];
|
||||
}
|
||||
|
||||
|
@ -20,6 +20,7 @@ use app\common\logic\BaseLogic;
|
||||
use app\common\model\auth\Admin;
|
||||
use app\common\model\auth\SystemMenu;
|
||||
use app\common\model\auth\SystemRoleMenu;
|
||||
use app\common\model\system_store\SystemStoreStaff;
|
||||
|
||||
|
||||
/**
|
||||
@ -43,13 +44,13 @@ class MenuLogic extends BaseLogic
|
||||
*/
|
||||
public static function getMenuByAdminId($adminId)
|
||||
{
|
||||
$admin = Admin::findOrEmpty($adminId);
|
||||
$admin = SystemStoreStaff::findOrEmpty($adminId);
|
||||
|
||||
$where = [];
|
||||
$where[] = ['type', 'in', ['M', 'C']];
|
||||
$where[] = ['is_disable', '=', 0];
|
||||
|
||||
if ($admin['root'] != 1) {
|
||||
if ($admin['is_admin'] != 1 || $admin['is_manager'] != 1) {
|
||||
$roleMenu = SystemRoleMenu::whereIn('role_id', $admin['role_id'])->column('menu_id');
|
||||
$where[] = ['id', 'in', $roleMenu];
|
||||
}
|
||||
|
@ -4,6 +4,7 @@
|
||||
namespace app\store\middleware;
|
||||
|
||||
|
||||
use app\common\cache\StaffTokenCache;
|
||||
use app\store\service\AdminTokenService;
|
||||
use app\common\cache\AdminTokenCache;
|
||||
use app\common\service\JsonService;
|
||||
@ -35,7 +36,7 @@ class LoginMiddleware implements MiddlewareInterface
|
||||
return JsonService::fail('请求参数缺token', [], 0, 0);
|
||||
}
|
||||
|
||||
$adminInfo = (new AdminTokenCache())->getAdminInfo($token);
|
||||
$adminInfo = (new StaffTokenCache())->getAdminInfo($token);
|
||||
if (empty($adminInfo) && !$isNotNeedLogin) {
|
||||
//token过期无效并且该地址需要登录才能访问
|
||||
return JsonService::fail('登录超时,请重新登录', [], -1);
|
||||
@ -58,7 +59,6 @@ class LoginMiddleware implements MiddlewareInterface
|
||||
//给request赋值,用于控制器
|
||||
$request->adminInfo = $adminInfo;
|
||||
$request->adminId = $adminInfo['admin_id'] ?? 0;
|
||||
$request->supplierId = $adminInfo['supplier_id'] ?? 0;
|
||||
|
||||
return $handler($request);
|
||||
}
|
||||
|
@ -4,9 +4,7 @@
|
||||
namespace app\store\service;
|
||||
|
||||
|
||||
use app\common\cache\AdminTokenCache;
|
||||
use app\common\cache\StaffTokenCache;
|
||||
use app\common\model\auth\AdminSession;
|
||||
use app\common\model\system_store\SystemStoreStaffSession;
|
||||
use Webman\Config;
|
||||
|
||||
@ -32,13 +30,13 @@ class AdminTokenService
|
||||
//获取token延长过期的时间
|
||||
$expireTime = $time + Config::get('project.admin_token.expire_duration');
|
||||
|
||||
$adminTokenCache = new StaffTokenCache();
|
||||
$staffTokenCache = new StaffTokenCache();
|
||||
|
||||
//token处理
|
||||
if ($adminSession) {
|
||||
if ($adminSession->expire_time < $time || $multipointLogin === 0) {
|
||||
//清空缓存
|
||||
$adminTokenCache->deleteAdminInfo($adminSession->token);
|
||||
$staffTokenCache->deleteAdminInfo($adminSession->token);
|
||||
//如果token过期或账号设置不支持多处登录,更新token
|
||||
$adminSession->token = create_token($adminId);
|
||||
}
|
||||
@ -56,7 +54,7 @@ class AdminTokenService
|
||||
]);
|
||||
}
|
||||
|
||||
return $adminTokenCache->setAdminInfo($adminSession->token);
|
||||
return $staffTokenCache->setAdminInfo($adminSession->token);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -72,7 +70,7 @@ class AdminTokenService
|
||||
public static function overtimeToken($token)
|
||||
{
|
||||
$time = time();
|
||||
$adminSession = AdminSession::where('token', '=', $token)->findOrEmpty();
|
||||
$adminSession = SystemStoreStaffSession::where('token', '=', $token)->findOrEmpty();
|
||||
if ($adminSession->isEmpty()) {
|
||||
return false;
|
||||
}
|
||||
@ -80,7 +78,7 @@ class AdminTokenService
|
||||
$adminSession->expire_time = $time + Config::get('project.admin_token.expire_duration');
|
||||
$adminSession->update_time = $time;
|
||||
$adminSession->save();
|
||||
return (new AdminTokenCache())->setAdminInfo($adminSession->token);
|
||||
return (new StaffTokenCache())->setAdminInfo($adminSession->token);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -37,6 +37,6 @@ return [
|
||||
app\common\http\middleware\AdminAllowMiddleware::class,
|
||||
app\store\middleware\InitMiddleware::class,
|
||||
app\store\middleware\LoginMiddleware::class,
|
||||
app\store\middleware\AuthMiddleware::class,
|
||||
// app\store\middleware\AuthMiddleware::class,
|
||||
]
|
||||
];
|
||||
|
Loading…
x
Reference in New Issue
Block a user