重构初始化

This commit is contained in:
技术老胡
2026-04-15 11:45:46 +08:00
parent 72d72d735b
commit 7612026773
381 changed files with 28287 additions and 14717 deletions

View File

@@ -0,0 +1,138 @@
<?php
namespace app\http\admin\controller\payment;
use app\common\base\BaseController;
use app\http\admin\validation\PaymentChannelValidator;
use app\service\payment\config\PaymentChannelService;
use support\Request;
use support\Response;
/**
* 支付通道管理控制器。
*
* 负责支付通道的列表、详情、新增、修改和删除。
*/
class PaymentChannelController extends BaseController
{
/**
* 构造函数,注入支付通道服务。
*/
public function __construct(
protected PaymentChannelService $paymentChannelService
) {
}
/**
* GET /admin/payment-channels
*
* 查询支付通道列表。
*/
public function index(Request $request): Response
{
$data = $this->validated($request->all(), PaymentChannelValidator::class, 'index');
return $this->page(
$this->paymentChannelService->paginate(
$data,
(int) ($data['page'] ?? 1),
(int) ($data['page_size'] ?? 10)
)
);
}
/**
* GET /admin/payment-channels/{id}
*
* 查询支付通道详情。
*/
public function show(Request $request, string $id): Response
{
$data = $this->validated(['id' => (int) $id], PaymentChannelValidator::class, 'show');
$paymentChannel = $this->paymentChannelService->findById((int) $data['id']);
if (!$paymentChannel) {
return $this->fail('支付通道不存在', 404);
}
return $this->success($paymentChannel);
}
/**
* POST /admin/payment-channels
*
* 新增支付通道。
*/
public function store(Request $request): Response
{
$data = $this->validated($request->all(), PaymentChannelValidator::class, 'store');
return $this->success($this->paymentChannelService->create($data));
}
/**
* PUT /admin/payment-channels/{id}
*
* 修改支付通道。
*/
public function update(Request $request, string $id): Response
{
$payload = $request->all();
$scene = array_diff(array_keys($payload), ['status']) === [] ? 'updateStatus' : 'update';
$data = $this->validated(
array_merge($payload, ['id' => (int) $id]),
PaymentChannelValidator::class,
$scene
);
$paymentChannel = $this->paymentChannelService->update((int) $data['id'], $data);
if (!$paymentChannel) {
return $this->fail('支付通道不存在', 404);
}
return $this->success($paymentChannel);
}
/**
* DELETE /admin/payment-channels/{id}
*
* 删除支付通道。
*/
public function destroy(Request $request, string $id): Response
{
$data = $this->validated(['id' => (int) $id], PaymentChannelValidator::class, 'destroy');
if (!$this->paymentChannelService->delete((int) $data['id'])) {
return $this->fail('支付通道不存在', 404);
}
return $this->success(true);
}
/**
* 查询启用中的通道选项。
*/
public function options(Request $request): Response
{
return $this->success($this->paymentChannelService->enabledOptions());
}
/**
* 查询路由编排场景下的通道选项。
*/
public function routeOptions(Request $request): Response
{
return $this->success($this->paymentChannelService->routeOptions($request->all()));
}
/**
* 远程查询支付通道选择项。
*/
public function selectOptions(Request $request): Response
{
$page = max(1, (int) $request->input('page', 1));
$pageSize = min(50, max(1, (int) $request->input('page_size', 20)));
return $this->success($this->paymentChannelService->searchOptions($request->all(), $page, $pageSize));
}
}

View File

