| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162 |
- <?php
- namespace Models;
- class TokenModel
- {
- private \PDO $pdo;
- public function __construct()
- {
- if (isset($GLOBALS['pdo']) && $GLOBALS['pdo'] instanceof \PDO) {
- $this->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);
- }
- }
|