refactor(member, auth): streamline product info retrieval and enhance dashboard statistics
- Updated `getProductInfo` method in `Member` model to use a unified model for fetching product data. - Refactored `logLogin` method to utilize `MemberLoginLog` for logging login attempts. - Introduced `getDashboardStats` method in `AuthService` to gather user-specific statistics, including remaining quotas and counts of authorized accounts, published tasks, and works. - Added new database configuration for Douyin business statistics.
This commit is contained in:
@@ -4,6 +4,9 @@ declare(strict_types=1);
|
||||
namespace app\api\service;
|
||||
|
||||
use app\api\common\Jwt;
|
||||
use app\api\model\DyVideoCron;
|
||||
use app\api\model\DyVideoUser;
|
||||
use app\api\model\DysVideoLog;
|
||||
use app\api\model\Member;
|
||||
|
||||
/**
|
||||
@@ -155,6 +158,7 @@ class AuthService
|
||||
|
||||
// 获取套餐信息
|
||||
$productInfo = $member->getProductInfo();
|
||||
$dashboardStats = $this->getDashboardStats($member, $productInfo);
|
||||
|
||||
return [
|
||||
'userid' => $member->userid,
|
||||
@@ -163,14 +167,66 @@ class AuthService
|
||||
'endtime' => $member->endtime,
|
||||
'formtypeid' => $member->formtypeid,
|
||||
'disabled' => $member->disabled,
|
||||
'video_num' => $member->video_num,
|
||||
'sp_num' => $member->sp_num,
|
||||
'product' => $productInfo ? [
|
||||
'v_type' => $productInfo['v_type'] ?? null,
|
||||
'nameu' => $productInfo['nameu'] ?? '',
|
||||
'video_num' => $productInfo['video_num'] ?? 0,
|
||||
'account_num' => $productInfo['account_num'] ?? 0,
|
||||
] : null,
|
||||
'stats' => $dashboardStats,
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取首页统计数据。
|
||||
*
|
||||
* 此处按 acgpmw `dyai/controller/index.php::right()` 的首页语义对齐:
|
||||
* - 账户剩余条数:优先展示用户余额 `member.video_num`
|
||||
* - 授权账号:统计 `dy_video_user`
|
||||
* - 发布任务:统计 `dy_video_cron`
|
||||
* - 发布作品:统计抖音日志分表 `dys_video_log_{userid % 1000}`
|
||||
*
|
||||
* 查询失败时返回 null,避免前端把异常误展示为 0。
|
||||
*
|
||||
* @param Member $member 当前登录用户
|
||||
* @param array|null $productInfo 当前套餐信息
|
||||
* @return array
|
||||
*/
|
||||
private function getDashboardStats(Member $member, ?array $productInfo = null): array
|
||||
{
|
||||
$isUnlimitedQuota = $productInfo && (int) ($productInfo['video_num'] ?? 0) < 0;
|
||||
|
||||
$stats = [
|
||||
'remaining_quota' => $isUnlimitedQuota ? null : (int) ($member->video_num ?? 0),
|
||||
'remaining_quota_unlimited' => $isUnlimitedQuota,
|
||||
'published_works_count' => null,
|
||||
'authorized_account_count' => null,
|
||||
'published_task_count' => null,
|
||||
];
|
||||
|
||||
try {
|
||||
$stats['authorized_account_count'] = DyVideoUser::countActiveByUserId((int) $member->userid);
|
||||
} catch (\Throwable $exception) {
|
||||
// 统计接口需要尽量稳健,单项查询失败时不阻断登录信息返回。
|
||||
}
|
||||
|
||||
try {
|
||||
$stats['published_task_count'] = DyVideoCron::countActiveByUserId((int) $member->userid);
|
||||
} catch (\Throwable $exception) {
|
||||
// 这里与 acgpmw 一样只排除 status=3 的任务,其余状态均计入首页统计。
|
||||
}
|
||||
|
||||
try {
|
||||
$stats['published_works_count'] = DysVideoLog::countPublishedByUserId((int) $member->userid);
|
||||
} catch (\Throwable $exception) {
|
||||
// 发布作品日志使用分表存储,查询失败时前端按“待接入”兜底展示。
|
||||
}
|
||||
|
||||
return $stats;
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改密码
|
||||
* @param int $userid
|
||||
|
||||
Reference in New Issue
Block a user