mirror of
https://gitee.com/technical-laohu/mpay_v2_webman.git
synced 2026-04-23 02:24:27 +08:00
重构初始化
This commit is contained in:
47
app/http/mer/controller/account/AccountController.php
Normal file
47
app/http/mer/controller/account/AccountController.php
Normal file
@@ -0,0 +1,47 @@
|
||||
<?php
|
||||
|
||||
namespace app\http\mer\controller\account;
|
||||
|
||||
use app\common\base\BaseController;
|
||||
use app\http\mer\validation\BalanceValidator;
|
||||
use app\service\account\funds\MerchantAccountService;
|
||||
use app\service\merchant\MerchantService;
|
||||
use support\Request;
|
||||
use support\Response;
|
||||
|
||||
/**
|
||||
* 商户账户控制器。
|
||||
*
|
||||
* 负责商户余额查询等账户类接口。
|
||||
*/
|
||||
class AccountController extends BaseController
|
||||
{
|
||||
/**
|
||||
* 构造函数,注入商户与账户服务。
|
||||
*/
|
||||
public function __construct(
|
||||
protected MerchantService $merchantService,
|
||||
protected MerchantAccountService $merchantAccountService
|
||||
) {
|
||||
}
|
||||
|
||||
/**
|
||||
* GET /mer/merchant/{merchantNo}/balance
|
||||
*
|
||||
* 查询商户余额。
|
||||
*/
|
||||
public function balance(Request $request, string $merchantNo): Response
|
||||
{
|
||||
$data = $this->validated(['merchant_no' => $merchantNo], BalanceValidator::class, 'show');
|
||||
|
||||
$currentMerchantNo = $this->currentMerchantNo($request);
|
||||
if ($currentMerchantNo !== '' && $currentMerchantNo !== (string) $data['merchant_no']) {
|
||||
return $this->fail('无权查看该商户余额', 403);
|
||||
}
|
||||
|
||||
$merchant = $this->merchantService->findEnabledMerchantByNo((string) $data['merchant_no']);
|
||||
|
||||
return $this->success($this->merchantAccountService->getBalanceSnapshot((int) $merchant->id));
|
||||
}
|
||||
}
|
||||
|
||||
191
app/http/mer/controller/merchant/MerchantPortalController.php
Normal file
191
app/http/mer/controller/merchant/MerchantPortalController.php
Normal file
@@ -0,0 +1,191 @@
|
||||
<?php
|
||||
|
||||
namespace app\http\mer\controller\merchant;
|
||||
|
||||
use app\common\base\BaseController;
|
||||
use app\http\mer\validation\MerchantPortalValidator;
|
||||
use app\service\merchant\portal\MerchantPortalService;
|
||||
use support\Request;
|
||||
use support\Response;
|
||||
|
||||
/**
|
||||
* 商户后台基础页面控制器。
|
||||
*
|
||||
* 统一承接当前商户可见的资料、通道、路由、凭证、清算和资金页面数据。
|
||||
*/
|
||||
class MerchantPortalController extends BaseController
|
||||
{
|
||||
public function __construct(
|
||||
protected MerchantPortalService $merchantPortalService
|
||||
) {
|
||||
}
|
||||
|
||||
/**
|
||||
* 当前商户资料。
|
||||
*/
|
||||
public function profile(Request $request): Response
|
||||
{
|
||||
$merchantId = $this->currentMerchantId($request);
|
||||
if ($merchantId <= 0) {
|
||||
return $this->fail('未获取到当前商户信息', 401);
|
||||
}
|
||||
|
||||
return $this->success($this->merchantPortalService->profile($merchantId));
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新当前商户资料。
|
||||
*/
|
||||
public function updateProfile(Request $request): Response
|
||||
{
|
||||
$merchantId = $this->currentMerchantId($request);
|
||||
if ($merchantId <= 0) {
|
||||
return $this->fail('未获取到当前商户信息', 401);
|
||||
}
|
||||
|
||||
$data = $this->validated($this->payload($request), MerchantPortalValidator::class, 'profileUpdate');
|
||||
|
||||
return $this->success($this->merchantPortalService->updateProfile($merchantId, $data));
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改当前商户登录密码。
|
||||
*/
|
||||
public function changePassword(Request $request): Response
|
||||
{
|
||||
$merchantId = $this->currentMerchantId($request);
|
||||
if ($merchantId <= 0) {
|
||||
return $this->fail('未获取到当前商户信息', 401);
|
||||
}
|
||||
|
||||
$data = $this->validated($this->payload($request), MerchantPortalValidator::class, 'passwordUpdate');
|
||||
|
||||
return $this->success($this->merchantPortalService->changePassword($merchantId, $data));
|
||||
}
|
||||
|
||||
/**
|
||||
* 我的通道列表。
|
||||
*/
|
||||
public function myChannels(Request $request): Response
|
||||
{
|
||||
$merchantId = $this->currentMerchantId($request);
|
||||
if ($merchantId <= 0) {
|
||||
return $this->fail('未获取到当前商户信息', 401);
|
||||
}
|
||||
|
||||
$payload = $this->payload($request);
|
||||
$page = max(1, (int) ($payload['page'] ?? 1));
|
||||
$pageSize = max(1, (int) ($payload['page_size'] ?? 10));
|
||||
|
||||
return $this->success($this->merchantPortalService->myChannels($payload, $merchantId, $page, $pageSize));
|
||||
}
|
||||
|
||||
/**
|
||||
* 路由预览。
|
||||
*/
|
||||
public function routePreview(Request $request): Response
|
||||
{
|
||||
$merchantId = $this->currentMerchantId($request);
|
||||
if ($merchantId <= 0) {
|
||||
return $this->fail('未获取到当前商户信息', 401);
|
||||
}
|
||||
|
||||
$payload = $this->validated($this->payload($request), MerchantPortalValidator::class, 'routePreview');
|
||||
$payTypeId = (int) ($payload['pay_type_id'] ?? 0);
|
||||
$payAmount = (int) ($payload['pay_amount'] ?? 0);
|
||||
$statDate = trim((string) ($payload['stat_date'] ?? ''));
|
||||
|
||||
return $this->success($this->merchantPortalService->routePreview($merchantId, $payTypeId, $payAmount, $statDate));
|
||||
}
|
||||
|
||||
/**
|
||||
* 当前商户接口凭证。
|
||||
*/
|
||||
public function apiCredential(Request $request): Response
|
||||
{
|
||||
$merchantId = $this->currentMerchantId($request);
|
||||
if ($merchantId <= 0) {
|
||||
return $this->fail('未获取到当前商户信息', 401);
|
||||
}
|
||||
|
||||
return $this->success($this->merchantPortalService->apiCredential($merchantId));
|
||||
}
|
||||
|
||||
/**
|
||||
* 生成或重置接口凭证。
|
||||
*/
|
||||
public function issueCredential(Request $request): Response
|
||||
{
|
||||
$merchantId = $this->currentMerchantId($request);
|
||||
if ($merchantId <= 0) {
|
||||
return $this->fail('未获取到当前商户信息', 401);
|
||||
}
|
||||
|
||||
return $this->success($this->merchantPortalService->issueCredential($merchantId));
|
||||
}
|
||||
|
||||
/**
|
||||
* 当前商户的清算记录列表。
|
||||
*/
|
||||
public function settlementRecords(Request $request): Response
|
||||
{
|
||||
$merchantId = $this->currentMerchantId($request);
|
||||
if ($merchantId <= 0) {
|
||||
return $this->fail('未获取到当前商户信息', 401);
|
||||
}
|
||||
|
||||
$payload = $this->payload($request);
|
||||
$page = max(1, (int) ($payload['page'] ?? 1));
|
||||
$pageSize = max(1, (int) ($payload['page_size'] ?? 10));
|
||||
|
||||
return $this->success($this->merchantPortalService->settlementRecords($payload, $merchantId, $page, $pageSize));
|
||||
}
|
||||
|
||||
/**
|
||||
* 当前商户的清算记录详情。
|
||||
*/
|
||||
public function settlementRecordShow(Request $request, string $settleNo): Response
|
||||
{
|
||||
$merchantId = $this->currentMerchantId($request);
|
||||
if ($merchantId <= 0) {
|
||||
return $this->fail('未获取到当前商户信息', 401);
|
||||
}
|
||||
|
||||
$detail = $this->merchantPortalService->settlementRecordDetail($settleNo, $merchantId);
|
||||
if (!$detail) {
|
||||
return $this->fail('清算记录不存在', 404);
|
||||
}
|
||||
|
||||
return $this->success($detail);
|
||||
}
|
||||
|
||||
/**
|
||||
* 当前商户可提现余额快照。
|
||||
*/
|
||||
public function withdrawableBalance(Request $request): Response
|
||||
{
|
||||
$merchantId = $this->currentMerchantId($request);
|
||||
if ($merchantId <= 0) {
|
||||
return $this->fail('未获取到当前商户信息', 401);
|
||||
}
|
||||
|
||||
return $this->success($this->merchantPortalService->withdrawableBalance($merchantId));
|
||||
}
|
||||
|
||||
/**
|
||||
* 当前商户资金流水列表。
|
||||
*/
|
||||
public function balanceFlows(Request $request): Response
|
||||
{
|
||||
$merchantId = $this->currentMerchantId($request);
|
||||
if ($merchantId <= 0) {
|
||||
return $this->fail('未获取到当前商户信息', 401);
|
||||
}
|
||||
|
||||
$payload = $this->payload($request);
|
||||
$page = max(1, (int) ($payload['page'] ?? 1));
|
||||
$pageSize = max(1, (int) ($payload['page_size'] ?? 10));
|
||||
|
||||
return $this->success($this->merchantPortalService->balanceFlows($payload, $merchantId, $page, $pageSize));
|
||||
}
|
||||
}
|
||||
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', '')));
|
||||
}
|
||||
}
|
||||
|
||||
44
app/http/mer/controller/trade/PayOrderController.php
Normal file
44
app/http/mer/controller/trade/PayOrderController.php
Normal file
@@ -0,0 +1,44 @@
|
||||
<?php
|
||||
|
||||
namespace app\http\mer\controller\trade;
|
||||
|
||||
use app\common\base\BaseController;
|
||||
use app\http\mer\validation\PayOrderValidator;
|
||||
use app\service\payment\order\PayOrderService;
|
||||
use support\Request;
|
||||
use support\Response;
|
||||
|
||||
/**
|
||||
* 商户后台支付订单控制器。
|
||||
*
|
||||
* 商户后台只能看到当前登录商户自己的支付订单。
|
||||
*/
|
||||
class PayOrderController extends BaseController
|
||||
{
|
||||
/**
|
||||
* 构造函数,注入支付订单服务。
|
||||
*/
|
||||
public function __construct(
|
||||
protected PayOrderService $payOrderService
|
||||
) {
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询当前商户的支付订单列表。
|
||||
*/
|
||||
public function index(Request $request): Response
|
||||
{
|
||||
$merchantId = $this->currentMerchantId($request);
|
||||
if ($merchantId <= 0) {
|
||||
return $this->fail('未获取到当前商户信息', 401);
|
||||
}
|
||||
|
||||
$data = $this->validated($request->all(), PayOrderValidator::class, 'index');
|
||||
$data['merchant_id'] = $merchantId;
|
||||
$page = max(1, (int) ($data['page'] ?? 1));
|
||||
$pageSize = max(1, (int) ($data['page_size'] ?? 10));
|
||||
|
||||
return $this->success($this->payOrderService->paginate($data, $page, $pageSize, $merchantId));
|
||||
}
|
||||
}
|
||||
|
||||
72
app/http/mer/controller/trade/RefundOrderController.php
Normal file
72
app/http/mer/controller/trade/RefundOrderController.php
Normal file
@@ -0,0 +1,72 @@
|
||||
<?php
|
||||
|
||||
namespace app\http\mer\controller\trade;
|
||||
|
||||
use app\common\base\BaseController;
|
||||
use app\http\mer\validation\RefundActionValidator;
|
||||
use app\http\mer\validation\RefundOrderValidator;
|
||||
use app\service\payment\order\RefundService;
|
||||
use support\Request;
|
||||
use support\Response;
|
||||
|
||||
/**
|
||||
* 商户后台退款订单控制器。
|
||||
*/
|
||||
class RefundOrderController extends BaseController
|
||||
{
|
||||
public function __construct(
|
||||
protected RefundService $refundService
|
||||
) {
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询当前商户的退款订单列表。
|
||||
*/
|
||||
public function index(Request $request): Response
|
||||
{
|
||||
$merchantId = $this->currentMerchantId($request);
|
||||
if ($merchantId <= 0) {
|
||||
return $this->fail('未获取到当前商户信息', 401);
|
||||
}
|
||||
|
||||
$data = $this->validated($request->all(), RefundOrderValidator::class, 'index');
|
||||
$data['merchant_id'] = $merchantId;
|
||||
$page = max(1, (int) ($data['page'] ?? 1));
|
||||
$pageSize = max(1, (int) ($data['page_size'] ?? 10));
|
||||
|
||||
return $this->success($this->refundService->paginate($data, $page, $pageSize, $merchantId));
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询当前商户的退款订单详情。
|
||||
*/
|
||||
public function show(Request $request, string $refundNo): Response
|
||||
{
|
||||
$merchantId = $this->currentMerchantId($request);
|
||||
if ($merchantId <= 0) {
|
||||
return $this->fail('未获取到当前商户信息', 401);
|
||||
}
|
||||
|
||||
return $this->success($this->refundService->detail($refundNo, $merchantId));
|
||||
}
|
||||
|
||||
/**
|
||||
* 重试当前商户的退款单。
|
||||
*/
|
||||
public function retry(Request $request, string $refundNo): Response
|
||||
{
|
||||
$merchantId = $this->currentMerchantId($request);
|
||||
if ($merchantId <= 0) {
|
||||
return $this->fail('未获取到当前商户信息', 401);
|
||||
}
|
||||
|
||||
$data = $this->validated(
|
||||
array_merge($request->all(), ['refund_no' => $refundNo]),
|
||||
RefundActionValidator::class,
|
||||
'retry'
|
||||
);
|
||||
|
||||
return $this->success($this->refundService->retryRefund($refundNo, $data, $merchantId));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user