c909ebdf88
- 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.
82 lines
2.1 KiB
PHP
82 lines
2.1 KiB
PHP
<?php
|
|
declare(strict_types=1);
|
|
|
|
namespace app\api\model;
|
|
|
|
use think\Model;
|
|
use think\Collection;
|
|
|
|
/**
|
|
* 授权账号模型(对应 dy_video_user 表)
|
|
*
|
|
* 首页“授权账号”卡片按 acgpmw 首页逻辑统计未禁用账号数。
|
|
*/
|
|
class DyVideoUser extends Model
|
|
{
|
|
protected $connection = 'dbmember';
|
|
|
|
protected $name = 'dy_video_user';
|
|
|
|
protected $pk = 'id';
|
|
|
|
protected $autoWriteTimestamp = false;
|
|
|
|
/**
|
|
* 统计当前用户可用的授权账号数量。
|
|
*
|
|
* @param int $userid 用户ID
|
|
* @return int
|
|
*/
|
|
public static function countActiveByUserId(int $userid): int
|
|
{
|
|
return (int) self::where('userid', $userid)
|
|
->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();
|
|
}
|
|
}
|