Files
mini_tp/app/api/model/DysVideoLog.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

75 lines
1.9 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\db\Query;
/**
* 抖音发布日志模型(对应分表 dys_video_log_{userid % 1000}
*
* 该表在 douying 库中按用户取模分表,首页“发布作品”统计需要按原系统规则动态定位表名。
*/
class DysVideoLog extends Model
{
protected $connection = 'dbdouying';
// 仅作为默认占位,真正查询时会按用户ID动态切换分表名。
protected $name = 'dys_video_log_0';
protected $pk = 'id';
protected $autoWriteTimestamp = false;
/**
* 统计当前用户已发布作品数量。
*
* 此处按 acgpmw 首页逻辑对齐,仅统计 status<=1 的发布记录。
*
* @param int $userid 用户ID
* @return int
*/
public static function countPublishedByUserId(int $userid): int
{
$tableName = self::resolveTableName($userid);
return (int) (new self())
->db()
->name($tableName)
->where('userid', $userid)
->where('status', '<=', 1)
->count();
}
/**
* 构建当前用户的视频作品基础查询。
*
* 作品日志按 `dys_video_log_{userid % 1000}` 分表存储,
* 这里统一返回已定位分表且已限定用户范围的查询对象。
*
* @param int $userid 用户ID
* @return Query
*/
public static function buildUserQuery(int $userid): Query
{
$tableName = self::resolveTableName($userid);
return (new self())
->db()
->name($tableName)
->where('userid', $userid);
}
/**
* 根据用户ID计算分表名。
*
* @param int $userid 用户ID
* @return string
*/
private static function resolveTableName(int $userid): string
{
return sprintf('dys_video_log_%d', $userid % 1000);
}
}