1.ws优化bet.win订阅,修复中大奖没有推送

This commit is contained in:
2026-05-27 09:47:42 +08:00
parent 4c69a8c77f
commit a7c2a29764
3 changed files with 151 additions and 16 deletions

View File

@@ -339,7 +339,15 @@ final class GameBetSettleService
'payout_pending_review' => $payoutPendingReview,
'server_time' => $now,
]), $userId);
GameWebSocketEventBus::publish(self::TOPIC_BET_WIN, $data);
$ok = GameWebSocketEventBus::publish(self::TOPIC_BET_WIN, $data);
if (!$ok) {
Log::warning('bet.win publish failed (will retry next round)', [
'period_id' => $periodId,
'user_id' => $userId,
'total_win' => $payload['total_win'] ?? '',
]);
continue;
}
if ($periodId > 0) {
self::markBetWinNotifyOnce($periodId, $userId);
}

View File

@@ -4,6 +4,7 @@ declare(strict_types=1);
namespace app\common\service;
use support\Log;
use support\Redis;
use Throwable;
@@ -17,12 +18,13 @@ final class GameWebSocketEventBus
/**
* @param array<string, mixed> $data
* @return bool 是否成功入队false 表示 Redis 不可用或参数非法,调用方应避免标记“已推送”)
*/
public static function publish(string $topic, array $data): void
public static function publish(string $topic, array $data): bool
{
$topic = trim($topic);
if ($topic === '') {
return;
return false;
}
$payload = [
'topic' => $topic,
@@ -32,11 +34,17 @@ final class GameWebSocketEventBus
];
$json = json_encode($payload, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES);
if (!is_string($json) || $json === '') {
return;
return false;
}
try {
Redis::lPush(self::KEY_QUEUE, $json);
} catch (Throwable) {
$len = Redis::lPush(self::KEY_QUEUE, $json);
return is_numeric($len) && (int) $len > 0;
} catch (Throwable $e) {
Log::warning('ws event bus publish failed', [
'topic' => $topic,
'error' => $e->getMessage(),
]);
return false;
}
}