Files
mini_tp/app/api/controller/v1/Platform.php
T
nepiedg c909ebdf88 feat(platform): add endpoint to retrieve platform accounts for a user
- Introduced `getPlatformAccountsByUserId` method in `DyVideoUser` model to fetch active platform accounts for a specified user.
- Added new API route for accessing platform accounts under `v1/platform/accounts`, requiring user authentication.
2026-04-02 07:39:37 +00:00

67 lines
1.9 KiB
PHP

<?php
declare(strict_types=1);
namespace app\api\controller\v1;
use app\api\common\Response;
use app\api\controller\BaseController;
use app\api\service\PlatformService;
use think\App;
/**
* 平台账号管理控制器。
*
* 本控制器仅提供小程序“平台账号管理”所需的最基础只读接口,
* 关键字段和状态含义按 acgpmw `platform.php` 列表逻辑对齐。
*/
class Platform extends BaseController
{
protected PlatformService $platformService;
public function __construct(App $app)
{
parent::__construct($app);
$this->platformService = new PlatformService();
}
/**
* 平台账号列表。
*
* GET /api/v1/platform/accounts
*
* 请求参数:
* - `platform`:平台编号,可选;为空时返回全部平台
*
* 返回结构:
* - `filters`:当前平台筛选项
* - `summary`:当前筛选结果统计
* - `list`:账号列表,含账号授权、数据授权、异常状态
*/
public function accounts()
{
try {
$payload = $this->request->payload ?? null;
if (!$payload || empty($payload['userid'])) {
return Response::error('未登录', 401);
}
$platformInput = $this->request->get('platform');
$platform = null;
if ($platformInput !== null && $platformInput !== '' && $platformInput !== 'all') {
if (!is_numeric((string) $platformInput)) {
return Response::error('平台参数格式错误', 400);
}
$platform = (int) $platformInput;
}
$result = $this->platformService->getAccountList((int) $payload['userid'], $platform);
return Response::success($result);
} catch (\Exception $exception) {
return Response::error($exception->getMessage(), $exception->getCode() ?: 500);
}
}
}