miner
This commit is contained in:
@@ -30,8 +30,8 @@ final class Router
|
||||
private const OVERVIEW_WINDOW_DAYS = 15;
|
||||
private const FX_FETCH_MAX_AGE_HOURS = 3.0;
|
||||
private const BASE_OFFER_SPEEDS = [
|
||||
'fiat' => ['value' => 50.0, 'unit' => 'kH/s'],
|
||||
'crypto' => ['value' => 75.0, 'unit' => 'kH/s'],
|
||||
'fiat' => ['value' => 100.0, 'unit' => 'kH/s'],
|
||||
'crypto' => ['value' => 50.0, 'unit' => 'kH/s'],
|
||||
];
|
||||
|
||||
private string $moduleBasePath;
|
||||
@@ -1907,18 +1907,23 @@ final class Router
|
||||
{
|
||||
$paymentType = $this->enumValue($input['payment_type'] ?? 'fiat', ['fiat', 'crypto'], 'payment_type');
|
||||
$baseSpeed = self::BASE_OFFER_SPEEDS[$paymentType] ?? self::BASE_OFFER_SPEEDS['fiat'];
|
||||
$bonusPercent = $this->optionalDecimal($input['bonus_percent'] ?? null);
|
||||
$basePriceCurrency = $paymentType === 'crypto'
|
||||
? 'USD'
|
||||
: $this->requiredCurrency($input['base_price_currency'] ?? ($input['reference_price_currency'] ?? $input['price_currency'] ?? null), 'base_price_currency');
|
||||
$projectCryptoCurrency = $this->requiredCurrency($this->settings($projectKey, [
|
||||
'cost_plans' => false,
|
||||
'currencies' => false,
|
||||
'payouts' => false,
|
||||
'wallet_withdrawals' => false,
|
||||
'miner_offers' => false,
|
||||
'purchased_miners' => false,
|
||||
])['crypto_currency'] ?? 'DOGE', 'crypto_currency');
|
||||
$basePriceCurrency = $this->requiredCurrency($input['base_price_currency'] ?? ($input['reference_price_currency'] ?? $input['price_currency'] ?? null), 'base_price_currency');
|
||||
$payload = [
|
||||
'label' => $this->requiredString($input['label'] ?? null, 'label', 120),
|
||||
'runtime_months' => $this->optionalPositiveInt($input['runtime_months'] ?? null),
|
||||
'runtime_months' => 3,
|
||||
'mining_speed_value' => $baseSpeed['value'],
|
||||
'mining_speed_unit' => $baseSpeed['unit'],
|
||||
'bonus_speed_value' => $this->bonusSpeedFromPercent((float) $baseSpeed['value'], (string) $baseSpeed['unit'], $bonusPercent),
|
||||
'bonus_speed_unit' => $bonusPercent !== null ? (string) $baseSpeed['unit'] : null,
|
||||
'bonus_percent' => $bonusPercent,
|
||||
'bonus_speed_value' => null,
|
||||
'bonus_speed_unit' => null,
|
||||
'bonus_percent' => null,
|
||||
'base_price_amount' => $this->requiredDecimal($input['base_price_amount'] ?? ($input['reference_price_amount'] ?? $input['price_amount'] ?? null), 'base_price_amount'),
|
||||
'base_price_currency' => $basePriceCurrency,
|
||||
'payment_type' => $paymentType,
|
||||
@@ -1927,12 +1932,23 @@ final class Router
|
||||
'is_active' => !empty($input['is_active']) ? 1 : 0,
|
||||
];
|
||||
|
||||
if ($bonusPercent !== null && $bonusPercent < 0) {
|
||||
throw new ApiException('Bonus-Prozent darf nicht negativ sein.', 422);
|
||||
if ($paymentType === 'crypto') {
|
||||
$allowedCryptoCurrencies = array_values(array_unique(['USD', $projectCryptoCurrency]));
|
||||
if (!in_array($payload['base_price_currency'], $allowedCryptoCurrencies, true)) {
|
||||
throw new ApiException('Bei Krypto-Angeboten sind nur USD oder die Projekt-Kryptowaehrung erlaubt.', 422, [
|
||||
'field' => 'base_price_currency',
|
||||
'allowed' => $allowedCryptoCurrencies,
|
||||
]);
|
||||
}
|
||||
} else {
|
||||
if ($payload['base_price_currency'] !== 'EUR') {
|
||||
throw new ApiException('Bei FIAT-Angeboten ist aktuell nur EUR als Basiswaehrung erlaubt.', 422, [
|
||||
'field' => 'base_price_currency',
|
||||
'allowed' => ['EUR'],
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
$this->assertCurrencyType($payload['base_price_currency'], false, 'base_price_currency');
|
||||
|
||||
return $this->repository()->saveMinerOffer($projectKey, $payload);
|
||||
}
|
||||
|
||||
|
||||
@@ -8,13 +8,51 @@ use Modules\MiningChecker\Support\ApiException;
|
||||
final class AnalyticsService
|
||||
{
|
||||
private const BASE_OFFER_SPEEDS = [
|
||||
'fiat' => ['value' => 50.0, 'unit' => 'kH/s'],
|
||||
'crypto' => ['value' => 75.0, 'unit' => 'kH/s'],
|
||||
'fiat' => ['value' => 100.0, 'unit' => 'kH/s'],
|
||||
'crypto' => ['value' => 50.0, 'unit' => 'kH/s'],
|
||||
];
|
||||
|
||||
private const OFFER_SPEED_MULTIPLIERS = [
|
||||
1, 2, 3, 4, 5, 6, 7, 8, 9, 10,
|
||||
11, 12, 13, 14, 15, 16, 17, 18, 19, 20,
|
||||
private const OFFER_SPEED_OPTIONS = [
|
||||
['value' => 50.0, 'unit' => 'kH/s'],
|
||||
['value' => 75.0, 'unit' => 'kH/s'],
|
||||
['value' => 100.0, 'unit' => 'kH/s'],
|
||||
['value' => 150.0, 'unit' => 'kH/s'],
|
||||
['value' => 200.0, 'unit' => 'kH/s'],
|
||||
['value' => 250.0, 'unit' => 'kH/s'],
|
||||
['value' => 300.0, 'unit' => 'kH/s'],
|
||||
['value' => 350.0, 'unit' => 'kH/s'],
|
||||
['value' => 400.0, 'unit' => 'kH/s'],
|
||||
['value' => 450.0, 'unit' => 'kH/s'],
|
||||
['value' => 500.0, 'unit' => 'kH/s'],
|
||||
['value' => 1.0, 'unit' => 'MH/s'],
|
||||
['value' => 5.0, 'unit' => 'MH/s'],
|
||||
['value' => 10.0, 'unit' => 'MH/s'],
|
||||
['value' => 15.0, 'unit' => 'MH/s'],
|
||||
['value' => 20.0, 'unit' => 'MH/s'],
|
||||
['value' => 30.0, 'unit' => 'MH/s'],
|
||||
['value' => 50.0, 'unit' => 'MH/s'],
|
||||
['value' => 75.0, 'unit' => 'MH/s'],
|
||||
['value' => 100.0, 'unit' => 'MH/s'],
|
||||
['value' => 150.0, 'unit' => 'MH/s'],
|
||||
['value' => 200.0, 'unit' => 'MH/s'],
|
||||
['value' => 250.0, 'unit' => 'MH/s'],
|
||||
['value' => 300.0, 'unit' => 'MH/s'],
|
||||
];
|
||||
|
||||
private const OFFER_RUNTIME_CONFIGS = [
|
||||
'crypto' => [
|
||||
['months' => 3, 'discount_percent' => 0.0, 'bonus_percent' => 5.0],
|
||||
['months' => 6, 'discount_percent' => 10.0, 'bonus_percent' => 10.0],
|
||||
['months' => 12, 'discount_percent' => 35.0, 'bonus_percent' => 10.0],
|
||||
['months' => 18, 'discount_percent' => 45.0, 'bonus_percent' => 15.0],
|
||||
['months' => 24, 'discount_percent' => 55.0, 'bonus_percent' => 20.0],
|
||||
['months' => 36, 'discount_percent' => 65.0, 'bonus_percent' => 20.0],
|
||||
],
|
||||
'fiat' => [
|
||||
['months' => 3, 'discount_percent' => 0.0, 'bonus_percent' => 5.0],
|
||||
['months' => 6, 'discount_percent' => 10.0, 'bonus_percent' => 10.0],
|
||||
['months' => 12, 'discount_percent' => 35.0, 'bonus_percent' => 10.0],
|
||||
],
|
||||
];
|
||||
|
||||
private ?FxService $fx;
|
||||
@@ -970,7 +1008,6 @@ final class AnalyticsService
|
||||
$baseSpeed = self::BASE_OFFER_SPEEDS[$paymentType] ?? self::BASE_OFFER_SPEEDS['fiat'];
|
||||
$baseSpeedValue = (float) $baseSpeed['value'];
|
||||
$baseSpeedUnit = (string) $baseSpeed['unit'];
|
||||
$baseBonusPercent = $this->deriveBonusPercent($offer, $baseSpeedValue, $baseSpeedUnit);
|
||||
$basePriceAmount = is_numeric($offer['base_price_amount'] ?? null)
|
||||
? (float) $offer['base_price_amount']
|
||||
: (is_numeric($offer['reference_price_amount'] ?? null)
|
||||
@@ -978,33 +1015,60 @@ final class AnalyticsService
|
||||
: (is_numeric($offer['usd_reference_amount'] ?? null)
|
||||
? (float) $offer['usd_reference_amount']
|
||||
: (is_numeric($offer['price_amount'] ?? null) ? (float) $offer['price_amount'] : null)));
|
||||
$baseSpeedMh = $this->normalizeHashrateMh($baseSpeedValue, $baseSpeedUnit);
|
||||
$runtimeConfigs = self::OFFER_RUNTIME_CONFIGS[$paymentType] ?? self::OFFER_RUNTIME_CONFIGS['fiat'];
|
||||
|
||||
foreach (self::OFFER_SPEED_MULTIPLIERS as $multiplier) {
|
||||
$derivedSpeedValue = $baseSpeedValue * $multiplier;
|
||||
$derivedBonusValue = $baseBonusPercent !== null
|
||||
? round($derivedSpeedValue * ($baseBonusPercent / 100), 4)
|
||||
: null;
|
||||
$derivedPriceAmount = $basePriceAmount !== null
|
||||
? round($basePriceAmount * $multiplier, 8)
|
||||
: null;
|
||||
foreach ($runtimeConfigs as $runtimeConfig) {
|
||||
$runtimeMonths = (int) ($runtimeConfig['months'] ?? 0);
|
||||
$discountPercent = (float) ($runtimeConfig['discount_percent'] ?? 0.0);
|
||||
$bonusPercent = (float) ($runtimeConfig['bonus_percent'] ?? 0.0);
|
||||
if ($runtimeMonths <= 0 || $baseSpeedMh <= 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$expanded[] = array_merge($offer, [
|
||||
'id' => sprintf('%s:%s:%s', (string) ($offer['id'] ?? 'offer'), $paymentType, rtrim(rtrim(number_format($derivedSpeedValue, 4, '.', ''), '0'), '.')),
|
||||
'base_offer_id' => $offer['id'] ?? null,
|
||||
'base_offer_label' => $offer['label'] ?? null,
|
||||
'payment_type' => $paymentType,
|
||||
'label' => trim(((string) ($offer['label'] ?? 'Miner-Angebot')) . ' · ' . $this->formatSpeedLabel($derivedSpeedValue, $baseSpeedUnit)),
|
||||
'mining_speed_value' => $derivedSpeedValue,
|
||||
'mining_speed_unit' => $baseSpeedUnit,
|
||||
'bonus_speed_value' => $derivedBonusValue,
|
||||
'bonus_speed_unit' => $derivedBonusValue !== null ? $baseSpeedUnit : null,
|
||||
'bonus_percent' => $baseBonusPercent,
|
||||
'speed_factor' => $multiplier,
|
||||
'base_speed_value' => $baseSpeedValue,
|
||||
'base_speed_unit' => $baseSpeedUnit,
|
||||
'base_price_amount' => $derivedPriceAmount,
|
||||
'reference_price_amount' => $derivedPriceAmount,
|
||||
]);
|
||||
foreach (self::OFFER_SPEED_OPTIONS as $speedOption) {
|
||||
$derivedSpeedValue = (float) ($speedOption['value'] ?? 0.0);
|
||||
$derivedSpeedUnit = (string) ($speedOption['unit'] ?? '');
|
||||
$derivedSpeedMh = $this->normalizeHashrateMh($derivedSpeedValue, $derivedSpeedUnit);
|
||||
if ($derivedSpeedMh <= 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$speedFactor = $derivedSpeedMh / $baseSpeedMh;
|
||||
$runtimeFactor = $runtimeMonths / 3.0;
|
||||
$discountFactor = max(0.0, 1.0 - ($discountPercent / 100.0));
|
||||
$derivedBonusValue = round($derivedSpeedValue * ($bonusPercent / 100.0), 4);
|
||||
$derivedPriceAmount = $basePriceAmount !== null
|
||||
? round($basePriceAmount * $speedFactor * $runtimeFactor * $discountFactor, 8)
|
||||
: null;
|
||||
|
||||
$expanded[] = array_merge($offer, [
|
||||
'id' => sprintf(
|
||||
'%s:%s:%s:%s',
|
||||
(string) ($offer['id'] ?? 'offer'),
|
||||
$paymentType,
|
||||
$runtimeMonths,
|
||||
rtrim(rtrim(number_format($derivedSpeedMh, 4, '.', ''), '0'), '.')
|
||||
),
|
||||
'base_offer_id' => $offer['id'] ?? null,
|
||||
'base_offer_label' => $offer['label'] ?? null,
|
||||
'payment_type' => $paymentType,
|
||||
'label' => trim(((string) ($offer['label'] ?? 'Miner-Angebot')) . ' · ' . $this->formatSpeedLabel($derivedSpeedValue, $derivedSpeedUnit) . ' · ' . $runtimeMonths . ' Monate'),
|
||||
'runtime_months' => $runtimeMonths,
|
||||
'mining_speed_value' => $derivedSpeedValue,
|
||||
'mining_speed_unit' => $derivedSpeedUnit,
|
||||
'bonus_speed_value' => $derivedBonusValue > 0 ? $derivedBonusValue : null,
|
||||
'bonus_speed_unit' => $derivedBonusValue > 0 ? $derivedSpeedUnit : null,
|
||||
'bonus_percent' => $bonusPercent,
|
||||
'discount_percent' => $discountPercent,
|
||||
'speed_factor' => $speedFactor,
|
||||
'base_speed_value' => $baseSpeedValue,
|
||||
'base_speed_unit' => $baseSpeedUnit,
|
||||
'base_runtime_months' => 3,
|
||||
'base_price_amount' => $derivedPriceAmount,
|
||||
'reference_price_amount' => $derivedPriceAmount,
|
||||
]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1019,7 +1083,7 @@ final class AnalyticsService
|
||||
return $runtimeCompare;
|
||||
}
|
||||
|
||||
return ((int) ($left['speed_factor'] ?? 0)) <=> ((int) ($right['speed_factor'] ?? 0));
|
||||
return ((float) ($left['speed_factor'] ?? 0.0)) <=> ((float) ($right['speed_factor'] ?? 0.0));
|
||||
});
|
||||
|
||||
return $expanded;
|
||||
|
||||
Reference in New Issue
Block a user