105 lines
4.4 KiB
PHP
105 lines
4.4 KiB
PHP
<?php
|
||
|
||
declare(strict_types=1);
|
||
|
||
/**
|
||
* 诊断某一期 bet.win / jackpot.hit 标记与推送条件:
|
||
* - 输出每个已结算中奖用户的:user_id / bet_id / streak_at_bet / 档位 / odds_factor / win_amount / is_jackpot
|
||
* - 输出 jackpot 审核阈值(若配置)与 payout_pending_review
|
||
*
|
||
* 用法:
|
||
* php scripts/debug_period_win_flags.php --period-id=77689
|
||
* php scripts/debug_period_win_flags.php --period-no=20260528-171443-3ebcbf2e
|
||
*/
|
||
|
||
require_once __DIR__ . '/../vendor/autoload.php';
|
||
require_once __DIR__ . '/../support/bootstrap.php';
|
||
|
||
use app\common\library\game\StreakWinReward;
|
||
use app\common\service\GameBetSettleService;
|
||
use support\think\Db;
|
||
|
||
$opts = getopt('', ['period-id:', 'period-no:']);
|
||
$periodId = isset($opts['period-id']) ? (int) $opts['period-id'] : 0;
|
||
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;
|
||
if ($periodId <= 0) {
|
||
// 兜底:部分环境 game_record.period_no 与 bet_order.period_no 不一致(或 game_record 未落库),从注单反查 period_id
|
||
$pid2 = Db::name('bet_order')->where('period_no', $periodNo)->value('period_id');
|
||
$periodId = is_numeric((string) $pid2) ? (int) $pid2 : 0;
|
||
}
|
||
echo "period_no={$periodNo} => period_id={$periodId}" . PHP_EOL;
|
||
}
|
||
}
|
||
if ($periodId <= 0) {
|
||
fwrite(STDERR, "请指定 --period-id 或 --period-no\n");
|
||
exit(1);
|
||
}
|
||
|
||
$record = Db::name('game_record')->where('id', $periodId)->find();
|
||
if (!is_array($record)) {
|
||
fwrite(STDERR, "对局不存在: period_id={$periodId}\n");
|
||
exit(1);
|
||
}
|
||
$resultNumber = filter_var($record['result_number'] ?? 0, FILTER_VALIDATE_INT);
|
||
if ($resultNumber === false || $resultNumber < 1) {
|
||
fwrite(STDERR, "对局尚未开奖(result_number 无效),无法诊断\n");
|
||
exit(1);
|
||
}
|
||
$periodNo = is_string($record['period_no'] ?? null) ? (string) $record['period_no'] : '';
|
||
|
||
echo "period_id={$periodId} period_no={$periodNo} result_number={$resultNumber}" . PHP_EOL;
|
||
|
||
// 注意:这里只输出标记相关信息,不会触发任何写库/推送
|
||
$rows = Db::name('bet_order')
|
||
->where('period_id', $periodId)
|
||
->whereIn('status', [GameBetSettleService::PLAY_STATUS_SETTLED, GameBetSettleService::PLAY_STATUS_PENDING_REVIEW])
|
||
->field(['id', 'user_id', 'streak_at_bet', 'total_amount', 'win_amount', 'status'])
|
||
->order('id', 'asc')
|
||
->select()
|
||
->toArray();
|
||
|
||
if ($rows === []) {
|
||
echo "no settled orders\n";
|
||
exit(0);
|
||
}
|
||
|
||
echo "streak_win_reward rows (level=1..10):" . PHP_EOL;
|
||
foreach (StreakWinReward::loadRows() as $r) {
|
||
$st = (int) ($r['streak'] ?? 0);
|
||
$od = (int) ($r['odds_factor'] ?? 1);
|
||
$jk = !empty($r['is_jackpot']) ? 1 : 0;
|
||
echo "- level={$st} odds_factor={$od} is_jackpot={$jk}" . PHP_EOL;
|
||
}
|
||
|
||
echo PHP_EOL . "orders:" . PHP_EOL;
|
||
$anyJackpot = false;
|
||
foreach ($rows as $row) {
|
||
$betId = (int) ($row['id'] ?? 0);
|
||
$uid = (int) ($row['user_id'] ?? 0);
|
||
$streakAtBet = (int) ($row['streak_at_bet'] ?? 0);
|
||
$win = is_string($row['win_amount'] ?? null) ? (string) $row['win_amount'] : (is_numeric($row['win_amount'] ?? null) ? (string) $row['win_amount'] : '0.00');
|
||
$winNorm = bcadd($win, '0', 2);
|
||
$level = StreakWinReward::levelFromStreakAtBet($streakAtBet);
|
||
$odds = StreakWinReward::totalOddsMultiplierForStreakAtBet($streakAtBet);
|
||
$isJackpotByStreak = StreakWinReward::isJackpotForStreakAtBet($streakAtBet);
|
||
$needReview = ((int) ($row['status'] ?? 0)) === GameBetSettleService::PLAY_STATUS_PENDING_REVIEW;
|
||
$flags = (new ReflectionClass(GameBetSettleService::class))->getMethod('betWinJackpotFlagsForOrder');
|
||
$flags->setAccessible(true);
|
||
/** @var array{is_jackpot: bool, payout_pending_review: bool} $computed */
|
||
$computed = $flags->invoke(null, $row, $winNorm, $needReview);
|
||
$anyJackpot = $anyJackpot || !empty($computed['is_jackpot']);
|
||
|
||
echo "- bet_id={$betId} user_id={$uid} streak_at_bet={$streakAtBet} level={$level} odds_factor={$odds} win_amount={$winNorm}"
|
||
. " is_jackpot_by_streak=" . ($isJackpotByStreak ? '1' : '0')
|
||
. " payout_pending_review=" . (!empty($computed['payout_pending_review']) ? '1' : '0')
|
||
. " is_jackpot=" . (!empty($computed['is_jackpot']) ? '1' : '0')
|
||
. PHP_EOL;
|
||
}
|
||
|
||
echo PHP_EOL . "summary: any_jackpot=" . ($anyJackpot ? '1' : '0') . PHP_EOL;
|
||
|