1.期号记录修改为纯数字

This commit is contained in:
2026-05-29 11:53:12 +08:00
parent 0aa0809ad1
commit f286fcc56f
5 changed files with 113 additions and 10 deletions

View File

@@ -5,6 +5,7 @@ declare(strict_types=1);
namespace app\api\controller;
use app\common\library\game\BetChips;
use app\common\library\game\GamePeriodNo;
use app\common\library\game\StreakWinReward;
use app\common\library\game\ZiHuaDictionary;
use app\common\model\BetOrder;
@@ -21,7 +22,7 @@ use support\Response;
class Game extends MobileBase
{
protected array $noNeedLogin = ['dictionaryList'];
protected array $noNeedLogin = ['dictionaryList', 'periodHistory'];
public function lobbyInit(Request $request): Response
{
@@ -58,7 +59,10 @@ class Game extends MobileBase
'runtime_enabled' => GameRecordService::getConfigBool(GameRecordService::KEY_AUTO_CREATE),
'period' => [
'period_id' => $periodRow ? $this->intValue($periodRow['id'] ?? 0) : 0,
'period_no' => (string) ($periodRow['period_no'] ?? ''),
'period_no' => GamePeriodNo::toDisplay(
(string) ($periodRow['period_no'] ?? ''),
$periodRow ? $this->intValue($periodRow['id'] ?? 0) : 0
),
'status' => $this->mapPeriodStatus($periodRow['status'] ?? null),
'countdown' => $countdown,
'lock_at' => $lockAt,
@@ -105,6 +109,36 @@ class Game extends MobileBase
]);
}
/**
* 获取最近开奖记录(默认最新 30 条),期号为纯数字。
*/
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;
}
if ($limit > 100) {
$limit = 100;
}
$list = GameRecord::whereNotNull('result_number')->order('id', 'desc')->limit($limit)->select();
$rows = [];
foreach ($list as $item) {
$periodId = $this->intValue($item->id ?? 0);
$rows[] = [
'period_no' => GamePeriodNo::toDisplay((string) ($item->period_no ?? ''), $periodId),
'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);
@@ -120,7 +154,10 @@ class Game extends MobileBase
return $this->mobileSuccess([
'runtime_enabled' => GameRecordService::getConfigBool(GameRecordService::KEY_AUTO_CREATE),
'period_id' => $this->intValue($periodRow['id'] ?? 0),
'period_no' => $periodRow['period_no'],
'period_no' => GamePeriodNo::toDisplay(
(string) ($periodRow['period_no'] ?? ''),
$this->intValue($periodRow['id'] ?? 0)
),
'status' => $this->mapPeriodStatus($periodRow['status'] ?? null),
'countdown' => max(0, ($startAt + 30) - $now),
'bet_close_in' => max(0, ($startAt + 20) - $now),
@@ -188,6 +225,12 @@ class Game extends MobileBase
return $this->mobileError(3001, 'Game is paused');
}
$period = GameRecord::where('period_no', $periodNo)->find();
if (!$period && ctype_digit($periodNo)) {
$periodIdLookup = filter_var($periodNo, FILTER_VALIDATE_INT);
if ($periodIdLookup !== false && $periodIdLookup > 0) {
$period = GameRecord::find($periodIdLookup);
}
}
if (!$period) {
return $this->mobileError(2002, 'Game period does not exist');
}
@@ -311,9 +354,13 @@ class Game extends MobileBase
'biz_type' => 'bet',
'changed_at' => time(),
], $userId, $streakAtBet));
$periodIdForDisplay = filter_var($period->id ?? null, FILTER_VALIDATE_INT);
if ($periodIdForDisplay === false) {
$periodIdForDisplay = 0;
}
return $this->mobileSuccess([
'order_no' => $orderNo,
'period_no' => $period->period_no,
'period_no' => GamePeriodNo::toDisplay((string) ($period->period_no ?? ''), $periodIdForDisplay),
'status' => 'accepted',
'bet_id' => $betChipId,
'single_bet_amount' => $singleAmount,
@@ -437,7 +484,7 @@ class Game extends MobileBase
}
$rows[] = [
'order_no' => (string) $item->id,
'period_no' => $item->period_no,
'period_no' => GamePeriodNo::toDisplay((string) ($item->period_no ?? ''), $periodIdValue),
'numbers' => $item->pick_numbers ?? [],
// 整笔压注金额(本笔总扣款)
'bet_amount' => $item->total_amount,