1.新增商城参数配置菜单-管理兑换比例
This commit is contained in:
58
app/common/library/MallPlayxRatios.php
Normal file
58
app/common/library/MallPlayxRatios.php
Normal 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;
|
||||
}
|
||||
}
|
||||
25
app/common/model/MallConfig.php
Normal file
25
app/common/model/MallConfig.php
Normal file
@@ -0,0 +1,25 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace app\common\model;
|
||||
|
||||
use support\think\Model;
|
||||
|
||||
/**
|
||||
* 积分商城配置(比例等)
|
||||
*/
|
||||
class MallConfig extends Model
|
||||
{
|
||||
protected string $name = 'mall_config';
|
||||
|
||||
protected bool $autoWriteTimestamp = true;
|
||||
|
||||
protected array $type = [
|
||||
'create_time' => 'integer',
|
||||
'update_time' => 'integer',
|
||||
'return_ratio' => 'float',
|
||||
'unlock_ratio' => 'float',
|
||||
'points_to_cash_ratio' => 'float',
|
||||
];
|
||||
}
|
||||
Reference in New Issue
Block a user