deploy: auto commit repo-root changes 2026-07-05 12:33:57
This commit is contained in:
@@ -3,7 +3,6 @@
|
||||
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
|
||||
@@ -13,7 +12,9 @@ class AiUnlock extends BaseModel
|
||||
*/
|
||||
public static function isUnlocked(int $userId, int $matchId): bool
|
||||
{
|
||||
return self::where('user_id', $userId)->where('match_id', $matchId)->count() > 0;
|
||||
$analysisKey = AiQuotaService::makeKey(AiQuotaService::TYPE_MATCH, $matchId);
|
||||
return AiQuotaService::hasUnlocked($userId, $analysisKey)
|
||||
|| self::where('user_id', $userId)->where('match_id', $matchId)->count() > 0;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -22,42 +23,20 @@ class AiUnlock extends BaseModel
|
||||
*/
|
||||
public static function unlock(int $userId, int $matchId): array
|
||||
{
|
||||
// 已解锁则直接返回
|
||||
if (self::isUnlocked($userId, $matchId)) {
|
||||
return ['ok' => true, 'msg' => '已解锁'];
|
||||
}
|
||||
|
||||
// 检查今日剩余次数
|
||||
$user = User::findOrEmpty($userId);
|
||||
if ($user->isEmpty()) {
|
||||
return ['ok' => false, 'msg' => '用户不存在'];
|
||||
}
|
||||
|
||||
// VIP用户不限次数
|
||||
if (AiQuotaService::isVip($user)) {
|
||||
$analysisKey = AiQuotaService::makeKey(AiQuotaService::TYPE_MATCH, $matchId);
|
||||
$result = AiQuotaService::unlock($userId, AiQuotaService::TYPE_MATCH, $analysisKey, $matchId);
|
||||
if (!empty($result['ok']) && self::where('user_id', $userId)->where('match_id', $matchId)->count() <= 0) {
|
||||
self::create([
|
||||
'user_id' => $userId,
|
||||
'match_id' => $matchId,
|
||||
]);
|
||||
return ['ok' => true, 'msg' => 'VIP解锁'];
|
||||
}
|
||||
|
||||
$freeCount = AiQuotaService::resetDailyIfNeeded($user);
|
||||
|
||||
if ($freeCount <= 0) {
|
||||
return ['ok' => false, 'msg' => '今日免费次数已用完,升级VIP可无限使用'];
|
||||
}
|
||||
|
||||
// 扣次数 + 写解锁记录
|
||||
$user->ai_free_count = $freeCount - 1;
|
||||
$user->save();
|
||||
|
||||
self::create([
|
||||
'user_id' => $userId,
|
||||
'match_id' => $matchId,
|
||||
]);
|
||||
|
||||
return ['ok' => true, 'msg' => '解锁成功', 'remain' => $user->ai_free_count];
|
||||
return [
|
||||
'ok' => (bool) ($result['ok'] ?? false),
|
||||
'msg' => (string) ($result['msg'] ?? ''),
|
||||
'remain' => $result['remain'] ?? AiQuotaService::getRemainCount($userId),
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user