setDescription('生成头条sitemap'); $this->addOption('platform', 'p', InputOption::VALUE_OPTIONAL, '指定的平台id.', false); } public function execute(InputInterface $input, OutputInterface $output): int { $platform = $input->getOption('platform'); // 域名 $domain = AppWebsiteConfig::find($platform)->app_domain; $sitemapArray = []; $query = AppNews::query()->select(['id', 'created_at'])->where('is_delete', 0)->get()->toArray(); foreach ($query as $item) { // $date = date('Y-m-d', $item['created_at']); $sitemapArray[] = << https://$domain/news/{$item['id']} {$item['created_at']} EOF; } if ($sitemapArray) { $val = implode(PHP_EOL, $sitemapArray); $sitemap = << $val EOF; file_put_contents('/www/wwwroot/huoerguosifeichi/sitemap.xml', $sitemap); } //var_dump($links); return 0; } private function _getTask($brand): \Generator { $query = Db::table('app_brands'); if ($brand) { $query->where(['id' => $brand]); } $query->where('id', '>', 1)->orderBy('id'); foreach ($query->cursor() as $row) { yield $row; } } private function _getTaskName($name): string { return strtolower(strtr($name, [ '.' => '-', ' ' => '-' ])); } public function spiderStart(): void { list($result, $httpCode) = $this->request($this->getBaseUrl() . '/fashion/street-style/'); preg_match_all('/