1.优化websocket连接
2.修复游戏实施对局显示错误
This commit is contained in:
@@ -10,7 +10,7 @@ use support\Response;
|
||||
use Webman\Http\Request as WebmanRequest;
|
||||
|
||||
/**
|
||||
* 游戏实时对局
|
||||
* Game live control.
|
||||
*/
|
||||
class Live extends Backend
|
||||
{
|
||||
@@ -40,7 +40,7 @@ class Live extends Backend
|
||||
}
|
||||
|
||||
/**
|
||||
* 后台实时对局 WebSocket 配置(管理员联调专用)。
|
||||
* WebSocket config for admin live page.
|
||||
*/
|
||||
public function wsConfig(WebmanRequest $request): Response
|
||||
{
|
||||
@@ -64,8 +64,8 @@ class Live extends Backend
|
||||
|
||||
return $this->success('', [
|
||||
'name' => 'ws.admin.live',
|
||||
'ws_url' => WebSocketConfigHelper::wsUrl(),
|
||||
'connect_tip' => '后台实时对局页将自动订阅管理员全量主题(含本局下注、候选号、开奖与派彩信息)。',
|
||||
'ws_url' => WebSocketConfigHelper::wsUrl($request),
|
||||
'connect_tip' => 'The admin live page auto-subscribes topics for status, draw result and payout events.',
|
||||
'subscribe_topics' => $topics,
|
||||
'sample_messages' => [
|
||||
'{"action":"ping"}',
|
||||
@@ -98,7 +98,7 @@ class Live extends Backend
|
||||
}
|
||||
|
||||
/**
|
||||
* 预约本期开奖号码(倒计时结束后自动开奖,不立即开奖)。
|
||||
* Schedule draw number for current period.
|
||||
*/
|
||||
public function draw(WebmanRequest $request): Response
|
||||
{
|
||||
@@ -126,7 +126,7 @@ class Live extends Backend
|
||||
}
|
||||
|
||||
/**
|
||||
* 游戏运行开关:关闭时禁止下注、派彩结束后不自动开新期,但当局仍自动开奖并结算;重新开启且无进行中局时立即创建新一期。
|
||||
* Runtime switch for game period generation and betting.
|
||||
*/
|
||||
public function runtime(WebmanRequest $request): Response
|
||||
{
|
||||
@@ -147,7 +147,7 @@ class Live extends Backend
|
||||
}
|
||||
|
||||
/**
|
||||
* 作废当前对局(下注/封盘阶段),填写原因后退款待开奖注单并关闭运行开关。
|
||||
* Void current period and refund waiting orders.
|
||||
*/
|
||||
public function voidPeriod(WebmanRequest $request): Response
|
||||
{
|
||||
|
||||
@@ -10,7 +10,7 @@ use support\Response;
|
||||
use Webman\Http\Request as WebmanRequest;
|
||||
|
||||
/**
|
||||
* WebSocket 测试:状态流(period.tick / period.opened)
|
||||
* WebSocket test for period status stream.
|
||||
*/
|
||||
class GameCurrentStatus extends Backend
|
||||
{
|
||||
@@ -35,8 +35,8 @@ class GameCurrentStatus extends Backend
|
||||
|
||||
return $this->success('', [
|
||||
'name' => 'ws.period',
|
||||
'ws_url' => WebSocketConfigHelper::wsUrl(),
|
||||
'connect_tip' => '连接成功后会自动订阅下列主题;也可在「发送消息」中手动改订阅。未订阅时不会收到业务推送。',
|
||||
'ws_url' => WebSocketConfigHelper::wsUrl($request),
|
||||
'connect_tip' => 'After connected, topics are auto-subscribed. You can also send subscribe manually.',
|
||||
'subscribe_topics' => $subscribeTopics,
|
||||
'sample_messages' => [
|
||||
'{"action":"ping"}',
|
||||
|
||||
@@ -76,7 +76,7 @@ class Account extends Frontend
|
||||
'last_bet_period_no' => $user->last_bet_period_no ?? '',
|
||||
'create_time' => $user->create_time ?? 0,
|
||||
|
||||
// 资金字段(4 位小数字符串,与 /api/wallet/balanceSummary 对齐)
|
||||
// 资金字段(4 位小数字符串,与钱包展示口径一致)
|
||||
'coin' => floatval($coinBalance),
|
||||
'coin_balance' => floatval($coinBalance),
|
||||
'frozen_balance' => 0.00,
|
||||
|
||||
@@ -18,7 +18,7 @@ use support\Response;
|
||||
|
||||
class Game extends MobileBase
|
||||
{
|
||||
protected array $noNeedLogin = ['dictionaryList', 'periodHistory'];
|
||||
protected array $noNeedLogin = ['dictionaryList'];
|
||||
|
||||
public function lobbyInit(Request $request): Response
|
||||
{
|
||||
@@ -93,28 +93,6 @@ class Game extends MobileBase
|
||||
]);
|
||||
}
|
||||
|
||||
public function periodHistory(Request $request): Response
|
||||
{
|
||||
$response = $this->initializeMobile($request);
|
||||
if ($response !== null) {
|
||||
return $response;
|
||||
}
|
||||
$limit = $this->intValue($request->input('limit', 30));
|
||||
if ($limit < 1) {
|
||||
$limit = 30;
|
||||
}
|
||||
$list = GameRecord::whereNotNull('result_number')->order('id', 'desc')->limit($limit)->select();
|
||||
$rows = [];
|
||||
foreach ($list as $item) {
|
||||
$rows[] = [
|
||||
'period_no' => $item->period_no,
|
||||
'result_number' => $item->result_number,
|
||||
'open_time' => $item->update_time,
|
||||
];
|
||||
}
|
||||
return $this->mobileSuccess(['list' => $rows]);
|
||||
}
|
||||
|
||||
public function periodCurrent(Request $request): Response
|
||||
{
|
||||
$response = $this->initializeMobile($request);
|
||||
@@ -138,14 +116,6 @@ class Game extends MobileBase
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 与前端文档对齐:/api/game/current_status
|
||||
*/
|
||||
public function currentStatus(Request $request): Response
|
||||
{
|
||||
return $this->periodCurrent($request);
|
||||
}
|
||||
|
||||
/**
|
||||
* 兼容旧路由:/api/game/betPlace
|
||||
* 新语义与 place_bet 一致:bet_amount 作为“单注金额”。
|
||||
|
||||
@@ -4,47 +4,12 @@ declare(strict_types=1);
|
||||
|
||||
namespace app\api\controller;
|
||||
|
||||
use app\common\library\finance\WithdrawFlow;
|
||||
use app\common\model\UserWalletRecord;
|
||||
use Webman\Http\Request;
|
||||
use support\Response;
|
||||
|
||||
class Wallet extends MobileBase
|
||||
{
|
||||
public function balanceSummary(Request $request): Response
|
||||
{
|
||||
$response = $this->initializeMobile($request);
|
||||
if ($response !== null) {
|
||||
return $response;
|
||||
}
|
||||
$user = $this->auth->getUser();
|
||||
$coinBalance = WithdrawFlow::amountString($user->coin ?? '0');
|
||||
$flow = WithdrawFlow::status(intval($user->id), [
|
||||
'total_deposit_coin' => $user->total_deposit_coin ?? '0',
|
||||
'total_withdraw_coin' => $user->total_withdraw_coin ?? '0',
|
||||
'bet_flow_coin' => $user->bet_flow_coin ?? '0',
|
||||
]);
|
||||
$maxWithdrawable = WithdrawFlow::maxWithdrawable($coinBalance, $flow);
|
||||
return $this->mobileSuccess([
|
||||
'coin_balance' => floatval($coinBalance),
|
||||
'frozen_balance' => 0.00,
|
||||
'withdrawable_balance' => floatval($coinBalance),
|
||||
'max_withdrawable' => floatval($maxWithdrawable),
|
||||
'total_deposit_coin' => floatval(WithdrawFlow::amountString($user->total_deposit_coin ?? '0')),
|
||||
'total_withdraw_coin' => floatval(WithdrawFlow::amountString($user->total_withdraw_coin ?? '0')),
|
||||
'bet_flow_coin' => floatval($flow['bet_flow_coin']),
|
||||
'withdraw_flow' => [
|
||||
'ratio' => floatval($flow['ratio']),
|
||||
'net_deposit' => floatval($flow['net_deposit']),
|
||||
'required_bet_flow' => floatval($flow['required_bet_flow']),
|
||||
'remaining_bet_flow' => floatval($flow['remaining_bet_flow']),
|
||||
'eligible' => $flow['eligible'],
|
||||
'max_withdraw_by_flow' => $flow['flow_unlimited'] ? null : floatval($flow['max_withdraw_by_flow']),
|
||||
'flow_unlimited' => $flow['flow_unlimited'],
|
||||
],
|
||||
]);
|
||||
}
|
||||
|
||||
public function recordList(Request $request): Response
|
||||
{
|
||||
$response = $this->initializeMobile($request);
|
||||
|
||||
@@ -4,15 +4,37 @@ declare(strict_types=1);
|
||||
|
||||
namespace app\common\library\admin;
|
||||
|
||||
use Webman\Http\Request;
|
||||
|
||||
final class WebSocketConfigHelper
|
||||
{
|
||||
public static function wsUrl(): string
|
||||
public static function wsUrl(?Request $request = null): string
|
||||
{
|
||||
$url = trim((string) env('H5_WEBSOCKET_URL', ''));
|
||||
if ($url !== '') {
|
||||
return $url;
|
||||
}
|
||||
return 'ws://127.0.0.1:3131';
|
||||
|
||||
if ($request !== null) {
|
||||
$proto = strtolower((string) $request->header('x-forwarded-proto', ''));
|
||||
if ($proto === '') {
|
||||
$proto = strtolower((string) $request->header('x-forwarded-protocol', ''));
|
||||
}
|
||||
$isHttps = $proto === 'https'
|
||||
|| strtolower((string) $request->header('x-forwarded-ssl', '')) === 'on'
|
||||
|| strtolower((string) $request->header('x-scheme', '')) === 'https';
|
||||
$scheme = $isHttps ? 'wss' : 'ws';
|
||||
|
||||
$host = trim((string) $request->header('host', ''));
|
||||
if ($host === '') {
|
||||
$host = trim((string) $request->header('x-forwarded-host', ''));
|
||||
}
|
||||
if ($host !== '') {
|
||||
return $scheme . '://' . $host . '/ws/';
|
||||
}
|
||||
}
|
||||
|
||||
return 'ws://127.0.0.1:3131/ws/';
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user