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

This commit is contained in:
2026-07-13 22:48:56 +02:00
parent cb8c494a23
commit e0afaca57b
8 changed files with 406 additions and 28 deletions

View File

@@ -111,6 +111,92 @@ final class MiningRepository
]);
}
public function listOfferBasisHistory(string $projectKey, int $limit = 50): array
{
$stmt = $this->pdo->prepare(
'SELECT * FROM ' . $this->table('offer_basis_history') . '
WHERE project_key = :project_key AND owner_sub = :owner_sub
ORDER BY created_at DESC, id DESC
LIMIT :limit'
);
$stmt->bindValue(':project_key', $projectKey, PDO::PARAM_STR);
$stmt->bindValue(':owner_sub', $this->ownerSub, PDO::PARAM_STR);
$stmt->bindValue(':limit', $limit, PDO::PARAM_INT);
$stmt->execute();
return $this->normalizeRows($stmt->fetchAll() ?: []);
}
public function latestOfferBasisEntry(string $projectKey, string $offerType): ?array
{
$stmt = $this->pdo->prepare(
'SELECT * FROM ' . $this->table('offer_basis_history') . '
WHERE project_key = :project_key AND owner_sub = :owner_sub AND offer_type = :offer_type
ORDER BY created_at DESC, id DESC
LIMIT 1'
);
$stmt->execute([
'project_key' => $projectKey,
'owner_sub' => $this->ownerSub,
'offer_type' => strtolower(trim($offerType)),
]);
$row = $stmt->fetch();
return is_array($row) ? $this->normalizeRow($row) : null;
}
public function saveOfferBasisEntry(string $projectKey, array $payload): array
{
$normalizedType = strtolower(trim((string) ($payload['offer_type'] ?? '')));
$latest = $this->latestOfferBasisEntry($projectKey, $normalizedType);
if (
is_array($latest)
&& (string) ($latest['base_price_currency'] ?? '') === (string) ($payload['base_price_currency'] ?? '')
&& is_numeric($latest['base_price_amount'] ?? null)
&& is_numeric($payload['base_price_amount'] ?? null)
&& abs((float) $latest['base_price_amount'] - (float) $payload['base_price_amount']) < 0.00000001
) {
return $latest;
}
if ($this->driver === 'pgsql') {
$stmt = $this->pdo->prepare(
'INSERT INTO ' . $this->table('offer_basis_history') . ' (
project_key, owner_sub, offer_type, base_price_amount, base_price_currency
) VALUES (
:project_key, :owner_sub, :offer_type, :base_price_amount, :base_price_currency
)
RETURNING *'
);
$stmt->execute([
'project_key' => $projectKey,
'owner_sub' => $this->ownerSub,
'offer_type' => $normalizedType,
'base_price_amount' => $payload['base_price_amount'],
'base_price_currency' => $payload['base_price_currency'],
]);
return $this->normalizeRow($stmt->fetch() ?: []);
}
$stmt = $this->pdo->prepare(
'INSERT INTO ' . $this->table('offer_basis_history') . ' (
project_key, owner_sub, offer_type, base_price_amount, base_price_currency
) VALUES (
:project_key, :owner_sub, :offer_type, :base_price_amount, :base_price_currency
)'
);
$stmt->execute([
'project_key' => $projectKey,
'owner_sub' => $this->ownerSub,
'offer_type' => $normalizedType,
'base_price_amount' => $payload['base_price_amount'],
'base_price_currency' => $payload['base_price_currency'],
]);
$id = (int) $this->pdo->lastInsertId();
$fetch = $this->pdo->prepare('SELECT * FROM ' . $this->table('offer_basis_history') . ' WHERE id = :id LIMIT 1');
$fetch->execute(['id' => $id]);
return $this->normalizeRow($fetch->fetch() ?: []);
}
public function tableExists(string $logicalName): bool
{
$tableName = $this->table($logicalName);
@@ -1384,6 +1470,7 @@ final class MiningRepository
'wallet_snapshots' => $this->prefix . 'wallet_snapshots',
'wallet_withdrawals' => $this->prefix . 'wallet_withdrawals',
'miner_offers' => $this->prefix . 'miner_offers',
'offer_basis_history' => $this->prefix . 'offer_basis_history',
'purchased_miners' => $this->prefix . 'purchased_miners',
default => throw new \RuntimeException('Unknown mining table: ' . $logicalName),
};