1.新增商城参数配置菜单-管理兑换比例

This commit is contained in:
2026-05-06 15:21:59 +08:00
parent c2c2baeaec
commit ec499dce0f
31 changed files with 577 additions and 34 deletions

View File

@@ -0,0 +1,58 @@
<?php
declare(strict_types=1);
namespace app\common\library;
use app\common\model\MallConfig;
/**
* PlayX 与积分商城相关的比例配置:优先读 mall_config无表记录时回退 .env
*/
final class MallPlayxRatios
{
private static ?array $cache = null;
/**
* @return array{return_ratio: float, unlock_ratio: float, points_to_cash_ratio: float}
*/
public static function get(): array
{
if (self::$cache !== null) {
return self::$cache;
}
$row = MallConfig::order('id', 'asc')->find();
if ($row) {
self::$cache = [
'return_ratio' => self::toFloat($row->return_ratio),
'unlock_ratio' => self::toFloat($row->unlock_ratio),
'points_to_cash_ratio' => self::toFloat($row->points_to_cash_ratio),
];
return self::$cache;
}
self::$cache = [
'return_ratio' => floatval(env('PLAYX_RETURN_RATIO', '0.1')),
'unlock_ratio' => floatval(env('PLAYX_UNLOCK_RATIO', '0.1')),
'points_to_cash_ratio' => floatval(env('PLAYX_POINTS_TO_CASH_RATIO', '0.1')),
];
return self::$cache;
}
public static function forget(): void
{
self::$cache = null;
}
private static function toFloat(mixed $v): float
{
if (is_numeric($v)) {
return floatval($v);
}
return 0.0;
}
}