deploy: auto commit repo-root changes 2026-07-05 12:03:49
This commit is contained in:
@@ -0,0 +1,44 @@
|
||||
<?php
|
||||
|
||||
namespace app\common\service\ai;
|
||||
|
||||
use app\common\model\user\User;
|
||||
|
||||
class AiQuotaService
|
||||
{
|
||||
public const DAILY_FREE_COUNT = 3;
|
||||
public const VIP_REMAIN_COUNT = 999;
|
||||
|
||||
public static function isVip(User $user): bool
|
||||
{
|
||||
return (int) $user->getData('is_vip') === 1 && (int) $user->getData('vip_expire_time') > time();
|
||||
}
|
||||
|
||||
public static function resetDailyIfNeeded(User $user): int
|
||||
{
|
||||
$today = date('Y-m-d');
|
||||
if ($user->getData('ai_free_date') !== $today) {
|
||||
$user->save([
|
||||
'ai_free_count' => self::DAILY_FREE_COUNT,
|
||||
'ai_free_date' => $today,
|
||||
]);
|
||||
return self::DAILY_FREE_COUNT;
|
||||
}
|
||||
|
||||
return max(0, (int) $user->getData('ai_free_count'));
|
||||
}
|
||||
|
||||
public static function getRemainCount(int $userId): int
|
||||
{
|
||||
$user = User::findOrEmpty($userId);
|
||||
if ($user->isEmpty()) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (self::isVip($user)) {
|
||||
return self::VIP_REMAIN_COUNT;
|
||||
}
|
||||
|
||||
return self::resetDailyIfNeeded($user);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user