ysdsad
All checks were successful
Deploy / deploy-staging (push) Successful in 27s
Deploy / deploy-production (push) Has been skipped

This commit is contained in:
2026-08-14 01:51:48 +02:00
parent 6de12f164d
commit 3d2b566bf2
8 changed files with 391 additions and 69 deletions

View File

@@ -239,10 +239,12 @@ final class MiningRepository
$stmt = $this->pdo->prepare(
'INSERT INTO ' . $this->table('cost_plans') . ' (
project_key, owner_sub, label, starts_at, runtime_months, mining_speed_value, mining_speed_unit,
bonus_speed_value, bonus_speed_unit, auto_renew, base_price_amount, payment_type, total_cost_amount, currency, note, is_active
bonus_speed_value, bonus_speed_unit, auto_renew, base_price_amount, payment_type, total_cost_amount, currency,
daily_cost_amount, daily_cost_currency, note, is_active
) VALUES (
:project_key, :owner_sub, :label, :starts_at, :runtime_months, :mining_speed_value, :mining_speed_unit,
:bonus_speed_value, :bonus_speed_unit, :auto_renew, :base_price_amount, :payment_type, :total_cost_amount, :currency, :note, :is_active
:bonus_speed_value, :bonus_speed_unit, :auto_renew, :base_price_amount, :payment_type, :total_cost_amount, :currency,
:daily_cost_amount, :daily_cost_currency, :note, :is_active
)
RETURNING *'
);
@@ -253,10 +255,12 @@ final class MiningRepository
$stmt = $this->pdo->prepare(
'INSERT INTO ' . $this->table('cost_plans') . ' (
project_key, owner_sub, label, starts_at, runtime_months, mining_speed_value, mining_speed_unit,
bonus_speed_value, bonus_speed_unit, auto_renew, base_price_amount, payment_type, total_cost_amount, currency, note, is_active
bonus_speed_value, bonus_speed_unit, auto_renew, base_price_amount, payment_type, total_cost_amount, currency,
daily_cost_amount, daily_cost_currency, note, is_active
) VALUES (
:project_key, :owner_sub, :label, :starts_at, :runtime_months, :mining_speed_value, :mining_speed_unit,
:bonus_speed_value, :bonus_speed_unit, :auto_renew, :base_price_amount, :payment_type, :total_cost_amount, :currency, :note, :is_active
:bonus_speed_value, :bonus_speed_unit, :auto_renew, :base_price_amount, :payment_type, :total_cost_amount, :currency,
:daily_cost_amount, :daily_cost_currency, :note, :is_active
)'
);
$stmt->execute($this->normalizeInsertPayload($projectKey, $payload));
@@ -1001,11 +1005,13 @@ final class MiningRepository
'INSERT INTO ' . $this->table('purchased_miners') . ' (
project_key, owner_sub, miner_offer_id, purchased_at, label, runtime_months,
mining_speed_value, mining_speed_unit, bonus_speed_value, bonus_speed_unit,
total_cost_amount, currency, usd_reference_amount, reference_price_amount, reference_price_currency, auto_renew, note, is_active
total_cost_amount, currency, usd_reference_amount, reference_price_amount, reference_price_currency,
daily_cost_amount, daily_cost_currency, auto_renew, note, is_active
) VALUES (
:project_key, :owner_sub, :miner_offer_id, :purchased_at, :label, :runtime_months,
:mining_speed_value, :mining_speed_unit, :bonus_speed_value, :bonus_speed_unit,
:total_cost_amount, :currency, :usd_reference_amount, :reference_price_amount, :reference_price_currency, :auto_renew, :note, :is_active
:total_cost_amount, :currency, :usd_reference_amount, :reference_price_amount, :reference_price_currency,
:daily_cost_amount, :daily_cost_currency, :auto_renew, :note, :is_active
)
RETURNING *'
);
@@ -1017,11 +1023,13 @@ final class MiningRepository
'INSERT INTO ' . $this->table('purchased_miners') . ' (
project_key, owner_sub, miner_offer_id, purchased_at, label, runtime_months,
mining_speed_value, mining_speed_unit, bonus_speed_value, bonus_speed_unit,
total_cost_amount, currency, usd_reference_amount, reference_price_amount, reference_price_currency, auto_renew, note, is_active
total_cost_amount, currency, usd_reference_amount, reference_price_amount, reference_price_currency,
daily_cost_amount, daily_cost_currency, auto_renew, note, is_active
) VALUES (
:project_key, :owner_sub, :miner_offer_id, :purchased_at, :label, :runtime_months,
:mining_speed_value, :mining_speed_unit, :bonus_speed_value, :bonus_speed_unit,
:total_cost_amount, :currency, :usd_reference_amount, :reference_price_amount, :reference_price_currency, :auto_renew, :note, :is_active
:total_cost_amount, :currency, :usd_reference_amount, :reference_price_amount, :reference_price_currency,
:daily_cost_amount, :daily_cost_currency, :auto_renew, :note, :is_active
)'
);
$stmt->execute($this->normalizePurchasedPayload($projectKey, $offerId, $payload));
@@ -1049,6 +1057,8 @@ final class MiningRepository
'usd_reference_amount' => $payload['usd_reference_amount'] ?? null,
'reference_price_amount' => $payload['reference_price_amount'] ?? null,
'reference_price_currency' => $payload['reference_price_currency'] ?? null,
'daily_cost_amount' => $payload['daily_cost_amount'] ?? $this->deriveDailyCostAmount($payload['total_cost_amount'] ?? null, $payload['runtime_months'] ?? null),
'daily_cost_currency' => $payload['daily_cost_currency'] ?? ($payload['currency'] ?? null),
'auto_renew' => $payload['auto_renew'] ?? 0,
'note' => $payload['note'] ?? null,
'is_active' => $payload['is_active'] ?? 1,
@@ -1059,11 +1069,13 @@ final class MiningRepository
'INSERT INTO ' . $this->table('purchased_miners') . ' (
project_key, owner_sub, miner_offer_id, purchased_at, label, runtime_months,
mining_speed_value, mining_speed_unit, bonus_speed_value, bonus_speed_unit,
total_cost_amount, currency, usd_reference_amount, reference_price_amount, reference_price_currency, auto_renew, note, is_active
total_cost_amount, currency, usd_reference_amount, reference_price_amount, reference_price_currency,
daily_cost_amount, daily_cost_currency, auto_renew, note, is_active
) VALUES (
:project_key, :owner_sub, :miner_offer_id, :purchased_at, :label, :runtime_months,
:mining_speed_value, :mining_speed_unit, :bonus_speed_value, :bonus_speed_unit,
:total_cost_amount, :currency, :usd_reference_amount, :reference_price_amount, :reference_price_currency, :auto_renew, :note, :is_active
:total_cost_amount, :currency, :usd_reference_amount, :reference_price_amount, :reference_price_currency,
:daily_cost_amount, :daily_cost_currency, :auto_renew, :note, :is_active
)
RETURNING *'
);
@@ -1075,11 +1087,13 @@ final class MiningRepository
'INSERT INTO ' . $this->table('purchased_miners') . ' (
project_key, owner_sub, miner_offer_id, purchased_at, label, runtime_months,
mining_speed_value, mining_speed_unit, bonus_speed_value, bonus_speed_unit,
total_cost_amount, currency, usd_reference_amount, reference_price_amount, reference_price_currency, auto_renew, note, is_active
total_cost_amount, currency, usd_reference_amount, reference_price_amount, reference_price_currency,
daily_cost_amount, daily_cost_currency, auto_renew, note, is_active
) VALUES (
:project_key, :owner_sub, :miner_offer_id, :purchased_at, :label, :runtime_months,
:mining_speed_value, :mining_speed_unit, :bonus_speed_value, :bonus_speed_unit,
:total_cost_amount, :currency, :usd_reference_amount, :reference_price_amount, :reference_price_currency, :auto_renew, :note, :is_active
:total_cost_amount, :currency, :usd_reference_amount, :reference_price_amount, :reference_price_currency,
:daily_cost_amount, :daily_cost_currency, :auto_renew, :note, :is_active
)'
);
$stmt->execute($params);
@@ -1567,6 +1581,9 @@ final class MiningRepository
private function normalizeInsertPayload(string $projectKey, array $payload): array
{
$dailyCostAmount = $payload['daily_cost_amount'] ?? $this->deriveDailyCostAmount($payload['total_cost_amount'] ?? null, $payload['runtime_months'] ?? null);
$dailyCostCurrency = $payload['daily_cost_currency'] ?? ($payload['currency'] ?? null);
return [
'project_key' => $projectKey,
'owner_sub' => $this->ownerSub,
@@ -1582,6 +1599,8 @@ final class MiningRepository
'payment_type' => $payload['payment_type'] ?? 'fiat',
'total_cost_amount' => $payload['total_cost_amount'],
'currency' => $payload['currency'],
'daily_cost_amount' => $dailyCostAmount,
'daily_cost_currency' => $dailyCostCurrency,
'note' => $payload['note'],
'is_active' => $payload['is_active'],
];
@@ -1608,6 +1627,9 @@ final class MiningRepository
private function normalizePurchasedPayload(string $projectKey, ?int $offerId, array $payload): array
{
$dailyCostAmount = $payload['daily_cost_amount'] ?? $this->deriveDailyCostAmount($payload['total_cost_amount'] ?? null, $payload['runtime_months'] ?? null);
$dailyCostCurrency = $payload['daily_cost_currency'] ?? ($payload['currency'] ?? null);
return [
'project_key' => $projectKey,
'owner_sub' => $this->ownerSub,
@@ -1624,12 +1646,33 @@ final class MiningRepository
'usd_reference_amount' => $payload['usd_reference_amount'],
'reference_price_amount' => $payload['reference_price_amount'] ?? null,
'reference_price_currency' => $payload['reference_price_currency'] ?? null,
'daily_cost_amount' => $dailyCostAmount,
'daily_cost_currency' => $dailyCostCurrency,
'auto_renew' => $payload['auto_renew'] ?? 0,
'note' => $payload['note'],
'is_active' => $payload['is_active'],
];
}
private function deriveDailyCostAmount(mixed $totalCostAmount, mixed $runtimeMonths): ?float
{
if (!is_numeric($totalCostAmount) || !is_numeric($runtimeMonths)) {
return null;
}
$months = (float) $runtimeMonths;
if ($months <= 0) {
return null;
}
$runtimeDays = $months * 30.4375;
if ($runtimeDays <= 0) {
return null;
}
return round(((float) $totalCostAmount) / $runtimeDays, 10);
}
private function normalizeRows(array $rows): array
{
return array_map(fn (array $row): array => $this->normalizeRow($row), $rows);