1.优化中奖事件统一使用bet.win订阅中奖消息

This commit is contained in:
2026-05-26 15:36:22 +08:00
parent d8d03662ed
commit 38dec9d7a2
2 changed files with 40 additions and 3 deletions

View File

@@ -17,10 +17,12 @@ final class StreakWinReward
/** @var list<array{streak: int, odds_factor: int, is_jackpot: bool}>|null */
private static ?array $cache = null;
private static ?string $cacheConfigValue = null;
public static function clearCache(): void
{
self::$cache = null;
self::$cacheConfigValue = null;
}
/**
@@ -97,11 +99,16 @@ final class StreakWinReward
*/
public static function loadRows(): array
{
if (self::$cache !== null) {
$row = GameHotDataRedis::gameConfigRow(self::CONFIG_KEY);
$rawValue = $row['config_value'] ?? null;
$normalizedRaw = is_string($rawValue) ? trim($rawValue) : (is_numeric($rawValue) ? (string) $rawValue : '');
if (self::$cache !== null && self::$cacheConfigValue === $normalizedRaw) {
return self::$cache;
}
$row = GameHotDataRedis::gameConfigRow(self::CONFIG_KEY);
self::$cache = self::parseFromConfigValue($row['config_value'] ?? null);
self::$cache = self::parseFromConfigValue($normalizedRaw);
self::$cacheConfigValue = $normalizedRaw;
return self::$cache;
}

View File

@@ -5,6 +5,7 @@ declare(strict_types=1);
namespace app\common\service;
use app\common\library\game\StreakWinReward;
use support\Log;
use support\think\Db;
use Throwable;
@@ -191,6 +192,35 @@ final class GameBetSettleService
]);
}
// 兜底若已判定本期中奖is_win=true但聚合中奖事件意外缺失补一条 bet.win保证客户端可感知中奖。
foreach ($userOutcome as $userId => $info) {
$hadWin = (bool) ($info['had_win'] ?? false);
if (!$hadWin || isset($winByUser[$userId])) {
continue;
}
$agg = $aggregateByUser[$userId] ?? null;
if (!is_array($agg) || bccomp((string) ($agg['total_win'] ?? '0.00'), '0', 2) <= 0) {
continue;
}
$isJackpotTier = isset($jackpotNotify[$userId]);
$winByUser[$userId] = [
'user_id' => $userId,
'period_id' => $recordId,
'period_no' => (string) ($agg['period_no'] ?? ''),
'result_number' => $resultNumber,
'total_win' => (string) ($agg['total_win'] ?? '0.00'),
'balance_after' => (string) ($agg['balance_after'] ?? '0'),
'is_jackpot' => $isJackpotTier,
'bets' => [],
];
Log::warning('bet.win fallback emitted for settled winner', [
'user_id' => $userId,
'period_id' => $recordId,
'period_no' => (string) ($agg['period_no'] ?? ''),
'is_jackpot' => $isJackpotTier,
]);
}
$jackpotHits = [];
$hitUserIds = [];
foreach ($jackpotNotify as $uid => $_) {