mirror of
https://gitee.com/technical-laohu/mpay_v2_webman.git
synced 2026-04-21 17:44:27 +08:00
重构初始化
This commit is contained in:
122
app/http/admin/controller/system/AdminUserController.php
Normal file
122
app/http/admin/controller/system/AdminUserController.php
Normal file
@@ -0,0 +1,122 @@
|
||||
<?php
|
||||
|
||||
namespace app\http\admin\controller\system;
|
||||
|
||||
use app\common\base\BaseController;
|
||||
use app\http\admin\validation\AdminUserValidator;
|
||||
use app\service\system\user\AdminUserService;
|
||||
use support\Request;
|
||||
use support\Response;
|
||||
|
||||
/**
|
||||
* 管理员用户管理控制器。
|
||||
*
|
||||
* 负责管理员账号的列表、详情、新增、修改和删除。
|
||||
*/
|
||||
class AdminUserController extends BaseController
|
||||
{
|
||||
/**
|
||||
* 构造函数,注入管理员用户服务。
|
||||
*/
|
||||
public function __construct(
|
||||
protected AdminUserService $adminUserService
|
||||
) {
|
||||
}
|
||||
|
||||
/**
|
||||
* GET /adminapi/admin-users
|
||||
*
|
||||
* 查询管理员用户列表。
|
||||
*/
|
||||
public function index(Request $request): Response
|
||||
{
|
||||
$data = $this->validated($request->all(), AdminUserValidator::class, 'index');
|
||||
|
||||
return $this->page(
|
||||
$this->adminUserService->paginate(
|
||||
$data,
|
||||
(int) ($data['page'] ?? 1),
|
||||
(int) ($data['page_size'] ?? 10)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* GET /adminapi/admin-users/{id}
|
||||
*
|
||||
* 查询管理员用户详情。
|
||||
*/
|
||||
public function show(Request $request, string $id): Response
|
||||
{
|
||||
$data = $this->validated(['id' => (int) $id], AdminUserValidator::class, 'show');
|
||||
$adminUser = $this->adminUserService->findById((int) $data['id']);
|
||||
|
||||
if (!$adminUser) {
|
||||
return $this->fail('管理员用户不存在', 404);
|
||||
}
|
||||
|
||||
return $this->success($adminUser);
|
||||
}
|
||||
|
||||
/**
|
||||
* POST /adminapi/admin-users
|
||||
*
|
||||
* 新增管理员用户。
|
||||
*/
|
||||
public function store(Request $request): Response
|
||||
{
|
||||
$data = $this->validated($request->all(), AdminUserValidator::class, 'store');
|
||||
|
||||
return $this->success($this->adminUserService->create($data));
|
||||
}
|
||||
|
||||
/**
|
||||
* PUT /adminapi/admin-users/{id}
|
||||
*
|
||||
* 修改管理员用户。
|
||||
*/
|
||||
public function update(Request $request, string $id): Response
|
||||
{
|
||||
$data = $this->validated(
|
||||
array_merge($request->all(), ['id' => (int) $id]),
|
||||
AdminUserValidator::class,
|
||||
'update'
|
||||
);
|
||||
|
||||
$adminUser = $this->adminUserService->update((int) $data['id'], $data);
|
||||
if (!$adminUser) {
|
||||
return $this->fail('管理员用户不存在', 404);
|
||||
}
|
||||
|
||||
return $this->success($adminUser);
|
||||
}
|
||||
|
||||
/**
|
||||
* DELETE /adminapi/admin-users/{id}
|
||||
*
|
||||
* 删除管理员用户。
|
||||
*/
|
||||
public function destroy(Request $request, string $id): Response
|
||||
{
|
||||
$data = $this->validated(['id' => (int) $id], AdminUserValidator::class, 'destroy');
|
||||
$adminUser = $this->adminUserService->findById((int) $data['id']);
|
||||
|
||||
if (!$adminUser) {
|
||||
return $this->fail('管理员用户不存在', 404);
|
||||
}
|
||||
|
||||
if ((int) $adminUser->is_super === 1) {
|
||||
return $this->fail('超级管理员不允许删除');
|
||||
}
|
||||
|
||||
if ((int) $data['id'] === $this->currentAdminId($request)) {
|
||||
return $this->fail('不允许删除当前登录用户');
|
||||
}
|
||||
|
||||
if (!$this->adminUserService->delete((int) $data['id'])) {
|
||||
return $this->fail('管理员用户删除失败');
|
||||
}
|
||||
|
||||
return $this->success(true);
|
||||
}
|
||||
}
|
||||
65
app/http/admin/controller/system/AuthController.php
Normal file
65
app/http/admin/controller/system/AuthController.php
Normal file
@@ -0,0 +1,65 @@
|
||||
<?php
|
||||
|
||||
namespace app\http\admin\controller\system;
|
||||
|
||||
use app\common\base\BaseController;
|
||||
use app\http\admin\validation\AuthValidator;
|
||||
use app\service\system\access\AdminAuthService;
|
||||
use app\service\system\user\AdminUserService;
|
||||
use support\Request;
|
||||
use support\Response;
|
||||
|
||||
/**
|
||||
* 管理员认证控制器。
|
||||
*/
|
||||
class AuthController extends BaseController
|
||||
{
|
||||
public function __construct(
|
||||
protected AdminAuthService $adminAuthService,
|
||||
protected AdminUserService $adminUserService
|
||||
) {
|
||||
}
|
||||
|
||||
public function login(Request $request): Response
|
||||
{
|
||||
$data = $this->validated($request->all(), AuthValidator::class, 'login');
|
||||
|
||||
return $this->success($this->adminAuthService->authenticateCredentials(
|
||||
(string) $data['username'],
|
||||
(string) $data['password'],
|
||||
$request->getRealIp(),
|
||||
$request->header('user-agent', '')
|
||||
));
|
||||
}
|
||||
|
||||
public function logout(Request $request): Response
|
||||
{
|
||||
$token = trim((string) ($request->header('authorization', '') ?: $request->header('x-admin-token', '')));
|
||||
$token = preg_replace('/^Bearer\s+/i', '', $token) ?: $token;
|
||||
|
||||
if ($token === '') {
|
||||
return $this->fail('未获取到登录令牌', 401);
|
||||
}
|
||||
|
||||
$this->adminAuthService->revokeToken($token);
|
||||
|
||||
return $this->success(true);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取当前登录管理员的信息
|
||||
*/
|
||||
public function profile(Request $request): Response
|
||||
{
|
||||
$adminId = $this->currentAdminId($request);
|
||||
if ($adminId <= 0) {
|
||||
return $this->fail('未获取到当前管理员信息', 401);
|
||||
}
|
||||
|
||||
return $this->success($this->adminUserService->profile(
|
||||
$adminId,
|
||||
(string) $this->requestAttribute($request, 'auth.admin_username', '')
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,42 @@
|
||||
<?php
|
||||
|
||||
namespace app\http\admin\controller\system;
|
||||
|
||||
use app\common\base\BaseController;
|
||||
use app\http\admin\validation\SystemConfigPageValidator;
|
||||
use app\service\system\config\SystemConfigPageService;
|
||||
use support\Request;
|
||||
use support\Response;
|
||||
|
||||
class SystemConfigPageController extends BaseController
|
||||
{
|
||||
public function __construct(
|
||||
protected SystemConfigPageService $systemConfigPageService
|
||||
) {
|
||||
}
|
||||
|
||||
public function index(Request $request): Response
|
||||
{
|
||||
return $this->success($this->systemConfigPageService->tabs());
|
||||
}
|
||||
|
||||
public function show(Request $request, string $groupCode): Response
|
||||
{
|
||||
$data = $this->validated(['group_code' => $groupCode], SystemConfigPageValidator::class, 'show');
|
||||
|
||||
return $this->success($this->systemConfigPageService->detail((string) $data['group_code']));
|
||||
}
|
||||
|
||||
public function store(Request $request, string $groupCode): Response
|
||||
{
|
||||
$data = $this->validated(
|
||||
array_merge($this->payload($request), ['group_code' => $groupCode]),
|
||||
SystemConfigPageValidator::class,
|
||||
'store'
|
||||
);
|
||||
|
||||
return $this->success(
|
||||
$this->systemConfigPageService->save((string) $data['group_code'], (array) ($data['values'] ?? []))
|
||||
);
|
||||
}
|
||||
}
|
||||
30
app/http/admin/controller/system/SystemController.php
Normal file
30
app/http/admin/controller/system/SystemController.php
Normal file
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
namespace app\http\admin\controller\system;
|
||||
|
||||
use app\common\base\BaseController;
|
||||
use app\service\bootstrap\SystemBootstrapService;
|
||||
use support\Request;
|
||||
use support\Response;
|
||||
|
||||
/**
|
||||
* 管理后台系统数据控制器。
|
||||
*/
|
||||
class SystemController extends BaseController
|
||||
{
|
||||
public function __construct(
|
||||
protected SystemBootstrapService $systemBootstrapService
|
||||
) {
|
||||
}
|
||||
|
||||
public function menuTree(Request $request): Response
|
||||
{
|
||||
return $this->success($this->systemBootstrapService->getMenuTree('admin'));
|
||||
}
|
||||
|
||||
public function dictItems(Request $request): Response
|
||||
{
|
||||
return $this->success($this->systemBootstrapService->getDictItems((string) $request->get('code', '')));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user