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:
@@ -0,0 +1,103 @@
|
||||
<?php
|
||||
|
||||
namespace app\http\admin\controller\merchant;
|
||||
|
||||
use app\common\base\BaseController;
|
||||
use app\http\admin\validation\MerchantApiCredentialValidator;
|
||||
use app\service\merchant\security\MerchantApiCredentialService;
|
||||
use support\Request;
|
||||
use support\Response;
|
||||
|
||||
/**
|
||||
* 商户接口凭证管理控制器。
|
||||
*/
|
||||
class MerchantApiCredentialController extends BaseController
|
||||
{
|
||||
/**
|
||||
* 构造函数,注入商户 API 凭证服务。
|
||||
*/
|
||||
public function __construct(
|
||||
protected MerchantApiCredentialService $merchantApiCredentialService
|
||||
) {
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询商户 API 凭证列表。
|
||||
*/
|
||||
public function index(Request $request): Response
|
||||
{
|
||||
$data = $this->validated($request->all(), MerchantApiCredentialValidator::class, 'index');
|
||||
|
||||
return $this->page(
|
||||
$this->merchantApiCredentialService->paginate(
|
||||
$data,
|
||||
(int) ($data['page'] ?? 1),
|
||||
(int) ($data['page_size'] ?? 10)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询商户 API 凭证详情。
|
||||
*/
|
||||
public function show(Request $request, string $id): Response
|
||||
{
|
||||
$data = $this->validated(['id' => (int) $id], MerchantApiCredentialValidator::class, 'show');
|
||||
$credential = $this->merchantApiCredentialService->findById((int) $data['id']);
|
||||
|
||||
if (!$credential) {
|
||||
return $this->fail('商户接口凭证不存在', 404);
|
||||
}
|
||||
|
||||
return $this->success($credential);
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增商户 API 凭证。
|
||||
*/
|
||||
public function store(Request $request): Response
|
||||
{
|
||||
$data = $this->validated($request->all(), MerchantApiCredentialValidator::class, 'store');
|
||||
|
||||
return $this->success($this->merchantApiCredentialService->create($data));
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改商户 API 凭证。
|
||||
*/
|
||||
public function update(Request $request, string $id): Response
|
||||
{
|
||||
$data = $this->validated(
|
||||
array_merge($request->all(), ['id' => (int) $id]),
|
||||
MerchantApiCredentialValidator::class,
|
||||
'update'
|
||||
);
|
||||
|
||||
$credential = $this->merchantApiCredentialService->update((int) $data['id'], $data);
|
||||
if (!$credential) {
|
||||
return $this->fail('商户接口凭证不存在', 404);
|
||||
}
|
||||
|
||||
return $this->success($credential);
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除商户 API 凭证。
|
||||
*/
|
||||
public function destroy(Request $request, string $id): Response
|
||||
{
|
||||
$data = $this->validated(['id' => (int) $id], MerchantApiCredentialValidator::class, 'destroy');
|
||||
$credential = $this->merchantApiCredentialService->findById((int) $data['id']);
|
||||
|
||||
if (!$credential) {
|
||||
return $this->fail('商户接口凭证不存在', 404);
|
||||
}
|
||||
|
||||
if (!$this->merchantApiCredentialService->delete((int) $data['id'])) {
|
||||
return $this->fail('商户接口凭证删除失败');
|
||||
}
|
||||
|
||||
return $this->success(true);
|
||||
}
|
||||
}
|
||||
|
||||
141
app/http/admin/controller/merchant/MerchantController.php
Normal file
141
app/http/admin/controller/merchant/MerchantController.php
Normal file
@@ -0,0 +1,141 @@
|
||||
<?php
|
||||
|
||||
namespace app\http\admin\controller\merchant;
|
||||
|
||||
use app\common\base\BaseController;
|
||||
use app\http\admin\validation\MerchantValidator;
|
||||
use app\service\merchant\MerchantService;
|
||||
use support\Request;
|
||||
use support\Response;
|
||||
|
||||
/**
|
||||
* 商户管理控制器。
|
||||
*
|
||||
* 当前先提供商户列表查询,后续可继续扩展商户详情、新增、编辑等能力。
|
||||
*/
|
||||
class MerchantController extends BaseController
|
||||
{
|
||||
/**
|
||||
* 构造函数,注入商户服务。
|
||||
*/
|
||||
public function __construct(
|
||||
protected MerchantService $merchantService
|
||||
) {
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询商户列表。
|
||||
*
|
||||
* 返回值里额外携带启用中的商户分组选项,方便前端一次性渲染筛选条件。
|
||||
*/
|
||||
public function index(Request $request): Response
|
||||
{
|
||||
$data = $this->validated($request->all(), MerchantValidator::class, 'index');
|
||||
$page = max(1, (int) ($data['page'] ?? 1));
|
||||
$pageSize = max(1, (int) ($data['page_size'] ?? 10));
|
||||
|
||||
return $this->success($this->merchantService->paginateWithGroupOptions($data, $page, $pageSize));
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询商户详情。
|
||||
*/
|
||||
public function show(Request $request, string $id): Response
|
||||
{
|
||||
$data = $this->validated(['id' => (int) $id], MerchantValidator::class, 'show');
|
||||
$merchant = $this->merchantService->findById((int) $data['id']);
|
||||
|
||||
if (!$merchant) {
|
||||
return $this->fail('商户不存在', 404);
|
||||
}
|
||||
|
||||
return $this->success($merchant);
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增商户。
|
||||
*/
|
||||
public function store(Request $request): Response
|
||||
{
|
||||
$data = $this->validated($request->all(), MerchantValidator::class, 'store');
|
||||
return $this->success($this->merchantService->createWithDetail($data));
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新商户。
|
||||
*/
|
||||
public function update(Request $request, string $id): Response
|
||||
{
|
||||
$payload = array_merge($request->all(), ['id' => (int) $id]);
|
||||
$scene = count(array_diff(array_keys($request->all()), ['status'])) === 0 ? 'updateStatus' : 'update';
|
||||
$data = $this->validated($payload, MerchantValidator::class, $scene);
|
||||
$merchant = $this->merchantService->updateWithDetail((int) $data['id'], $data);
|
||||
|
||||
if (!$merchant) {
|
||||
return $this->fail('商户不存在', 404);
|
||||
}
|
||||
|
||||
return $this->success($merchant);
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除商户。
|
||||
*/
|
||||
public function destroy(Request $request, string $id): Response
|
||||
{
|
||||
$data = $this->validated(['id' => (int) $id], MerchantValidator::class, 'destroy');
|
||||
|
||||
return $this->success($this->merchantService->delete((int) $data['id']));
|
||||
}
|
||||
|
||||
/**
|
||||
* 重置商户登录密码。
|
||||
*/
|
||||
public function resetPassword(Request $request, string $id): Response
|
||||
{
|
||||
$payload = array_merge($request->all(), ['id' => (int) $id]);
|
||||
$data = $this->validated($payload, MerchantValidator::class, 'resetPassword');
|
||||
|
||||
return $this->success($this->merchantService->resetPassword((int) $data['id'], (string) $data['password']));
|
||||
}
|
||||
|
||||
/**
|
||||
* 生成或重置商户接口凭证。
|
||||
*/
|
||||
public function issueCredential(Request $request, string $id): Response
|
||||
{
|
||||
$merchantId = (int) $id;
|
||||
|
||||
return $this->success($this->merchantService->issueCredential($merchantId));
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询商户总览。
|
||||
*/
|
||||
public function overview(Request $request, string $id): Response
|
||||
{
|
||||
$data = $this->validated(['id' => (int) $id], MerchantValidator::class, 'overview');
|
||||
|
||||
return $this->success($this->merchantService->overview((int) $data['id']));
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询商户下拉选项。
|
||||
*/
|
||||
public function options(Request $request): Response
|
||||
{
|
||||
return $this->success($this->merchantService->enabledOptions());
|
||||
}
|
||||
|
||||
/**
|
||||
* 远程查询商户选择项。
|
||||
*/
|
||||
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->merchantService->searchOptions($request->all(), $page, $pageSize));
|
||||
}
|
||||
}
|
||||
|
||||
118
app/http/admin/controller/merchant/MerchantGroupController.php
Normal file
118
app/http/admin/controller/merchant/MerchantGroupController.php
Normal file
@@ -0,0 +1,118 @@
|
||||
<?php
|
||||
|
||||
namespace app\http\admin\controller\merchant;
|
||||
|
||||
use app\common\base\BaseController;
|
||||
use app\http\admin\validation\MerchantGroupValidator;
|
||||
use app\service\merchant\group\MerchantGroupService;
|
||||
use support\Request;
|
||||
use support\Response;
|
||||
|
||||
/**
|
||||
* 商户分组管理控制器。
|
||||
*
|
||||
* 负责商户分组的列表、详情、新增、修改和删除。
|
||||
*/
|
||||
class MerchantGroupController extends BaseController
|
||||
{
|
||||
/**
|
||||
* 构造函数,注入商户分组服务。
|
||||
*/
|
||||
public function __construct(
|
||||
protected MerchantGroupService $merchantGroupService
|
||||
) {
|
||||
}
|
||||
|
||||
/**
|
||||
* GET /admin/merchant-groups
|
||||
*
|
||||
* 查询商户分组列表。
|
||||
*/
|
||||
public function index(Request $request): Response
|
||||
{
|
||||
$data = $this->validated($request->all(), MerchantGroupValidator::class, 'index');
|
||||
|
||||
return $this->page(
|
||||
$this->merchantGroupService->paginate(
|
||||
$data,
|
||||
(int) ($data['page'] ?? 1),
|
||||
(int) ($data['page_size'] ?? 10)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* GET /admin/merchant-groups/{id}
|
||||
*
|
||||
* 查询商户分组详情。
|
||||
*/
|
||||
public function show(Request $request, string $id): Response
|
||||
{
|
||||
$data = $this->validated(['id' => (int) $id], MerchantGroupValidator::class, 'show');
|
||||
$merchantGroup = $this->merchantGroupService->findById((int) $data['id']);
|
||||
|
||||
if (!$merchantGroup) {
|
||||
return $this->fail('商户分组不存在', 404);
|
||||
}
|
||||
|
||||
return $this->success($merchantGroup);
|
||||
}
|
||||
|
||||
/**
|
||||
* POST /admin/merchant-groups
|
||||
*
|
||||
* 新增商户分组。
|
||||
*/
|
||||
public function store(Request $request): Response
|
||||
{
|
||||
$data = $this->validated($request->all(), MerchantGroupValidator::class, 'store');
|
||||
|
||||
return $this->success($this->merchantGroupService->create($data));
|
||||
}
|
||||
|
||||
/**
|
||||
* PUT /admin/merchant-groups/{id}
|
||||
*
|
||||
* 修改商户分组。
|
||||
*/
|
||||
public function update(Request $request, string $id): Response
|
||||
{
|
||||
$data = $this->validated(
|
||||
array_merge($request->all(), ['id' => (int) $id]),
|
||||
MerchantGroupValidator::class,
|
||||
'update'
|
||||
);
|
||||
|
||||
$merchantGroup = $this->merchantGroupService->update((int) $data['id'], $data);
|
||||
if (!$merchantGroup) {
|
||||
return $this->fail('商户分组不存在', 404);
|
||||
}
|
||||
|
||||
return $this->success($merchantGroup);
|
||||
}
|
||||
|
||||
/**
|
||||
* DELETE /admin/merchant-groups/{id}
|
||||
*
|
||||
* 删除商户分组。
|
||||
*/
|
||||
public function destroy(Request $request, string $id): Response
|
||||
{
|
||||
$data = $this->validated(['id' => (int) $id], MerchantGroupValidator::class, 'destroy');
|
||||
|
||||
if (!$this->merchantGroupService->delete((int) $data['id'])) {
|
||||
return $this->fail('商户分组不存在', 404);
|
||||
}
|
||||
|
||||
return $this->success(true);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询商户分组下拉选项。
|
||||
*/
|
||||
public function options(Request $request): Response
|
||||
{
|
||||
return $this->success($this->merchantGroupService->enabledOptions());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,66 @@
|
||||
<?php
|
||||
|
||||
namespace app\http\admin\controller\merchant;
|
||||
|
||||
use app\common\base\BaseController;
|
||||
use app\http\admin\validation\MerchantPolicyValidator;
|
||||
use app\service\merchant\policy\MerchantPolicyService;
|
||||
use support\Request;
|
||||
use support\Response;
|
||||
|
||||
/**
|
||||
* 商户策略控制器。
|
||||
*/
|
||||
class MerchantPolicyController extends BaseController
|
||||
{
|
||||
public function __construct(
|
||||
protected MerchantPolicyService $merchantPolicyService
|
||||
) {
|
||||
}
|
||||
|
||||
public function index(Request $request): Response
|
||||
{
|
||||
$data = $this->validated($request->all(), MerchantPolicyValidator::class, 'index');
|
||||
|
||||
return $this->page(
|
||||
$this->merchantPolicyService->paginate(
|
||||
$data,
|
||||
(int) ($data['page'] ?? 1),
|
||||
(int) ($data['page_size'] ?? 10)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
public function show(Request $request, string $merchantId): Response
|
||||
{
|
||||
$data = $this->validated(['merchant_id' => (int) $merchantId], MerchantPolicyValidator::class, 'show');
|
||||
|
||||
return $this->success($this->merchantPolicyService->findByMerchantId((int) $data['merchant_id']));
|
||||
}
|
||||
|
||||
public function store(Request $request): Response
|
||||
{
|
||||
$data = $this->validated($request->all(), MerchantPolicyValidator::class, 'store');
|
||||
|
||||
return $this->success($this->merchantPolicyService->saveByMerchantId((int) $data['merchant_id'], $data));
|
||||
}
|
||||
|
||||
public function update(Request $request, string $merchantId): Response
|
||||
{
|
||||
$data = $this->validated(
|
||||
array_merge($request->all(), ['merchant_id' => (int) $merchantId]),
|
||||
MerchantPolicyValidator::class,
|
||||
'update'
|
||||
);
|
||||
|
||||
return $this->success($this->merchantPolicyService->saveByMerchantId((int) $data['merchant_id'], $data));
|
||||
}
|
||||
|
||||
public function destroy(Request $request, string $merchantId): Response
|
||||
{
|
||||
$data = $this->validated(['merchant_id' => (int) $merchantId], MerchantPolicyValidator::class, 'show');
|
||||
|
||||
return $this->success($this->merchantPolicyService->deleteByMerchantId((int) $data['merchant_id']));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user