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