request->domain(); $cacheKey = 'haonav_sitemap_' . md5($domain); $xml = Cache::get($cacheKey); if (! $xml) { $urls = [ ['loc' => $domain . '/haonav/index.html', 'priority' => '1.0', 'changefreq' => 'daily'], ['loc' => $domain . '/haonav/rank.html', 'priority' => '0.8', 'changefreq' => 'daily'], ['loc' => $domain . '/haonav/apply.html', 'priority' => '0.5', 'changefreq' => 'monthly'], ]; $cates = CategoryModel::where('status', 1)->field('id,update_at')->select(); foreach ($cates as $c) { $urls[] = [ 'loc' => $domain . '/haonav/category/' . $c->id . '.html', 'priority' => '0.8', 'changefreq' => 'weekly', 'lastmod' => $c->update_at ? date('Y-m-d', strtotime((string)$c->update_at)) : '', ]; } $links = LinksModel::where('status', 1)->field('id,update_at')->order('id', 'asc')->limit(5000)->select(); foreach ($links as $l) { $urls[] = [ 'loc' => $domain . '/haonav/site/' . $l->id . '.html', 'priority' => '0.6', 'changefreq' => 'weekly', 'lastmod' => $l->update_at ? date('Y-m-d', strtotime((string)$l->update_at)) : '', ]; } $xml = '' . "\n" . '' . "\n"; foreach ($urls as $u) { $xml .= " \n " . htmlspecialchars($u['loc']) . "\n"; if (! empty($u['lastmod'])) { $xml .= ' ' . $u['lastmod'] . "\n"; } $xml .= ' ' . $u['changefreq'] . "\n" . ' ' . $u['priority'] . "\n \n"; } $xml .= ''; Cache::set($cacheKey, $xml, 3600); } return Response::create($xml)->header([ 'Content-Type' => 'application/xml; charset=utf-8', 'Cache-Control' => 'public, max-age=3600', ]); } }