order(['id DESC'])->fetchAll(); } public function addRecord($data) { return $this->add($data); } public function findByFinishedSerial($finished_serial) { return $this->where(['finished_serial = :serial'], [':serial' => $finished_serial])->fetch(); } // 根据产品型号筛选记录(assembly 表无 product_type 列) public function getByTypeAndModel($product_type, $product_model) { if (empty($product_model)) { return []; } return $this->where(['product_model = :pm'], [':pm' => $product_model])->order(['id DESC'])->fetchAll(); } // 统计当日某操作员的录入数量 public function countTodayByOperator($operator) { $sql = "SELECT COUNT(*) as cnt FROM " . $this->getTable() . " WHERE operator = :op AND DATE(assembly_time) = CURDATE()"; $result = $this->query($sql, [':op' => $operator]); return $result[0]['cnt'] ?? 0; } // 统计总记录数(可按型号筛选) public function countTotal($product_type = '', $product_model = '') { if (!empty($product_model)) { $result = $this->where(['product_model = :pm'], [':pm' => $product_model])->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; } }