@@ -0,0 +1,98 @@
<?php
namespace app\http\admin\controller\payment;
use app\common\base\BaseController;
use app\http\admin\validation\PaymentPluginConfValidator;
use app\service\payment\config\PaymentPluginConfService;
use support\Request;
use support\Response;
/**
* 支付插件配置控制器。
*
* 负责插件公共配置的列表、详情、增删改和选项输出。
*/
class PaymentPluginConfController extends BaseController
{
public function __construct(
protected PaymentPluginConfService $paymentPluginConfService
) {
}
public function index(Request $request): Response
{
$data = $this->validated($request->all(), PaymentPluginConfValidator::class, 'index');
$page = max(1, (int) ($data['page'] ?? 1));
$pageSize = max(1, (int) ($data['page_size'] ?? 10));
return $this->page($this->paymentPluginConfService->paginate($data, $page, $pageSize));
}
public function show(Request $request, string $id): Response
{
$data = $this->validated(['id' => (int) $id], PaymentPluginConfValidator::class, 'show');
$pluginConf = $this->paymentPluginConfService->findById((int) $data['id']);
if (!$pluginConf) {
return $this->fail('插件配置不存在', 404);
}
return $this->success($pluginConf);
}
public function store(Request $request): Response
{
$data = $this->validated($request->all(), PaymentPluginConfValidator::class, 'store');
return $this->success($this->paymentPluginConfService->create($data));
}
public function update(Request $request, string $id): Response
{
$data = $this->validated(
array_merge($request->all(), ['id' => (int) $id]),
PaymentPluginConfValidator::class,
'update'
);
$pluginConf = $this->paymentPluginConfService->update((int) $data['id'], $data);
if (!$pluginConf) {
return $this->fail('插件配置不存在', 404);
}
return $this->success($pluginConf);
}
public function destroy(Request $request, string $id): Response
{
$data = $this->validated(['id' => (int) $id], PaymentPluginConfValidator::class, 'destroy');
if (!$this->paymentPluginConfService->delete((int) $data['id'])) {
return $this->fail('插件配置不存在', 404);
}
return $this->success(true);
}
public function options(Request $request): Response
{
$data = $this->validated($request->all(), PaymentPluginConfValidator::class, 'options');
return $this->success([
'configs' => $this->paymentPluginConfService->options((string) ($data['plugin_code'] ?? '')),
]);
}
/**
* 远程查询插件配置选项。
*/
public function selectOptions(Request $request): Response
{
$data = $this->validated($request->all(), PaymentPluginConfValidator::class, 'selectOptions');
$page = max(1, (int) ($data['page'] ?? 1));
$pageSize = min(50, max(1, (int) ($data['page_size'] ?? 20)));
return $this->success($this->paymentPluginConfService->searchOptions($data, $page, $pageSize));
}
}

View File

@@ -0,0 +1,123 @@
<?php
namespace app\http\admin\controller\payment;
use app\common\base\BaseController;
use app\http\admin\validation\PaymentPluginValidator;
use app\service\payment\config\PaymentPluginService;
use support\Request;
use support\Response;
/**
* 支付插件管理控制器。
*
* 负责插件字典的列表、详情、刷新同步和状态备注维护。
*/
class PaymentPluginController extends BaseController
{
/**
* 构造函数,注入支付插件服务。
*/
public function __construct(
protected PaymentPluginService $paymentPluginService
) {
}
/**
* 查询支付插件列表。
*/
public function index(Request $request): Response
{
$data = $this->validated($request->all(), PaymentPluginValidator::class, 'index');
$page = max(1, (int) ($data['page'] ?? 1));
$pageSize = max(1, (int) ($data['page_size'] ?? 10));
return $this->page($this->paymentPluginService->paginate($data, $page, $pageSize));
}
/**
* 查询支付插件详情。
*/
public function show(Request $request, string $code): Response
{
$data = $this->validated(['code' => $code], PaymentPluginValidator::class, 'show');
$paymentPlugin = $this->paymentPluginService->findByCode((string) $data['code']);
if (!$paymentPlugin) {
return $this->fail('支付插件不存在', 404);
}
return $this->success($paymentPlugin);
}
/**
* 修改支付插件。
*/
public function update(Request $request, string $code): Response
{
$payload = $request->all();
$scene = array_diff(array_keys($payload), ['status']) === [] ? 'updateStatus' : 'update';
$data = $this->validated(
array_merge($payload, ['code' => $code]),
PaymentPluginValidator::class,
$scene
);
$paymentPlugin = $this->paymentPluginService->update((string) $data['code'], $data);
if (!$paymentPlugin) {
return $this->fail('支付插件不存在', 404);
}
return $this->success($paymentPlugin);
}
/**
* 从插件目录刷新同步支付插件。
*/
public function refresh(Request $request): Response
{
return $this->success($this->paymentPluginService->refreshFromClasses());
}
/**
* 查询支付插件下拉选项。
*/
public function options(Request $request): Response
{
return $this->success([
'plugins' => $this->paymentPluginService->enabledOptions(),
]);
}
/**
* 远程查询支付插件选项。
*/
public function selectOptions(Request $request): Response
{
$data = $this->validated($request->all(), PaymentPluginValidator::class, 'selectOptions');
$page = max(1, (int) ($data['page'] ?? 1));
$pageSize = min(50, max(1, (int) ($data['page_size'] ?? 20)));
return $this->success($this->paymentPluginService->searchOptions($data, $page, $pageSize));
}
/**
* 查询通道配置场景下的插件选项。
*/
public function channelOptions(Request $request): Response
{
return $this->success([
'plugins' => $this->paymentPluginService->channelOptions(),
]);
}
/**
* 查询插件配置结构。
*/
public function schema(Request $request, string $code): Response
{
$data = $this->validated(['code' => $code], PaymentPluginValidator::class, 'show');
return $this->success($this->paymentPluginService->getSchema((string) $data['code']));
}
}

