36 lines
764 B
PHP
36 lines
764 B
PHP
<?php
|
|
namespace app\models;
|
|
|
|
use core\base\Model;
|
|
|
|
/**
|
|
* 固定资产模型
|
|
*/
|
|
class Asset extends Model
|
|
{
|
|
protected $table = 'asset';
|
|
|
|
public function getAll()
|
|
{
|
|
return $this->order(['id DESC'])->fetchAll();
|
|
}
|
|
|
|
public function getById($id)
|
|
{
|
|
return $this->where(['id = :id'], [':id' => $id])->fetch();
|
|
}
|
|
|
|
public function getCount()
|
|
{
|
|
$sql = 'SELECT COUNT(*) AS cnt, SUM(purchase_price * quantity) AS total_value FROM ' . $this->getTable();
|
|
$stmt = $this->pdo->prepare($sql);
|
|
$stmt->execute();
|
|
return $stmt->fetch();
|
|
}
|
|
|
|
public function getByStatus($status)
|
|
{
|
|
return $this->where(['status = :st'], [':st' => $status])->order(['id DESC'])->fetchAll();
|
|
}
|
|
}
|