Files
mini_tp/app/api/model/DyVideoUser.php
T
nepiedg be58aac7e7 feat(video): add user-specific video query and filter accounts functionality
- Introduced `buildUserQuery` method in `DysVideoLog` model to create a base query for user-specific video logs.
- Added `getVideoFilterAccountsByUserId` method in `DyVideoUser` model to retrieve active accounts for a specified user.
- Updated routing to include new video work API endpoints under `v1/video-work`, requiring user authentication.
2026-04-03 03:48:25 +00:00

106 lines
2.8 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<?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();
}
/**
* 获取视频作品页筛选用的账号列表。
*
* 对齐 acgpmw `video_info::video_list()`
* - 仅返回当前用户启用中的账号
* - 返回平台与昵称,供前端拼出“平台(昵称)#Pid”样式
*
* @param int $userid 用户ID
* @return Collection
*/
public static function getVideoFilterAccountsByUserId(int $userid): Collection
{
return self::where('userid', $userid)
->where('disabled', 0)
->order(['id' => 'desc'])
->field([
'id',
'platform',
'dy_nickname',
'dy_avatar',
])
->select();
}
}