66 lines
1.8 KiB
PHP
66 lines
1.8 KiB
PHP
<?php
|
|
namespace app\models;
|
|
|
|
use core\base\Model;
|
|
|
|
/**
|
|
* 通用工位记录模型
|
|
* 用于动态添加的工位类型的数据存储
|
|
* 通过 station_type 字段区分不同工位
|
|
*/
|
|
class StationRecord extends Model
|
|
{
|
|
protected $table = 'station_records';
|
|
|
|
/**
|
|
* 根据工位类型获取记录
|
|
*/
|
|
public function getByStationType($stationType, $limit = 100)
|
|
{
|
|
return $this->where(['station_type = :type'], [':type' => $stationType])
|
|
->order(['created_at DESC'])
|
|
->limit($limit)
|
|
->fetchAll();
|
|
}
|
|
|
|
/**
|
|
* 添加记录
|
|
* @param string $stationType 工位类型
|
|
* @param array $data 字段名→值的键值对
|
|
* @param string $operator 操作人
|
|
*/
|
|
public function addRecord($stationType, $data, $operator = '')
|
|
{
|
|
return $this->add([
|
|
'station_type' => $stationType,
|
|
'record_data' => json_encode($data, JSON_UNESCAPED_UNICODE),
|
|
'operator' => $operator,
|
|
'created_at' => date('Y-m-d H:i:s'),
|
|
]);
|
|
}
|
|
|
|
/**
|
|
* 统计今日某操作人的记录数
|
|
*/
|
|
public function countTodayByOperator($operator, $stationType = null)
|
|
{
|
|
$conditions = [];
|
|
$params = [];
|
|
|
|
$conditions[] = 'operator = :operator';
|
|
$params[':operator'] = $operator;
|
|
|
|
$conditions[] = 'DATE(created_at) = CURDATE()';
|
|
|
|
if ($stationType) {
|
|
$conditions[] = 'station_type = :type';
|
|
$params[':type'] = $stationType;
|
|
}
|
|
|
|
$result = $this->where($conditions, $params)
|
|
->field('COUNT(*) as cnt')
|
|
->fetch();
|
|
return $result['cnt'] ?? 0;
|
|
}
|
|
}
|