mirror of
https://gitee.com/technical-laohu/mpay_v2_webman.git
synced 2026-04-22 10:04:27 +08:00
重构初始化
This commit is contained in:
61
app/http/mer/controller/system/AuthController.php
Normal file
61
app/http/mer/controller/system/AuthController.php
Normal file
@@ -0,0 +1,61 @@
|
||||
<?php
|
||||
|
||||
namespace app\http\mer\controller\system;
|
||||
|
||||
use app\common\base\BaseController;
|
||||
use app\http\mer\validation\AuthValidator;
|
||||
use app\service\merchant\auth\MerchantAuthService;
|
||||
use support\Request;
|
||||
use support\Response;
|
||||
|
||||
/**
|
||||
* 商户认证控制器。
|
||||
*/
|
||||
class AuthController extends BaseController
|
||||
{
|
||||
public function __construct(
|
||||
protected MerchantAuthService $merchantAuthService
|
||||
) {
|
||||
}
|
||||
|
||||
public function login(Request $request): Response
|
||||
{
|
||||
$data = $this->validated($request->all(), AuthValidator::class, 'login');
|
||||
|
||||
return $this->success($this->merchantAuthService->authenticateCredentials(
|
||||
(string) $data['merchant_no'],
|
||||
(string) $data['password'],
|
||||
$request->getRealIp(),
|
||||
$request->header('user-agent', '')
|
||||
));
|
||||
}
|
||||
|
||||
public function logout(Request $request): Response
|
||||
{
|
||||
$token = trim((string) ($request->header('authorization', '') ?: $request->header('x-merchant-token', '')));
|
||||
$token = preg_replace('/^Bearer\s+/i', '', $token) ?: $token;
|
||||
|
||||
if ($token === '') {
|
||||
return $this->fail('未获取到登录令牌', 401);
|
||||
}
|
||||
|
||||
$this->merchantAuthService->revokeToken($token);
|
||||
|
||||
return $this->success(true);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取当前登录商户的信息
|
||||
*/
|
||||
public function profile(Request $request): Response
|
||||
{
|
||||
$merchantId = $this->currentMerchantId($request);
|
||||
if ($merchantId <= 0) {
|
||||
return $this->fail('未获取到当前商户信息', 401);
|
||||
}
|
||||
|
||||
$merchantNo = $this->currentMerchantNo($request);
|
||||
return $this->success($this->merchantAuthService->profile($merchantId, $merchantNo));
|
||||
}
|
||||
}
|
||||
|
||||
30
app/http/mer/controller/system/SystemController.php
Normal file
30
app/http/mer/controller/system/SystemController.php
Normal file
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
namespace app\http\mer\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('merchant'));
|
||||
}
|
||||
|
||||
public function dictItems(Request $request): Response
|
||||
{
|
||||
return $this->success($this->systemBootstrapService->getDictItems((string) $request->get('code', '')));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user