View File

@@ -0,0 +1,77 @@
<?php
namespace app\http\admin\controller\payment;
use app\common\base\BaseController;
use app\http\admin\validation\PaymentPollGroupBindValidator;
use app\service\payment\config\PaymentPollGroupBindService;
use support\Request;
use support\Response;
/**
* 商户分组路由绑定控制器。
*/
class PaymentPollGroupBindController extends BaseController
{
public function __construct(
protected PaymentPollGroupBindService $paymentPollGroupBindService
) {
}
public function index(Request $request): Response
{
$data = $this->validated($request->all(), PaymentPollGroupBindValidator::class, 'index');
return $this->page(
$this->paymentPollGroupBindService->paginate(
$data,
(int) ($data['page'] ?? 1),
(int) ($data['page_size'] ?? 10)
)
);
}
public function show(Request $request, string $id): Response
{
$data = $this->validated(['id' => (int) $id], PaymentPollGroupBindValidator::class, 'show');
$row = $this->paymentPollGroupBindService->findById((int) $data['id']);
if (!$row) {
return $this->fail('商户分组路由绑定不存在', 404);
}
return $this->success($row);
}
public function store(Request $request): Response
{
$data = $this->validated($request->all(), PaymentPollGroupBindValidator::class, 'store');
return $this->success($this->paymentPollGroupBindService->create($data));
}
public function update(Request $request, string $id): Response
{
$data = $this->validated(
array_merge($request->all(), ['id' => (int) $id]),
PaymentPollGroupBindValidator::class,
'update'
);
$row = $this->paymentPollGroupBindService->update((int) $data['id'], $data);
if (!$row) {
return $this->fail('商户分组路由绑定不存在', 404);
}
return $this->success($row);
}
public function destroy(Request $request, string $id): Response
{
$data = $this->validated(['id' => (int) $id], PaymentPollGroupBindValidator::class, 'destroy');
if (!$this->paymentPollGroupBindService->delete((int) $data['id'])) {
return $this->fail('商户分组路由绑定不存在', 404);
}
return $this->success(true);
}
}

View File

