diff --git a/app/BaseController.php b/app/BaseController.php index ebc71f3..127daf9 100644 --- a/app/BaseController.php +++ b/app/BaseController.php @@ -116,6 +116,8 @@ abstract class BaseController $url = $_SERVER["HTTP_REFERER"]; } elseif ($url) { $url = (strpos($url, '://') || 0 === strpos($url, '/')) ? $url : app('route')->buildUrl($url); + }else{ + $url = app('route')->buildUrl("/"); } $result = [ @@ -152,7 +154,6 @@ abstract class BaseController } elseif ($url) { $url = (strpos($url, '://') || 0 === strpos($url, '/')) ? $url : $this->app->route->buildUrl($url); } - $result = [ 'code' => 0, 'msg' => $msg, @@ -160,7 +161,6 @@ abstract class BaseController 'url' => $url, 'wait' => $wait, ]; - $type = $this->getResponseType(); if ($type == 'html') { $response = view(config('app.dispatch_success_tmpl'), $result); diff --git a/app/admin/controller/Index.php b/app/admin/controller/Index.php index 6912828..777efcb 100644 --- a/app/admin/controller/Index.php +++ b/app/admin/controller/Index.php @@ -15,6 +15,7 @@ use Exception; use think\db\exception\DataNotFoundException; use think\db\exception\DbException; use think\db\exception\ModelNotFoundException; +use think\facade\Request; class Index extends AuthController { @@ -82,11 +83,9 @@ class Index extends AuthController */ public function sitemap() { - //获取协议 - $protocol = ((!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] != 'off') || $_SERVER['SERVER_PORT'] == 443) ? - "https://" : "http://"; + //获取域名 - $domain = $protocol . $_SERVER['HTTP_HOST']; + $domain = Request::domain(); //获取页码 $page = input('page/d'); if (!$page) { @@ -114,10 +113,9 @@ class Index extends AuthController ->where('status', 1)->where('status', 1) ->page($page, $pagesize) ->order('id desc')->select(); - foreach ($categoryInfo as $v) { $str .= ''; - $str .= '' . $domain . url('article/lists?id=' . $v['id']) . ''; + $str .= '' . url('index/article/lists',["id"=>$v['id']],".html",$domain) . ''; $str .= '' . $v['create_time'] . ''; $str .= 'always'; $str .= '0.8'; @@ -132,7 +130,7 @@ class Index extends AuthController foreach ($documentInfo as $v) { $str .= ''; - $str .= '' . $domain . url('article/detail?id=' . $v['id']) . $v['id'] . ''; + $str .= '' . url('/index/article/detail',["id"=>$v['id']],".html",$domain) . ''; $str .= '' . $v['create_time'] . ''; $str .= 'monthly'; $str .= '0.6'; @@ -140,17 +138,13 @@ class Index extends AuthController } if (count($categoryInfo) < $pagesize && count($documentInfo) < $pagesize) { $str .= ''; - if (!(file_put_contents('sitemap.xml', $str, FILE_APPEND | LOCK_EX))) { - $this->error('站点地图更新失败!',"/admin/"); - } else { - $this->success('站点地图全部更新完成!', "/admin/"); - } + return (!(file_put_contents('sitemap.xml', $str, FILE_APPEND | LOCK_EX))) ? + $this->failedNotice("站点地图更新失败!", "/admin/") : + $this->successfulNotice("站点地图全部更新完成!", "/admin/"); } //写入 - if (!(file_put_contents('sitemap.xml', $str, FILE_APPEND | LOCK_EX))) { - $this->error('站点地图更新失败!'); - } else { - $this->success('站点地图正在生成,请稍后(' . $page . ')...', 'sitemap?page=' . ($page + 1)); - } + return (!(file_put_contents('sitemap.xml', $str, FILE_APPEND | LOCK_EX))) ? + $this->failedNotice("站点地图更新失败!", "/admin/") : + $this->successfulNotice('站点地图正在生成,请稍后(' . $page . ')...', 'sitemap?page=' . ($page + 1)); } } \ No newline at end of file diff --git a/app/admin/view/index/index.html b/app/admin/view/index/index.html index 0bd97a3..728af5d 100644 --- a/app/admin/view/index/index.html +++ b/app/admin/view/index/index.html @@ -38,9 +38,10 @@