Files
server/app/Models/Order.php
2025-12-17 12:33:42 -03:00

30 lines
851 B
PHP

<?php
namespace App\Models;
use App\Core\Model;
class Order extends Model
{
protected $table = 'orders';
public function recent($limit = 5)
{
$stmt = $this->conn->prepare("SELECT * FROM orders ORDER BY id DESC LIMIT :limit");
$stmt->bindValue(':limit', $limit, \PDO::PARAM_INT);
$stmt->execute();
return $stmt->fetchAll();
}
public function countAll()
{
$stmt = $this->conn->query("SELECT COUNT(*) as total FROM orders");
return $stmt->fetch()['total'];
}
public function countRecent($days = 7)
{
$stmt = $this->conn->prepare("SELECT COUNT(*) as total FROM orders WHERE created_at >= DATE_SUB(NOW(), INTERVAL :days DAY)");
$stmt->bindValue(':days', $days, \PDO::PARAM_INT);
$stmt->execute();
return $stmt->fetch()['total'];
}
}