初始化
This commit is contained in:
@@ -0,0 +1,56 @@
|
||||
<?php
|
||||
namespace app\models;
|
||||
|
||||
use core\base\Model;
|
||||
|
||||
/**
|
||||
* 财务账务记录模型
|
||||
*/
|
||||
class FinanceRecord extends Model
|
||||
{
|
||||
protected $table = 'finance_record';
|
||||
|
||||
public function getAll()
|
||||
{
|
||||
return $this->order(['record_date DESC', 'id DESC'])->fetchAll();
|
||||
}
|
||||
|
||||
public function getById($id)
|
||||
{
|
||||
return $this->where(['id = :id'], [':id' => $id])->fetch();
|
||||
}
|
||||
|
||||
public function getByDateRange($startDate, $endDate, $type = '')
|
||||
{
|
||||
$where = 'record_date >= :start AND record_date <= :end';
|
||||
$params = [':start' => $startDate, ':end' => $endDate];
|
||||
if ($type) {
|
||||
$where .= ' AND type = :type';
|
||||
$params[':type'] = $type;
|
||||
}
|
||||
return $this->where([$where], $params)->order(['record_date DESC', 'id DESC'])->fetchAll();
|
||||
}
|
||||
|
||||
public function getSummary($startDate, $endDate)
|
||||
{
|
||||
$sql = "SELECT
|
||||
type,
|
||||
SUM(amount) AS total,
|
||||
COUNT(*) AS cnt
|
||||
FROM " . $this->getTable() . "
|
||||
WHERE record_date >= :start AND record_date <= :end
|
||||
GROUP BY type";
|
||||
$stmt = $this->pdo->prepare($sql);
|
||||
$stmt->execute([':start' => $startDate, ':end' => $endDate]);
|
||||
return $stmt->fetchAll();
|
||||
}
|
||||
|
||||
public function getCount()
|
||||
{
|
||||
$sql = 'SELECT COUNT(*) AS cnt FROM ' . $this->getTable();
|
||||
$stmt = $this->pdo->prepare($sql);
|
||||
$stmt->execute();
|
||||
$row = $stmt->fetch();
|
||||
return (int)($row['cnt'] ?? 0);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user