初始化

This commit is contained in:
2026-08-08 18:28:49 +08:00
parent 9bef4420e0
commit f082037a6e
854 changed files with 217171 additions and 11 deletions
+43
View File
@@ -0,0 +1,43 @@
<?php
namespace app\models;
use core\base\Model;
/**
* 库存模型
*/
class Inventory extends Model
{
protected $table = 'inventory';
public function getAll()
{
return $this->order(['id DESC'])->fetchAll();
}
public function getById($id)
{
return $this->where(['id = :id'], [':id' => $id])->fetch();
}
public function getLowStock()
{
return $this->where(['quantity <= min_stock AND min_stock > 0'])->order(['quantity ASC'])->fetchAll();
}
public function getCount()
{
$sql = 'SELECT COUNT(*) AS cnt, SUM(quantity) AS total_qty FROM ' . $this->getTable();
$stmt = $this->pdo->prepare($sql);
$stmt->execute();
return $stmt->fetch();
}
public function search($keyword)
{
return $this->where(
['product_name LIKE :kw OR product_model LIKE :kw2 OR category LIKE :kw3'],
[':kw' => "%{$keyword}%", ':kw2' => "%{$keyword}%", ':kw3' => "%{$keyword}%"]
)->order(['id DESC'])->fetchAll();
}
}