pageUrl = $pageUrl; $this->account = $account; $this->password = $password; $this->unifiedData = new UnifiedScrmData(); } /** @return array */ protected function getSpiderConfig(): array { return [ 'pageUrl' => $this->pageUrl, 'listApi' => self::API_LIST, 'listMethod' => 'GET', 'paginationMode' => self::MODE_UI, 'authActions' => [ ['type' => 'wait', 'ms' => 4000], ], ]; } /** * @param array|null $listFirstPageData * @param array|null $countData */ protected function extractListTotalPages($listFirstPageData, $countData = null) { $total = (int) ($listFirstPageData['total'] ?? 0); $this->unifiedData->total = $total; $this->unifiedData->todayNewCount = (int) ($listFirstPageData['data']['today_num'] ?? 0); if ($total <= self::DEFAULT_PER_PAGE_COUNT) { return 1; } return (int) ceil($total / self::DEFAULT_PER_PAGE_COUNT); } /** @return array */ protected function buildListPageParams(int $page): array { return ['page' => $page, 'limit' => self::DEFAULT_PER_PAGE_COUNT]; } /** @return array */ protected function getUiPaginationConfig(): array { return [ 'nextBtnSelector' => '.tabs-content .arco-pagination-item-next', 'waitMs' => 2000, ]; } protected function parseToUnifiedData($detailData, array $allListPagesData): UnifiedScrmData { $unifiedData = $this->unifiedData; foreach ($allListPagesData as $pageRaw) { if (!is_array($pageRaw)) { continue; } $records = $pageRaw['rows'] ?? []; if (!is_array($records)) { continue; } foreach ($records as $item) { if (!is_array($item) || empty($item['username'])) { continue; } $number = (string) $item['username']; $isOnline = isset($item['state']) && (int) $item['state'] === 1; $unifiedData->addNumber($number, $isOnline, (int) ($item['today_num'] ?? 0)); } } return $unifiedData; } }