where('match_id', $matchId)->count() > 0; } /** * 解锁比赛(扣次数 + 写记录) * @return array ['ok' => bool, 'msg' => string] */ public static function unlock(int $userId, int $matchId): array { $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' => (bool) ($result['ok'] ?? false), 'msg' => (string) ($result['msg'] ?? ''), 'remain' => $result['remain'] ?? AiQuotaService::getRemainCount($userId), ]; } /** * 获取用户今日剩余次数 */ public static function getRemainCount(int $userId): int { return AiQuotaService::getRemainCount($userId); } }