1.ws优化bet.win订阅,修复中大奖没有推送
This commit is contained in:
84
scripts/republish_bet_win.php
Normal file
84
scripts/republish_bet_win.php
Normal file
@@ -0,0 +1,84 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* 补发 bet.win WebSocket 推送(已结算中奖但客户端未收到时使用)。
|
||||
*
|
||||
* 用法:
|
||||
* php scripts/republish_bet_win.php --period-id=123
|
||||
* php scripts/republish_bet_win.php --play-record-id=1370
|
||||
* php scripts/republish_bet_win.php --period-no=20260526-183418-c9c90ef1
|
||||
* php scripts/republish_bet_win.php --period-id=123 --force
|
||||
*/
|
||||
|
||||
require_once __DIR__ . '/../vendor/autoload.php';
|
||||
require_once __DIR__ . '/../support/bootstrap.php';
|
||||
|
||||
use app\common\service\GameBetSettleService;
|
||||
use support\Redis;
|
||||
use support\think\Db;
|
||||
|
||||
$opts = getopt('', ['period-id:', 'play-record-id:', 'period-no:', 'force']);
|
||||
$force = array_key_exists('force', $opts);
|
||||
|
||||
$periodId = isset($opts['period-id']) ? (int) $opts['period-id'] : 0;
|
||||
if (isset($opts['play-record-id'])) {
|
||||
$playId = (int) $opts['play-record-id'];
|
||||
if ($playId > 0) {
|
||||
$pid = Db::name('game_play_record')->where('id', $playId)->value('period_id');
|
||||
$periodId = is_numeric((string) $pid) ? (int) $pid : 0;
|
||||
echo "play_record_id={$playId} => period_id={$periodId}" . PHP_EOL;
|
||||
}
|
||||
}
|
||||
if ($periodId <= 0 && isset($opts['period-no'])) {
|
||||
$periodNo = trim((string) $opts['period-no']);
|
||||
if ($periodNo !== '') {
|
||||
$pid = Db::name('game_record')->where('period_no', $periodNo)->value('id');
|
||||
$periodId = is_numeric((string) $pid) ? (int) $pid : 0;
|
||||
echo "period_no={$periodNo} => period_id={$periodId}" . PHP_EOL;
|
||||
}
|
||||
}
|
||||
|
||||
if ($periodId <= 0) {
|
||||
fwrite(STDERR, "请指定 --period-id、--play-record-id 或 --period-no\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
$row = Db::name('game_record')->where('id', $periodId)->find();
|
||||
if (!is_array($row)) {
|
||||
fwrite(STDERR, "对局不存在: period_id={$periodId}\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
$resultNumber = filter_var($row['result_number'] ?? 0, FILTER_VALIDATE_INT);
|
||||
if ($resultNumber === false || $resultNumber < 1) {
|
||||
fwrite(STDERR, "对局尚未开奖,无法补发 bet.win\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
$payloads = GameBetSettleService::buildBetWinPayloadsFromSettledOrders($periodId, $resultNumber);
|
||||
if ($payloads === []) {
|
||||
echo "本期无已结算中奖注单,无需补发。\n";
|
||||
exit(0);
|
||||
}
|
||||
|
||||
if ($force) {
|
||||
foreach ($payloads as $payload) {
|
||||
$uid = (int) ($payload['user_id'] ?? 0);
|
||||
if ($uid <= 0) {
|
||||
continue;
|
||||
}
|
||||
try {
|
||||
Redis::del('dfw:v1:ws:betwin:' . $periodId . ':' . $uid);
|
||||
} catch (Throwable) {
|
||||
}
|
||||
}
|
||||
echo "已清除 dedup 键(--force)\n";
|
||||
}
|
||||
|
||||
GameBetSettleService::publishBetWinsAfterCommit($payloads, $periodId);
|
||||
echo '已补发 bet.win 用户数: ' . count($payloads) . PHP_EOL;
|
||||
foreach ($payloads as $p) {
|
||||
echo ' user_id=' . ($p['user_id'] ?? '') . ' total_win=' . ($p['total_win'] ?? '') . ' period_no=' . ($p['period_no'] ?? '') . PHP_EOL;
|
||||
}
|
||||
Reference in New Issue
Block a user