89 lines
2.4 KiB
PHP
89 lines
2.4 KiB
PHP
<?php
|
|
/**
|
|
* @deprecated 2026-06-18 已废弃,请使用 StationDefinition 替代。
|
|
*/
|
|
namespace app\models;
|
|
|
|
use core\base\Model;
|
|
|
|
/**
|
|
* 电池状态模型
|
|
* @deprecated
|
|
*/
|
|
class Battery extends Model
|
|
{
|
|
protected $table = 'battery_status';
|
|
|
|
public function getAll()
|
|
{
|
|
return $this->order(['id DESC'])->fetchAll();
|
|
}
|
|
|
|
public function addRecord($data)
|
|
{
|
|
return $this->add($data);
|
|
}
|
|
|
|
public function findBySerial($serial_no)
|
|
{
|
|
return $this->where(['serial_no = :serial'], [':serial' => $serial_no])->fetch();
|
|
}
|
|
|
|
// 根据产品类型和型号筛选记录
|
|
public function getByTypeAndModel($product_type, $product_model)
|
|
{
|
|
if (empty($product_type) && empty($product_model)) {
|
|
return [];
|
|
}
|
|
$conditions = [];
|
|
$params = [];
|
|
if (!empty($product_type)) {
|
|
$conditions[] = 'product_type = :pt';
|
|
$params[':pt'] = $product_type;
|
|
}
|
|
if (!empty($product_model)) {
|
|
$conditions[] = 'product_model = :pm';
|
|
$params[':pm'] = $product_model;
|
|
}
|
|
return $this->where($conditions, $params)->order(['id DESC'])->fetchAll();
|
|
}
|
|
|
|
// 统计当日某操作员的录入数量
|
|
public function countTodayByOperator($operator)
|
|
{
|
|
$sql = "SELECT COUNT(*) as cnt FROM " . $this->getTable() . " WHERE operator = :op AND DATE(created_at) = CURDATE()";
|
|
$result = $this->query($sql, [':op' => $operator]);
|
|
return $result[0]['cnt'] ?? 0;
|
|
}
|
|
|
|
// 统计总记录数(可按型号筛选)
|
|
public function countTotal($product_type = '', $product_model = '')
|
|
{
|
|
$conditions = [];
|
|
$params = [];
|
|
if (!empty($product_type)) {
|
|
$conditions[] = 'product_type = :pt';
|
|
$params[':pt'] = $product_type;
|
|
}
|
|
if (!empty($product_model)) {
|
|
$conditions[] = 'product_model = :pm';
|
|
$params[':pm'] = $product_model;
|
|
}
|
|
if (!empty($conditions)) {
|
|
$result = $this->where($conditions, $params)->field('COUNT(*) as cnt')->fetch();
|
|
} else {
|
|
$sql = "SELECT COUNT(*) as cnt FROM " . $this->getTable();
|
|
$result = $this->query($sql);
|
|
}
|
|
return $result[0]['cnt'] ?? 0;
|
|
}
|
|
|
|
public function batchImport($records)
|
|
{
|
|
foreach ($records as $record) {
|
|
$this->add($record);
|
|
}
|
|
return true;
|
|
}
|
|
}
|