$record) { $rows[sprintf('line:%06d', $index + 1)] = $record; } $this->store->replaceAll(self::PREFIX . $supplier, $rows, $companyId, $userId); $this->store->save(self::LOG_PREFIX . $supplier, 'upload:' . now()->format('YmdHis'), [ 'uploaded_at' => now()->toDateTimeString(), 'filename' => $filename, 'rows' => count($records), ], $companyId, $userId, 'import'); return count($records); } /** @return list> 最新的对账单行 */ public function rows(string $supplier, int $companyId): array { return $this->store->listRows(self::PREFIX . $supplier, $companyId); } /** @return list> 最近的上传记录(新到旧) */ public function uploads(string $supplier, int $companyId, int $limit = 10): array { $uploads = $this->store->listRows(self::LOG_PREFIX . $supplier, $companyId); usort($uploads, static fn (array $a, array $b): int => strcmp((string) ($b['uploaded_at'] ?? ''), (string) ($a['uploaded_at'] ?? ''))); return array_slice($uploads, 0, $limit); } /** @return list 已经上传过对账单的厂家名称 */ public function uploadedSuppliers(int $companyId): array { return array_values(array_map( static fn (string $dataset): string => substr($dataset, strlen(self::LOG_PREFIX)), $this->store->datasetsWithPrefix(self::LOG_PREFIX, $companyId), )); } }