deploy: auto commit repo-root changes 2026-07-05 12:03:49
This commit is contained in:
@@ -4,6 +4,7 @@ namespace app\common\model\ai;
|
||||
|
||||
use app\common\model\BaseModel;
|
||||
use app\common\model\user\User;
|
||||
use app\common\service\ai\AiQuotaService;
|
||||
|
||||
class AiUnlock extends BaseModel
|
||||
{
|
||||
@@ -33,7 +34,7 @@ class AiUnlock extends BaseModel
|
||||
}
|
||||
|
||||
// VIP用户不限次数
|
||||
if ($user->is_vip && $user->vip_expire_time > time()) {
|
||||
if (AiQuotaService::isVip($user)) {
|
||||
self::create([
|
||||
'user_id' => $userId,
|
||||
'match_id' => $matchId,
|
||||
@@ -41,20 +42,14 @@ class AiUnlock extends BaseModel
|
||||
return ['ok' => true, 'msg' => 'VIP解锁'];
|
||||
}
|
||||
|
||||
// 重置每日次数(跨天时)
|
||||
$today = date('Y-m-d');
|
||||
if ($user->ai_free_date !== $today) {
|
||||
$user->ai_free_count = 3;
|
||||
$user->ai_free_date = $today;
|
||||
$user->save();
|
||||
}
|
||||
$freeCount = AiQuotaService::resetDailyIfNeeded($user);
|
||||
|
||||
if ($user->ai_free_count <= 0) {
|
||||
if ($freeCount <= 0) {
|
||||
return ['ok' => false, 'msg' => '今日免费次数已用完,升级VIP可无限使用'];
|
||||
}
|
||||
|
||||
// 扣次数 + 写解锁记录
|
||||
$user->ai_free_count = $user->ai_free_count - 1;
|
||||
$user->ai_free_count = $freeCount - 1;
|
||||
$user->save();
|
||||
|
||||
self::create([
|
||||
@@ -70,18 +65,6 @@ class AiUnlock extends BaseModel
|
||||
*/
|
||||
public static function getRemainCount(int $userId): int
|
||||
{
|
||||
$user = User::findOrEmpty($userId);
|
||||
if ($user->isEmpty()) {
|
||||
return 0;
|
||||
}
|
||||
// VIP不限
|
||||
if ($user->is_vip && $user->vip_expire_time > time()) {
|
||||
return 999;
|
||||
}
|
||||
$today = date('Y-m-d');
|
||||
if ($user->ai_free_date !== $today) {
|
||||
return 3;
|
||||
}
|
||||
return max(0, (int)$user->ai_free_count);
|
||||
return AiQuotaService::getRemainCount($userId);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,6 +18,7 @@ namespace app\common\model\user;
|
||||
|
||||
use app\common\enum\user\UserEnum;
|
||||
use app\common\model\BaseModel;
|
||||
use app\common\service\ai\AiQuotaService;
|
||||
use app\common\service\FileService;
|
||||
use think\model\concern\SoftDelete;
|
||||
|
||||
@@ -204,14 +205,7 @@ class User extends BaseModel
|
||||
$isVip = false;
|
||||
}
|
||||
|
||||
// 每日免费次数重置
|
||||
$today = date('Y-m-d');
|
||||
if ($this->getData('ai_free_date') !== $today) {
|
||||
$this->save(['ai_free_count' => 3, 'ai_free_date' => $today]);
|
||||
$freeCount = 3;
|
||||
} else {
|
||||
$freeCount = (int) $this->getData('ai_free_count');
|
||||
}
|
||||
$freeCount = AiQuotaService::resetDailyIfNeeded($this);
|
||||
|
||||
// 获取等级卡片背景图
|
||||
$cardImage = '';
|
||||
|
||||
@@ -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