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.
This commit is contained in:
@@ -4,6 +4,7 @@ declare(strict_types=1);
|
||||
namespace app\api\model;
|
||||
|
||||
use think\Model;
|
||||
use think\Collection;
|
||||
|
||||
/**
|
||||
* 授权账号模型(对应 dy_video_user 表)
|
||||
@@ -32,4 +33,49 @@ class DyVideoUser extends Model
|
||||
->where('disabled', 0)
|
||||
->count();
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取当前用户的平台账号列表。
|
||||
*
|
||||
* 这里按 acgpmw `platform::index()` 和 `platform::get_zhanghu_list()` 的查询条件对齐:
|
||||
* - 仅返回当前用户数据
|
||||
* - 仅返回 `disabled=0` 的有效账号
|
||||
* - 排序保持 `is_endauth desc, id desc`
|
||||
*
|
||||
* @param int $userid 用户ID
|
||||
* @param int|null $platform 指定平台;为空时返回全部平台
|
||||
* @return Collection
|
||||
*/
|
||||
public static function getPlatformAccountsByUserId(int $userid, ?int $platform = null): Collection
|
||||
{
|
||||
$query = self::where('userid', $userid)
|
||||
->where('disabled', 0)
|
||||
->order(['is_endauth' => 'desc', 'id' => 'desc'])
|
||||
->field([
|
||||
'id',
|
||||
'userid',
|
||||
'platform',
|
||||
'is_lanv',
|
||||
'is_endauth',
|
||||
'aa_endauth',
|
||||
'browser',
|
||||
'is_qyh',
|
||||
'proviceid',
|
||||
'info_shouji',
|
||||
'dy_avatar',
|
||||
'dy_nickname',
|
||||
'dy_intro',
|
||||
'dy_account',
|
||||
'dy_openid',
|
||||
'dy_unique_id',
|
||||
'addtime',
|
||||
'updatetime',
|
||||
]);
|
||||
|
||||
if ($platform !== null) {
|
||||
$query->where('platform', $platform);
|
||||
}
|
||||
|
||||
return $query->select();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user