Files
webman-buildadmin/app/common/library/GameRewardConfigTemplate.php

56 lines
1.9 KiB
PHP

<?php
declare(strict_types=1);
namespace app\common\library;
/**
* 游戏奖励配置:默认模板(与 resource/game_reward_config_template.json 一致)
*/
class GameRewardConfigTemplate
{
private static ?array $cached = null;
public static function templatePath(): string
{
return dirname(__DIR__, 3) . DIRECTORY_SEPARATOR . 'resource' . DIRECTORY_SEPARATOR . 'game_reward_config_template.json';
}
/**
* @return array{tier_reward_form: string, bigwin_form: string}
*/
public static function getDefaultJsonColumns(): array
{
if (self::$cached !== null) {
return self::$cached;
}
$path = self::templatePath();
if (!is_file($path)) {
throw new \RuntimeException('game_reward_config_template.json missing: ' . $path);
}
$raw = file_get_contents($path);
if ($raw === false || trim($raw) === '') {
throw new \RuntimeException('game_reward_config_template.json read failed');
}
$decoded = json_decode($raw, true);
if (!is_array($decoded)) {
throw new \RuntimeException('game_reward_config_template.json invalid JSON');
}
$tier = $decoded['tier_reward_form'] ?? null;
$big = $decoded['bigwin_form'] ?? null;
if (!is_array($tier) || !is_array($big)) {
throw new \RuntimeException('game_reward_config_template.json missing tier_reward_form or bigwin_form');
}
$tierJson = json_encode($tier, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES);
$bigJson = json_encode($big, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES);
if (!is_string($tierJson) || !is_string($bigJson)) {
throw new \RuntimeException('game_reward_config_template encode failed');
}
self::$cached = [
'tier_reward_form' => $tierJson,
'bigwin_form' => $bigJson,
];
return self::$cached;
}
}