$venueIds * @return array{city_total: int, top_venues: array} */ public function citySummary(Collection $venueIds): array { $ids = $venueIds->map(fn ($id) => (int) $id)->filter()->unique()->values(); if ($ids->isEmpty()) { return ['city_total' => 0, 'top_venues' => []]; } $map = $this->venueCurrentMap($ids); $top = collect($map) ->sortByDesc('current_count') ->take(3) ->values() ->all(); $cityTotal = collect($map)->sum('current_count'); return [ 'city_total' => (int) $cityTotal, 'top_venues' => $top, ]; } /** * @param Collection $venueIds * @return array */ public function venueCurrentMap(Collection $venueIds): array { $ids = $venueIds->map(fn ($id) => (int) $id)->filter()->unique()->values(); if ($ids->isEmpty()) { return []; } $venues = Venue::query()->whereIn('id', $ids)->get(['id', 'name']); $seed = (int) now()->format('YmdHi'); // 分钟级动态变化 return $venues->map(function (Venue $venue) use ($seed) { $base = abs(crc32((string) ($venue->id * 131 + $seed))); $current = 20 + ($base % 380); // 20~399 return [ 'venue_id' => (int) $venue->id, 'venue_name' => (string) $venue->name, 'current_count' => (int) $current, ]; })->values()->all(); } }