pdo = $GLOBALS['pdo']; return; } throw new \RuntimeException('Global PDO connection not initialized'); } public function getByUf(string $uf): array { $stmt = $this->pdo->prepare('SELECT token_id, token_external_id, token_commodities_amount, token_commodities_value, token_uf, token_city, token_content, token_flag, wallet_id, chain_id, commodities_id, cpr_id, user_id FROM "token" WHERE token_uf = :uf ORDER BY token_id'); $stmt->execute(['uf' => $uf]); return $stmt->fetchAll(\PDO::FETCH_ASSOC); } public function getByUfAndCommodityName(string $uf, string $commoditiesName): array { $sql = 'SELECT t.token_id, t.token_external_id, t.token_commodities_amount, t.token_commodities_value, t.token_uf, t.token_city, t.token_content, t.token_flag, t.wallet_id, t.chain_id, t.commodities_id, t.cpr_id, t.user_id FROM "token" t JOIN "commodities" c ON c.commodities_id = t.commodities_id WHERE t.token_uf = :uf AND LOWER(TRIM(c.commodities_name)) = LOWER(TRIM(:name)) ORDER BY t.token_id'; $stmt = $this->pdo->prepare($sql); $stmt->execute(['uf' => $uf, 'name' => $commoditiesName]); return $stmt->fetchAll(\PDO::FETCH_ASSOC); } public function getByCompanyId(int $companyId): array { $sql = 'SELECT t.token_id, t.token_external_id, t.token_commodities_amount, t.token_commodities_value, t.token_uf, t.token_city, t.token_content, t.token_flag, t.wallet_id, t.chain_id, t.commodities_id, t.cpr_id, t.user_id FROM "token" t INNER JOIN "wallet" w ON w.wallet_id = t.wallet_id WHERE w.company_id = :company_id ORDER BY t.token_id'; $stmt = $this->pdo->prepare($sql); $stmt->execute(['company_id' => $companyId]); return $stmt->fetchAll(\PDO::FETCH_ASSOC); } public function findByCprId(int $cprId, bool $forUpdate = false): ?array { $sql = 'SELECT token_id, token_external_id, token_commodities_amount, token_commodities_value, token_uf, token_city, token_content, token_flag, wallet_id, chain_id, commodities_id, cpr_id, user_id FROM "token" WHERE cpr_id = :cpr_id ORDER BY token_id DESC LIMIT 1'; if ($forUpdate) { $sql .= ' FOR UPDATE'; } $stmt = $this->pdo->prepare($sql); $stmt->execute(['cpr_id' => $cprId]); $record = $stmt->fetch(\PDO::FETCH_ASSOC); return $record ?: null; } public function updateCommoditiesValue(int $tokenId, float $value): void { $stmt = $this->pdo->prepare( 'UPDATE "token" SET token_commodities_value = :value WHERE token_id = :token_id' ); $stmt->execute([ 'value' => $value, 'token_id' => $tokenId, ]); } }