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; } }