$orderIds 内部订单号(o_id) * @return array [内部订单号 => 货号] */ public function forOrderIds(ConnectionInterface $connection, string $itemsTable, array $orderIds): array { $orderIds = array_values(array_unique(array_filter( array_map(static fn ($value): int => (int) $value, $orderIds), static fn (int $value): bool => $value > 0, ))); if ($orderIds === []) { return []; } $rows = $connection->table($itemsTable) ->whereIn('o_id', $orderIds) ->where(function ($query): void { $query->whereNull('item_status') ->orWhereNotIn('item_status', self::EXCLUDED_STATUSES); }) ->get(['o_id', 'sku_id']); $skus = []; foreach ($rows as $row) { $sku = trim((string) $row->sku_id); if ($sku === '') { continue; } $skus[(int) $row->o_id][$sku] = true; } $codes = []; foreach ($skus as $orderId => $list) { $list = array_keys($list); sort($list); $codes[$orderId] = mb_substr(implode(',', $list), 0, 191); } return $codes; } }