$row, 'source_column' => $column, 'original' => $original, 'text' => $saved[$row]['text'] ?? $original, 'region' => (string) ($source['values'][$row][0] ?? '')]; } return $cells; } public static function payload(?array $payload, array $data, array $source): ?array { if (! array_key_exists('quote_notes', $data)) return $payload; $cells = self::cells($source); $changes = []; foreach ($data['quote_notes'] as $row => $value) { if (! isset($cells[$row])) throw ValidationException::withMessages(['quote_notes' => '报价备注位置已变化,请重新载入后修改。']); $text = (string) ($value ?? ''); if ($text !== $cells[$row]['original']) $changes[$row] = [...$cells[$row], 'text' => $text]; } $payload = $payload ?? []; unset($payload['quote_notes']); if ($changes !== []) $payload['quote_notes'] = $changes; return $payload ?: null; } public static function apply(array $source, array $notes): array { $cells = self::cells($source); foreach ($notes as $row => $note) { if (! isset($cells[$row]) || $cells[$row]['original'] !== $note['original']) { throw ValidationException::withMessages(['quote_notes' => '原报价备注已变化,请退回后重新核对。']); } $source['values'][$row][$cells[$row]['source_column']] = $note['text']; // The legacy import also stores the same general remarks above the matrix. if (filled($source['billing_rules'] ?? null) && trim($source['billing_rules']) === trim($note['original'])) { $source['billing_rules'] = $note['text']; } } return $source; } }