@@ -0,0 +1,79 @@
<?php
namespace app\http\admin\controller\payment;
use app\common\base\BaseController;
use app\http\admin\validation\PaymentPollGroupChannelValidator;
use app\service\payment\config\PaymentPollGroupChannelService;
use support\Request;
use support\Response;
/**
* 轮询组通道编排控制器。
*/
class PaymentPollGroupChannelController extends BaseController
{
public function __construct(
protected PaymentPollGroupChannelService $paymentPollGroupChannelService
) {
}
public function index(Request $request): Response
{
$data = $this->validated($request->all(), PaymentPollGroupChannelValidator::class, 'index');
return $this->page(
$this->paymentPollGroupChannelService->paginate(
$data,
(int) ($data['page'] ?? 1),
(int) ($data['page_size'] ?? 10)
)
);
}
public function show(Request $request, string $id): Response
{
$data = $this->validated(['id' => (int) $id], PaymentPollGroupChannelValidator::class, 'show');
$row = $this->paymentPollGroupChannelService->findById((int) $data['id']);
if (!$row) {
return $this->fail('轮询组通道编排不存在', 404);
}
return $this->success($row);
}
public function store(Request $request): Response
{
$data = $this->validated($request->all(), PaymentPollGroupChannelValidator::class, 'store');
return $this->success($this->paymentPollGroupChannelService->create($data));
}
public function update(Request $request, string $id): Response
{
$payload = $request->all();
$scene = array_diff(array_keys($payload), ['status']) === [] ? 'updateStatus' : 'update';
$data = $this->validated(
array_merge($payload, ['id' => (int) $id]),
PaymentPollGroupChannelValidator::class,
$scene
);
$row = $this->paymentPollGroupChannelService->update((int) $data['id'], $data);
if (!$row) {
return $this->fail('轮询组通道编排不存在', 404);
}
return $this->success($row);
}
public function destroy(Request $request, string $id): Response
{
$data = $this->validated(['id' => (int) $id], PaymentPollGroupChannelValidator::class, 'destroy');
if (!$this->paymentPollGroupChannelService->delete((int) $data['id'])) {
return $this->fail('轮询组通道编排不存在', 404);
}
return $this->success(true);
}
}

View File

@@ -0,0 +1,119 @@
<?php
namespace app\http\admin\controller\payment;
use app\common\base\BaseController;
use app\http\admin\validation\PaymentPollGroupValidator;
use app\service\payment\config\PaymentPollGroupService;
use support\Request;
use support\Response;
/**
* 支付轮询组管理控制器。
*
* 负责轮询组的列表、详情、新增、修改和删除。
*/
class PaymentPollGroupController extends BaseController
{
/**
* 构造函数,注入轮询组服务。
*/
public function __construct(
protected PaymentPollGroupService $paymentPollGroupService
) {
}
/**
* GET /admin/payment-poll-groups
*
* 查询轮询组列表。
*/
public function index(Request $request): Response
{
$data = $this->validated($request->all(), PaymentPollGroupValidator::class, 'index');
return $this->page(
$this->paymentPollGroupService->paginate(
$data,
(int) ($data['page'] ?? 1),
(int) ($data['page_size'] ?? 10)
)
);
}
/**
* GET /admin/payment-poll-groups/{id}
*
* 查询轮询组详情。
*/
public function show(Request $request, string $id): Response
{
$data = $this->validated(['id' => (int) $id], PaymentPollGroupValidator::class, 'show');
$paymentPollGroup = $this->paymentPollGroupService->findById((int) $data['id']);
if (!$paymentPollGroup) {
return $this->fail('轮询组不存在', 404);
}
return $this->success($paymentPollGroup);
}
/**
* POST /admin/payment-poll-groups
*
* 新增轮询组。
*/
public function store(Request $request): Response
{
$data = $this->validated($request->all(), PaymentPollGroupValidator::class, 'store');
return $this->success($this->paymentPollGroupService->create($data));
}
/**
* PUT /admin/payment-poll-groups/{id}
*
* 修改轮询组。
*/
public function update(Request $request, string $id): Response
{
$payload = $request->all();
$scene = array_diff(array_keys($payload), ['status']) === [] ? 'updateStatus' : 'update';
$data = $this->validated(
array_merge($payload, ['id' => (int) $id]),
PaymentPollGroupValidator::class,
$scene
);
$paymentPollGroup = $this->paymentPollGroupService->update((int) $data['id'], $data);
if (!$paymentPollGroup) {
return $this->fail('轮询组不存在', 404);
}
return $this->success($paymentPollGroup);
}
/**
* DELETE /admin/payment-poll-groups/{id}
*
* 删除轮询组。
*/
public function destroy(Request $request, string $id): Response
{
$data = $this->validated(['id' => (int) $id], PaymentPollGroupValidator::class, 'destroy');
if (!$this->paymentPollGroupService->delete((int) $data['id'])) {
return $this->fail('轮询组不存在', 404);
}
return $this->success(true);
}
/**
* 查询轮询组下拉选项。
*/
public function options(Request $request): Response
{
return $this->success($this->paymentPollGroupService->enabledOptions($request->all()));
}
}

