Some checks failed
lotterLaravel CI / test (push) Has been cancelled
- Updated AGENTS.md to clarify player interface bindings and agent account restrictions. - Improved PlayerAuthLoginController to include captcha verification for player login. - Enhanced AdminPlayerIndexController with permission checks for admin users. - Refactored AdminPlayerStoreController to enforce agent node restrictions for non-super admins. - Introduced new error codes for player authentication failures and updated related services. - Enhanced validation rules for agent profiles to include settlement cycle options. - Improved AdminCaptchaService to support separate scopes for admin and player captcha handling. - Updated various services to ensure proper credit management and settlement processes.
55 lines
1.5 KiB
PHP
55 lines
1.5 KiB
PHP
<?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);
|
||
}
|
||
|
||
/**
|
||
* 最小单位 → 主货币整数(占用授信时向上取整,与 preflight 按 major 校验一致)。
|
||
*/
|
||
public static function minorToMajor(int $minor, string $currencyCode): int
|
||
{
|
||
$factor = self::minorUnitFactor($currencyCode);
|
||
if ($factor <= 1) {
|
||
return $minor;
|
||
}
|
||
|
||
if ($minor <= 0) {
|
||
return 0;
|
||
}
|
||
|
||
return intdiv($minor + $factor - 1, $factor);
|
||
}
|
||
}
|