be58aac7e7
- 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.
75 lines
1.9 KiB
PHP
75 lines
1.9 KiB
PHP
<?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);
|
||
}
|
||
}
|