Files
2026-08-08 18:28:49 +08:00

95 lines
2.7 KiB
PHP

<?php
/**
* @deprecated 2026-06-18 已废弃,请使用 StationDefinition 替代。
* 所有工位数据操作统一通过 StationDefinition 模型处理。
* 此文件保留仅用于向后兼容,后续版本将删除。
*/
namespace app\models;
use core\base\Model;
/**
* 入库工位模型(成品入库)
* @deprecated
*/
class Inbound extends Model
{
protected $table = 'station_inbound';
// 获取所有记录
public function getAll()
{
return $this->order(['id DESC'])->fetchAll();
}
// 根据产品类型和型号筛选记录
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 addRecord($data)
{
return $this->add($data);
}
// 根据序列号查找
public function findBySerial($serial_no)
{
return $this->where(['serial_no = :serial'], [':serial' => $serial_no])->fetch();
}
// 批量导入
public function batchImport($records)
{
foreach ($records as $record) {
$this->add($record);
}
return true;
}
}