Implementacao upload anexos de ordens

This commit is contained in:
HalbeBruno
2026-03-12 15:20:38 -03:00
parent 6a1312d55c
commit fa96ec4aea
11 changed files with 352 additions and 11 deletions

View File

@@ -0,0 +1,41 @@
<?php
namespace App\Models;
use App\Core\Model;
class OrderAttachment extends Model
{
protected $table = 'order_attachments';
/**
* Retorna todos os anexos de uma ordem específica.
*/
public function findByOrderId(int $orderId): array
{
$stmt = $this->conn->prepare(
"SELECT * FROM {$this->table} WHERE order_id = :order_id ORDER BY created_at ASC"
);
$stmt->execute(['order_id' => $orderId]);
return $stmt->fetchAll();
}
/**
* Insere um registro de anexo no banco.
*/
public function create(array $data): int
{
$stmt = $this->conn->prepare(
"INSERT INTO {$this->table} (order_id, original_name, stored_name, mime_type, size)
VALUES (:order_id, :original_name, :stored_name, :mime_type, :size)"
);
$stmt->execute([
'order_id' => $data['order_id'],
'original_name' => $data['original_name'],
'stored_name' => $data['stored_name'],
'mime_type' => $data['mime_type'] ?? null,
'size' => $data['size'] ?? null,
]);
return (int) $this->conn->lastInsertId();
}
}