1.优化后台测试推送功能页面

2.优化开奖和实时对局页面
This commit is contained in:
2026-04-18 17:16:13 +08:00
parent 5c07967bf9
commit c184fa8a46
14 changed files with 582 additions and 78 deletions

View File

@@ -33,6 +33,9 @@ final class GameBetSettleService
->select()
->toArray();
/** @var array<int, array{period_no: string, total_win: string, balance_after: string, orders: list<array{order_no: string, win_amount: string, hit: bool}>}> */
$aggregateByUser = [];
foreach ($bets as $bet) {
$betId = (int) ($bet['id'] ?? 0);
if ($betId <= 0) {
@@ -59,11 +62,62 @@ final class GameBetSettleService
// 结算刚刚成功status 1 → 2把本单下注总额 1:1 累加到用户打码量
self::creditUserBetFlow($bet, $now);
if (bccomp($win, '0', 4) <= 0) {
$userId = (int) ($bet['user_id'] ?? 0);
if ($userId <= 0) {
continue;
}
self::creditUserPayout($bet, $betId, $win, $now);
$balanceAfter = (string) (Db::name('user')->where('id', $userId)->value('coin') ?? '0');
if (bccomp($win, '0', 4) > 0) {
$paid = self::creditUserPayout($bet, $betId, $win, $now);
if ($paid !== null) {
$balanceAfter = $paid;
}
}
$periodNo = (string) ($bet['period_no'] ?? '');
if (!isset($aggregateByUser[$userId])) {
$aggregateByUser[$userId] = [
'period_no' => $periodNo,
'total_win' => '0.0000',
'balance_after' => $balanceAfter,
'orders' => [],
];
}
$aggregateByUser[$userId]['total_win'] = bcadd($aggregateByUser[$userId]['total_win'], $win, 4);
$aggregateByUser[$userId]['balance_after'] = $balanceAfter;
$aggregateByUser[$userId]['orders'][] = [
'order_no' => (string) $betId,
'win_amount' => $win,
'hit' => bccomp($win, '0', 4) > 0,
];
}
foreach ($aggregateByUser as $userId => $agg) {
$hitOrderCount = 0;
foreach ($agg['orders'] as $o) {
if (($o['hit'] ?? false) === true) {
$hitOrderCount++;
}
}
UserPushService::publish((int) $userId, UserPushService::EVT_BET_SETTLED, [
'period_no' => $agg['period_no'],
'result_number' => $resultNumber,
'total_win_amount' => $agg['total_win'],
'order_count' => count($agg['orders']),
'hit_order_count' => $hitOrderCount,
'balance_after' => $agg['balance_after'],
]);
if (bccomp($agg['total_win'], '0', 4) > 0) {
UserPushService::publish((int) $userId, UserPushService::EVT_WALLET_CHANGED, [
'reason' => 'payout',
'ref_type' => 'game_period',
'ref_id' => (string) $recordId,
'delta' => $agg['total_win'],
'balance_after' => $agg['balance_after'],
]);
}
}
}
@@ -161,21 +215,26 @@ final class GameBetSettleService
]);
}
private static function creditUserPayout(array $bet, int $betId, string $winAmount, int $now): void
/**
* @return string|null 派彩后余额;已幂等入账过时返回当前余额;失败或未执行派彩返回 null
*/
private static function creditUserPayout(array $bet, int $betId, string $winAmount, int $now): ?string
{
$userId = (int) ($bet['user_id'] ?? 0);
if ($userId <= 0) {
return;
return null;
}
$idem = 'payout_bet_' . $betId;
if (Db::name('user_wallet_record')->where('idempotency_key', $idem)->value('id')) {
return;
$coin = Db::name('user')->where('id', $userId)->value('coin');
return (string) ($coin ?? '0');
}
$user = Db::name('user')->where('id', $userId)->find();
if (!$user) {
return;
return null;
}
$before = (string) ($user['coin'] ?? '0');
@@ -201,5 +260,7 @@ final class GameBetSettleService
'coin' => $after,
'update_time' => $now,
]);
return $after;
}
}