View File

@@ -0,0 +1,105 @@
<?php
namespace app\http\admin\controller\payment;
use app\common\base\BaseController;
use app\http\admin\validation\PaymentTypeValidator;
use app\service\payment\config\PaymentTypeService;
use support\Request;
use support\Response;
/**
* 支付方式管理控制器。
*
* 负责支付方式字典的列表、详情、新增、修改、删除和选项输出。
*/
class PaymentTypeController extends BaseController
{
/**
* 构造函数,注入支付方式服务。
*/
public function __construct(
protected PaymentTypeService $paymentTypeService
) {
}
/**
* 查询支付方式列表。
*/
public function index(Request $request): Response
{
$data = $this->validated($request->all(), PaymentTypeValidator::class, 'index');
$page = max(1, (int) ($data['page'] ?? 1));
$pageSize = max(1, (int) ($data['page_size'] ?? 10));
return $this->page($this->paymentTypeService->paginate($data, $page, $pageSize));
}
/**
* 查询支付方式详情。
*/
public function show(Request $request, string $id): Response
{
$data = $this->validated(['id' => (int) $id], PaymentTypeValidator::class, 'show');
$paymentType = $this->paymentTypeService->findById((int) $data['id']);
if (!$paymentType) {
return $this->fail('支付方式不存在', 404);
}
return $this->success($paymentType);
}
/**
* 新增支付方式。
*/
public function store(Request $request): Response
{
$data = $this->validated($request->all(), PaymentTypeValidator::class, 'store');
return $this->success($this->paymentTypeService->create($data));
}
/**
* 修改支付方式。
*/
public function update(Request $request, string $id): Response
{
$payload = $request->all();
$scene = array_diff(array_keys($payload), ['status']) === [] ? 'updateStatus' : 'update';
$data = $this->validated(
array_merge($payload, ['id' => (int) $id]),
PaymentTypeValidator::class,
$scene
);
$paymentType = $this->paymentTypeService->update((int) $data['id'], $data);
if (!$paymentType) {
return $this->fail('支付方式不存在', 404);
}
return $this->success($paymentType);
}
/**
* 删除支付方式。
*/
public function destroy(Request $request, string $id): Response
{
$data = $this->validated(['id' => (int) $id], PaymentTypeValidator::class, 'destroy');
if (!$this->paymentTypeService->delete((int) $data['id'])) {
return $this->fail('支付方式不存在', 404);
}
return $this->success(true);
}
/**
* 查询支付方式下拉选项。
*/
public function options(Request $request): Response
{
return $this->success($this->paymentTypeService->enabledOptions());
}
}

View File

@@ -0,0 +1,43 @@
<?php
namespace app\http\admin\controller\payment;
use app\common\base\BaseController;
use app\http\admin\validation\RouteResolveValidator;
use app\service\payment\runtime\PaymentRouteService;
use support\Request;
use support\Response;
/**
* 管理后台路由预览控制器。
*
* 负责按商户分组、支付方式和金额条件解析可用通道。
*/
class RouteController extends BaseController
{
/**
* 构造函数,注入路由服务。
*/
public function __construct(
protected PaymentRouteService $paymentRouteService
) {
}
/**
* GET /admin/routes/resolve
*
* 解析路由结果。
*/
public function resolve(Request $request): Response
{
$data = $this->validated($request->all(), RouteResolveValidator::class, 'resolve');
return $this->success($this->paymentRouteService->resolveByMerchantGroup(
(int) $data['merchant_group_id'],
(int) $data['pay_type_id'],
(int) $data['pay_amount'],
$data
));
}
}