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