feat: 增强代理和玩家管理功能
- 在多个控制器中更新权限检查逻辑,确保管理员能够更灵活地管理代理和玩家。 - 在 AdminPlayerStoreController 中引入对玩家创建能力的验证,确保只有具备相应权限的管理员能够创建玩家。 - 更新请求验证逻辑,新增 credit_limit、rebate_rate 和 extra_rebate_rate 字段,以支持更细粒度的玩家管理。 - 在 AgentNodeProfileController 中添加对父代理能力授予的验证,确保子代理的权限在父代理范围内。 - 引入 AgentProfileFieldRules 以简化代理资料更新请求的规则定义,提升代码复用性。
This commit is contained in:
52
app/Support/CreditAmountScale.php
Normal file
52
app/Support/CreditAmountScale.php
Normal file
@@ -0,0 +1,52 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Support;
|
||||
|
||||
use App\Models\Currency;
|
||||
use App\Services\LotterySettings;
|
||||
|
||||
/**
|
||||
* 信用占成盘额度(代理/玩家授信、已用)在库内按「主货币整数」存储;
|
||||
* 彩票下注、钱包 API 使用最小货币单位(minor)。本类负责二者换算。
|
||||
*/
|
||||
final class CreditAmountScale
|
||||
{
|
||||
public static function minorUnitFactor(string $currencyCode): int
|
||||
{
|
||||
$code = strtoupper(trim($currencyCode));
|
||||
if ($code === '') {
|
||||
return (int) max(1, 10 ** LotterySettings::currencyDisplayDecimals());
|
||||
}
|
||||
|
||||
$currency = Currency::query()->where('code', $code)->first();
|
||||
$decimals = $currency !== null
|
||||
? (int) $currency->decimal_places
|
||||
: LotterySettings::currencyDisplayDecimals();
|
||||
|
||||
return (int) max(1, 10 ** max(0, min(12, $decimals)));
|
||||
}
|
||||
|
||||
public static function majorToMinor(int $major, string $currencyCode): int
|
||||
{
|
||||
$major = max(0, $major);
|
||||
|
||||
return $major * self::minorUnitFactor($currencyCode);
|
||||
}
|
||||
|
||||
/** 最小单位 → 主货币整数(四舍五入)。 */
|
||||
public static function minorToMajor(int $minor, string $currencyCode): int
|
||||
{
|
||||
$factor = self::minorUnitFactor($currencyCode);
|
||||
if ($factor <= 1) {
|
||||
return $minor;
|
||||
}
|
||||
|
||||
if ($minor >= 0) {
|
||||
return intdiv($minor + intdiv($factor, 2), $factor);
|
||||
}
|
||||
|
||||
return -intdiv(-$minor + intdiv($factor, 2), $factor);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user