deploy: auto commit repo-root changes 2026-07-05 12:03:49

This commit is contained in:
hajimi
2026-07-05 12:03:49 +08:00
parent 074aa7ab3e
commit 1954948445
107 changed files with 161 additions and 125 deletions
@@ -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);
}
}