mirror of
https://gitee.com/technical-laohu/mpay_v2_webman.git
synced 2026-05-10 10:54:27 +08:00
1. 维护代码健壮
2. 更新项目结构文档
This commit is contained in:
103
app/http/mer/controller/file/FileRecordController.php
Normal file
103
app/http/mer/controller/file/FileRecordController.php
Normal file
@@ -0,0 +1,103 @@
|
||||
<?php
|
||||
|
||||
namespace app\http\mer\controller\file;
|
||||
|
||||
use app\common\base\BaseController;
|
||||
use app\exception\ValidationException;
|
||||
use app\http\admin\validation\FileRecordValidator;
|
||||
use app\service\file\FileRecordService;
|
||||
use support\Request;
|
||||
use support\Response;
|
||||
use Webman\Http\UploadFile;
|
||||
|
||||
/**
|
||||
* 商户端文件控制器。
|
||||
*
|
||||
* 供插件配置动态表单中的上传字段使用。
|
||||
*
|
||||
* @property FileRecordService $fileRecordService 文件记录服务
|
||||
*/
|
||||
class FileRecordController extends BaseController
|
||||
{
|
||||
/**
|
||||
* 构造方法。
|
||||
*
|
||||
* @param FileRecordService $fileRecordService 文件记录服务
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(
|
||||
protected FileRecordService $fileRecordService
|
||||
) {
|
||||
}
|
||||
|
||||
/**
|
||||
* 上传文件记录。
|
||||
*
|
||||
* @param Request $request 请求对象
|
||||
* @return Response 响应对象
|
||||
* @throws ValidationException
|
||||
*/
|
||||
public function upload(Request $request): Response
|
||||
{
|
||||
$data = $this->validated(array_merge($this->payload($request), ['scene' => $request->input('scene')]), FileRecordValidator::class, 'store');
|
||||
$uploadedFile = $request->file('file');
|
||||
if ($uploadedFile === null) {
|
||||
throw new ValidationException('请先选择上传文件');
|
||||
}
|
||||
|
||||
$createdBy = $this->currentMerchantId($request);
|
||||
$createdByName = $this->currentMerchantNo($request);
|
||||
|
||||
if (is_array($uploadedFile)) {
|
||||
$items = [];
|
||||
foreach ($uploadedFile as $file) {
|
||||
if ($file instanceof UploadFile) {
|
||||
$items[] = $this->fileRecordService->upload($file, $data, $createdBy, $createdByName);
|
||||
}
|
||||
}
|
||||
|
||||
if ($items === []) {
|
||||
throw new ValidationException('上传文件无效');
|
||||
}
|
||||
|
||||
return $this->success([
|
||||
'list' => $items,
|
||||
'total' => count($items),
|
||||
]);
|
||||
}
|
||||
|
||||
if (!$uploadedFile instanceof UploadFile) {
|
||||
throw new ValidationException('上传文件无效');
|
||||
}
|
||||
|
||||
return $this->success($this->fileRecordService->upload($uploadedFile, $data, $createdBy, $createdByName));
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取文件预览响应。
|
||||
*
|
||||
* @param Request $request 请求对象
|
||||
* @param string $id 文件记录ID
|
||||
* @return Response 响应对象
|
||||
*/
|
||||
public function preview(Request $request, string $id): Response
|
||||
{
|
||||
$data = $this->validated(['id' => (int) $id], FileRecordValidator::class, 'preview');
|
||||
|
||||
return $this->fileRecordService->previewResponse((int) $data['id']);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取文件下载响应。
|
||||
*
|
||||
* @param Request $request 请求对象
|
||||
* @param string $id 文件记录ID
|
||||
* @return Response 响应对象
|
||||
*/
|
||||
public function download(Request $request, string $id): Response
|
||||
{
|
||||
$data = $this->validated(['id' => (int) $id], FileRecordValidator::class, 'download');
|
||||
|
||||
return $this->fileRecordService->downloadResponse((int) $data['id']);
|
||||
}
|
||||
}
|
||||
@@ -100,6 +100,138 @@ class MerchantPortalController extends BaseController
|
||||
return $this->success($this->merchantPortalService->myChannels($payload, $merchantId, $page, $pageSize));
|
||||
}
|
||||
|
||||
public function channelCreateMeta(Request $request): Response
|
||||
{
|
||||
return $this->success($this->merchantPortalService->channelCreateMeta());
|
||||
}
|
||||
|
||||
public function createChannel(Request $request): Response
|
||||
{
|
||||
$merchantId = $this->currentMerchantId($request);
|
||||
if ($merchantId <= 0) {
|
||||
return $this->fail('未获取到当前商户信息', 401);
|
||||
}
|
||||
|
||||
$data = $this->validated($this->payload($request), MerchantPortalValidator::class, 'channelStore');
|
||||
|
||||
return $this->success($this->merchantPortalService->createChannel($merchantId, $data));
|
||||
}
|
||||
|
||||
public function updateChannel(Request $request, string $id): Response
|
||||
{
|
||||
$merchantId = $this->currentMerchantId($request);
|
||||
if ($merchantId <= 0) {
|
||||
return $this->fail('未获取到当前商户信息', 401);
|
||||
}
|
||||
|
||||
$data = $this->validated(
|
||||
array_merge($this->payload($request), ['id' => (int) $id]),
|
||||
MerchantPortalValidator::class,
|
||||
'channelUpdate'
|
||||
);
|
||||
|
||||
$channel = $this->merchantPortalService->updateChannel($merchantId, (int) $data['id'], $data);
|
||||
if (!$channel) {
|
||||
return $this->fail('通道不存在', 404);
|
||||
}
|
||||
|
||||
return $this->success($channel);
|
||||
}
|
||||
|
||||
public function deleteChannel(Request $request, string $id): Response
|
||||
{
|
||||
$merchantId = $this->currentMerchantId($request);
|
||||
if ($merchantId <= 0) {
|
||||
return $this->fail('未获取到当前商户信息', 401);
|
||||
}
|
||||
|
||||
$data = $this->validated(['id' => (int) $id], MerchantPortalValidator::class, 'channelDestroy');
|
||||
if (!$this->merchantPortalService->deleteChannel($merchantId, (int) $data['id'])) {
|
||||
return $this->fail('通道不存在', 404);
|
||||
}
|
||||
|
||||
return $this->success(true);
|
||||
}
|
||||
|
||||
public function pluginConfigs(Request $request): Response
|
||||
{
|
||||
$merchantId = $this->currentMerchantId($request);
|
||||
if ($merchantId <= 0) {
|
||||
return $this->fail('未获取到当前商户信息', 401);
|
||||
}
|
||||
|
||||
$payload = $this->validated($this->payload($request), MerchantPortalValidator::class, 'pluginConfigIndex');
|
||||
$page = max(1, (int) ($payload['page'] ?? 1));
|
||||
$pageSize = max(1, (int) ($payload['page_size'] ?? 10));
|
||||
|
||||
return $this->success($this->merchantPortalService->pluginConfigs($payload, $merchantId, $page, $pageSize));
|
||||
}
|
||||
|
||||
public function createPluginConfig(Request $request): Response
|
||||
{
|
||||
$merchantId = $this->currentMerchantId($request);
|
||||
if ($merchantId <= 0) {
|
||||
return $this->fail('未获取到当前商户信息', 401);
|
||||
}
|
||||
|
||||
$data = $this->validated($this->payload($request), MerchantPortalValidator::class, 'pluginConfigStore');
|
||||
|
||||
return $this->success($this->merchantPortalService->createPluginConfig($merchantId, $data));
|
||||
}
|
||||
|
||||
public function updatePluginConfig(Request $request, string $id): Response
|
||||
{
|
||||
$merchantId = $this->currentMerchantId($request);
|
||||
if ($merchantId <= 0) {
|
||||
return $this->fail('未获取到当前商户信息', 401);
|
||||
}
|
||||
|
||||
$data = $this->validated(
|
||||
array_merge($this->payload($request), ['id' => (int) $id]),
|
||||
MerchantPortalValidator::class,
|
||||
'pluginConfigUpdate'
|
||||
);
|
||||
|
||||
$config = $this->merchantPortalService->updatePluginConfig($merchantId, (int) $data['id'], $data);
|
||||
if (!$config) {
|
||||
return $this->fail('插件配置不存在', 404);
|
||||
}
|
||||
|
||||
return $this->success($config);
|
||||
}
|
||||
|
||||
public function deletePluginConfig(Request $request, string $id): Response
|
||||
{
|
||||
$merchantId = $this->currentMerchantId($request);
|
||||
if ($merchantId <= 0) {
|
||||
return $this->fail('未获取到当前商户信息', 401);
|
||||
}
|
||||
|
||||
$data = $this->validated(['id' => (int) $id], MerchantPortalValidator::class, 'pluginConfigDestroy');
|
||||
if (!$this->merchantPortalService->deletePluginConfig($merchantId, (int) $data['id'])) {
|
||||
return $this->fail('插件配置不存在', 404);
|
||||
}
|
||||
|
||||
return $this->success(true);
|
||||
}
|
||||
|
||||
public function pluginConfigOptions(Request $request): Response
|
||||
{
|
||||
$merchantId = $this->currentMerchantId($request);
|
||||
if ($merchantId <= 0) {
|
||||
return $this->fail('未获取到当前商户信息', 401);
|
||||
}
|
||||
|
||||
return $this->success([
|
||||
'configs' => $this->merchantPortalService->pluginConfigOptions($merchantId, (string) $request->get('plugin_code', '')),
|
||||
]);
|
||||
}
|
||||
|
||||
public function pluginSchema(Request $request, string $code): Response
|
||||
{
|
||||
return $this->success($this->merchantPortalService->pluginSchema($code));
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取路由解析结果。
|
||||
*
|
||||
@@ -113,7 +245,12 @@ class MerchantPortalController extends BaseController
|
||||
return $this->fail('未获取到当前商户信息', 401);
|
||||
}
|
||||
|
||||
$payload = $this->validated($this->payload($request), MerchantPortalValidator::class, 'routePreview');
|
||||
$rawPayload = $this->payload($request);
|
||||
if (empty($rawPayload['pay_type_id']) || empty($rawPayload['pay_amount'])) {
|
||||
return $this->success($this->merchantPortalService->routePreview($merchantId, 0, 0));
|
||||
}
|
||||
|
||||
$payload = $this->validated($rawPayload, MerchantPortalValidator::class, 'routePreview');
|
||||
$payTypeId = (int) ($payload['pay_type_id'] ?? 0);
|
||||
$payAmount = (int) ($payload['pay_amount'] ?? 0);
|
||||
$statDate = trim((string) ($payload['stat_date'] ?? ''));
|
||||
@@ -150,7 +287,9 @@ class MerchantPortalController extends BaseController
|
||||
return $this->fail('未获取到当前商户信息', 401);
|
||||
}
|
||||
|
||||
return $this->success($this->merchantPortalService->issueCredential($merchantId));
|
||||
$data = $this->validated($this->payload($request), MerchantPortalValidator::class, 'issueCredential');
|
||||
|
||||
return $this->success($this->merchantPortalService->issueCredential($merchantId, $data));
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user