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

This commit is contained in:
2026-05-26 19:01:28 +08:00
parent 98b2696f89
commit 6d3711e1db
4 changed files with 208 additions and 0 deletions

View File

@@ -0,0 +1,79 @@
<?php
declare(strict_types=1);
require_once __DIR__ . '/../vendor/autoload.php';
require_once __DIR__ . '/../support/bootstrap.php';
use app\common\service\GameBetSettleService;
use support\Redis;
use support\think\Db;
$playId = (int) ($argv[1] ?? 1372);
$row = Db::name('game_play_record')->where('id', $playId)->find();
if (!is_array($row)) {
$row = Db::name('bet_order')->where('id', $playId)->find();
}
if (!is_array($row)) {
fwrite(STDERR, "play record not found: {$playId}\n");
exit(1);
}
$periodId = (int) ($row['period_id'] ?? 0);
$periodNo = (string) ($row['period_no'] ?? '');
$userId = (int) ($row['user_id'] ?? 0);
$status = (int) ($row['status'] ?? 0);
$winAmount = (string) ($row['win_amount'] ?? '0');
echo "=== play_record id={$playId} ===\n";
echo "period_id={$periodId} period_no={$periodNo}\n";
echo "user_id={$userId} status={$status} win_amount={$winAmount}\n";
echo "streak_at_bet=" . ($row['streak_at_bet'] ?? '') . "\n";
$user = Db::name('user')->where('id', $userId)->field('id,username,phone')->find();
if (is_array($user)) {
echo "user: id={$user['id']} username={$user['username']} phone={$user['phone']}\n";
}
$gr = Db::name('game_record')->where('id', $periodId)->find();
if (is_array($gr)) {
echo "game_record: status={$gr['status']} result_number={$gr['result_number']} period_start_at={$gr['period_start_at']}\n";
}
$settleKey = 'dfw:v1:settle:notify:' . $periodId;
$betWinKey = 'dfw:v1:ws:betwin:' . $periodId . ':' . $userId;
echo "\n=== Redis dedup keys ===\n";
try {
echo "settle_notify={$settleKey} => " . var_export(Redis::get($settleKey), true) . "\n";
echo "bet_win={$betWinKey} => " . var_export(Redis::get($betWinKey), true) . "\n";
} catch (Throwable $e) {
echo 'redis err: ' . $e->getMessage() . "\n";
}
$queueLen = 0;
try {
$queueLen = (int) Redis::lLen('dfw:v1:ws:event:queue');
} catch (Throwable $e) {
}
echo "ws queue length={$queueLen}\n";
$resultNumber = is_array($gr) ? (int) ($gr['result_number'] ?? 0) : 0;
$payloads = GameBetSettleService::buildBetWinPayloadsFromSettledOrders($periodId, $resultNumber);
echo "\n=== buildBetWinPayloadsFromSettledOrders ===\n";
echo 'winner_count=' . count($payloads) . "\n";
foreach ($payloads as $p) {
echo json_encode($p, JSON_UNESCAPED_UNICODE) . "\n";
}
$allWinners = Db::name('bet_order')
->where('period_id', $periodId)
->whereIn('status', [2, 5])
->whereRaw('CAST(win_amount AS DECIMAL(20,2)) > 0')
->field('id,user_id,win_amount,status,streak_at_bet')
->select()
->toArray();
echo "\n=== all winning orders in period ===\n";
foreach ($allWinners as $w) {
echo "bet_id={$w['id']} user_id={$w['user_id']} win={$w['win_amount']} status={$w['status']} streak_at_bet={$w['streak_at_bet']}\n";
}