no message
This commit is contained in:
1 parent
5d85fb8bc3
commit
a82f234853
6 files changed
+112
-2
No files matched your search
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Models\Articles;
|
||||
use Illuminate\Http\Response;
|
||||
|
||||
class SitemapController extends Controller
|
||||
{
|
||||
public function index(): Response
|
||||
{
|
||||
// 连表查询分类:按 aOpt['noindexday'] 动态过滤过期文章
|
||||
$cArticles = Articles::where('iStatus', 1)
|
||||
->whereHas('oCategory', function ($q) {
|
||||
$q->where(function ($query) {
|
||||
// 1. 没有配置 noindexday,或者 noindexday = 0 的文章,一直保留
|
||||
$query->whereNull('aOpt')
|
||||
->orWhereRaw("JSON_UNQUOTE(JSON_EXTRACT(aOpt, '$.noindexday')) IS NULL")
|
||||
->orWhereRaw("JSON_UNQUOTE(JSON_EXTRACT(aOpt, '$.noindexday')) = '0'")
|
||||
// 2. 配置了天数的,只取 N 天内创建的新文章
|
||||
->orWhereRaw("articles.created_at >= NOW() - INTERVAL CAST(JSON_UNQUOTE(JSON_EXTRACT(aOpt, '$.noindexday')) AS UNSIGNED) DAY");
|
||||
});
|
||||
})
|
||||
->orderBy('created_at', 'desc')
|
||||
->get();
|
||||
|
||||
$sXmlContent = view('sitemap', [
|
||||
'cArticles' => $cArticles
|
||||
])->render();
|
||||
|
||||
return response($sXmlContent, 200)->header('Content-Type', 'text/xml');
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user