增加详情json
This commit is contained in:
@@ -92,33 +92,66 @@ class VideoSiteMapLogic
|
|||||||
return $this->arrDomainModel;
|
return $this->arrDomainModel;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Generate Site Map
|
* Generate Site Map & Video JSON
|
||||||
*
|
*
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function generateSiteMap()
|
public function generateSiteMap()
|
||||||
{
|
{
|
||||||
$arrResult = $this->VideoModel->findPaginatedWithCache([], 1, 1);
|
// 1. 只查一次总数(非常重要)
|
||||||
|
$arrResult = $this->VideoModel->findPaginatedWithCache([], 1, 1);
|
||||||
$this->intTotal = $arrResult['total'];
|
$this->intTotal = $arrResult['total'];
|
||||||
|
|
||||||
|
// 2. sitemap index
|
||||||
$this->generateMapIndex();
|
$this->generateMapIndex();
|
||||||
|
|
||||||
|
// 3. sitemap main
|
||||||
$this->generateMapMain();
|
$this->generateMapMain();
|
||||||
|
|
||||||
|
// 4. 统一分页数
|
||||||
$intTotalPage = ceil($this->intTotal / $this->intPageSize);
|
$intTotalPage = ceil($this->intTotal / $this->intPageSize);
|
||||||
|
|
||||||
|
// 5. 分页生成 sitemap + json(推荐放一起)
|
||||||
for ($intPage = 1; $intPage <= $intTotalPage; $intPage++) {
|
for ($intPage = 1; $intPage <= $intTotalPage; $intPage++) {
|
||||||
|
|
||||||
|
// 原有 sitemap
|
||||||
$this->generateMapInfo($intPage);
|
$this->generateMapInfo($intPage);
|
||||||
|
|
||||||
|
// 新增 JSON
|
||||||
|
$this->generateVideoJsonByPage($intPage);
|
||||||
}
|
}
|
||||||
|
|
||||||
echo date('Y-m-d H:i:s') . PHP_EOL;
|
echo date('Y-m-d H:i:s') . PHP_EOL;
|
||||||
}
|
}
|
||||||
|
/**
|
||||||
|
* Generate Site Map
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
// public function generateSiteMap()
|
||||||
|
// {
|
||||||
|
// $arrResult = $this->VideoModel->findPaginatedWithCache([], 1, 1);
|
||||||
|
// $this->intTotal = $arrResult['total'];
|
||||||
|
|
||||||
|
// $this->generateMapIndex();
|
||||||
|
|
||||||
|
// $this->generateMapMain();
|
||||||
|
|
||||||
|
// $intTotalPage = ceil($this->intTotal / $this->intPageSize);
|
||||||
|
// for ($intPage = 1; $intPage <= $intTotalPage; $intPage++) {
|
||||||
|
// $this->generateMapInfo($intPage);
|
||||||
|
// }
|
||||||
|
|
||||||
|
// echo date('Y-m-d H:i:s') . PHP_EOL;
|
||||||
|
// }
|
||||||
|
|
||||||
|
|
||||||
protected function generateMapInfo(int $intPage)
|
protected function generateMapInfo(int $intPage)
|
||||||
{
|
{
|
||||||
$intStartPage = $intPage ;
|
$intStartPage = $intPage;
|
||||||
$intStart = ($intStartPage-=1) * $this->intPageSize;
|
$intStart = ($intStartPage -= 1) * $this->intPageSize;
|
||||||
foreach ($this->getDomain() as $DomainModel) {
|
foreach ($this->getDomain() as $DomainModel) {
|
||||||
|
|
||||||
$strDomainDir = $this->strSiteMapPath . $DomainModel->d_domain;
|
$strDomainDir = $this->strSiteMapPath . $DomainModel->d_domain;
|
||||||
@@ -147,9 +180,9 @@ EOF;
|
|||||||
|
|
||||||
file_put_contents($strMapVideosFile, $strHead);
|
file_put_contents($strMapVideosFile, $strHead);
|
||||||
|
|
||||||
|
|
||||||
# 取 intpage * limit ~ intpage * (limit+1) 写入以上文件
|
# 取 intpage * limit ~ intpage * (limit+1) 写入以上文件
|
||||||
|
|
||||||
foreach ($this->fetchVideosByBatch($intStart, $this->intPageSize) as $Video) {
|
foreach ($this->fetchVideosByBatch($intStart, $this->intPageSize) as $Video) {
|
||||||
|
|
||||||
# 1 '/voddetail/{strPinYin}-{intVId}',
|
# 1 '/voddetail/{strPinYin}-{intVId}',
|
||||||
@@ -168,17 +201,15 @@ EOF;
|
|||||||
$strContent = sprintf($strTemplate, $strUrl, $strPriority);
|
$strContent = sprintf($strTemplate, $strUrl, $strPriority);
|
||||||
file_put_contents($strMapVideosFile, $strContent, FILE_APPEND);
|
file_put_contents($strMapVideosFile, $strContent, FILE_APPEND);
|
||||||
file_put_contents($strMapVideosFileTxt, $strUrl . PHP_EOL, FILE_APPEND);
|
file_put_contents($strMapVideosFileTxt, $strUrl . PHP_EOL, FILE_APPEND);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
file_put_contents($strMapVideosFile, $strEnd, FILE_APPEND);
|
file_put_contents($strMapVideosFile, $strEnd, FILE_APPEND);
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 分批查询小说数据,并以生成器方式返回
|
* 分批查询数据,并以生成器方式返回
|
||||||
*
|
*
|
||||||
* @param int $intStart 跳过的记录数(skip)
|
* @param int $intStart 跳过的记录数(skip)
|
||||||
* @param int $intCount 需要查询的总记录数
|
* @param int $intCount 需要查询的总记录数
|
||||||
@@ -194,9 +225,7 @@ EOF;
|
|||||||
while ($intRecordsFetched < $intRemainingRecords) {
|
while ($intRecordsFetched < $intRemainingRecords) {
|
||||||
$intLimit = min($this->intBatchSize, $intRemainingRecords - $intRecordsFetched);
|
$intLimit = min($this->intBatchSize, $intRemainingRecords - $intRecordsFetched);
|
||||||
$Cursor = $this->VideoModel->getCol()->find(
|
$Cursor = $this->VideoModel->getCol()->find(
|
||||||
[
|
[],
|
||||||
|
|
||||||
],
|
|
||||||
[
|
[
|
||||||
'skip' => $intStart + $intRecordsFetched,
|
'skip' => $intStart + $intRecordsFetched,
|
||||||
'limit' => $intLimit,
|
'limit' => $intLimit,
|
||||||
@@ -296,23 +325,23 @@ EOF;
|
|||||||
// foreach ($this->arrVideoArea as $strVideoAreaKey => $strVideoAreaVal) {
|
// foreach ($this->arrVideoArea as $strVideoAreaKey => $strVideoAreaVal) {
|
||||||
// foreach ($this->arrVideoYear as $strVideoYearKey => $strVideoYearVal) {
|
// foreach ($this->arrVideoYear as $strVideoYearKey => $strVideoYearVal) {
|
||||||
|
|
||||||
$strKey = "VIDEO_CATEGORY_URL";
|
$strKey = "VIDEO_CATEGORY_URL";
|
||||||
$strDomain = $DomainModel->d_domain;
|
$strDomain = $DomainModel->d_domain;
|
||||||
$strController = "";
|
$strController = "";
|
||||||
$strAction = "";
|
$strAction = "";
|
||||||
$arrArgs = [
|
$arrArgs = [
|
||||||
'strParentCategory' => $arrParentCategory['v_category_en'],
|
'strParentCategory' => $arrParentCategory['v_category_en'],
|
||||||
'strCategory' => $arrChildrenCategory['v_category_en'],
|
'strCategory' => $arrChildrenCategory['v_category_en'],
|
||||||
'strYear' => 'all',
|
'strYear' => 'all',
|
||||||
'strArea' => 'all',
|
'strArea' => 'all',
|
||||||
'strOrder' => $strSortKey,
|
'strOrder' => $strSortKey,
|
||||||
'strLang' => 'all',
|
'strLang' => 'all',
|
||||||
'intPage' => 1,
|
'intPage' => 1,
|
||||||
];
|
];
|
||||||
|
|
||||||
$strUri = $DomainModel->getFomartUrlEx($strKey, $strDomain, $strController, $strAction, $arrArgs);
|
$strUri = $DomainModel->getFomartUrlEx($strKey, $strDomain, $strController, $strAction, $arrArgs);
|
||||||
$strUrl = sprintf("https://www.%s%s", $DomainModel->d_domain, $strUri);
|
$strUrl = sprintf("https://www.%s%s", $DomainModel->d_domain, $strUri);
|
||||||
$strContent = <<<EOF
|
$strContent = <<<EOF
|
||||||
<url>
|
<url>
|
||||||
<loc>{$strUrl}</loc>
|
<loc>{$strUrl}</loc>
|
||||||
<lastmod>{$this->strDate}</lastmod>
|
<lastmod>{$this->strDate}</lastmod>
|
||||||
@@ -320,7 +349,7 @@ EOF;
|
|||||||
<priority>0.8</priority>
|
<priority>0.8</priority>
|
||||||
</url>
|
</url>
|
||||||
EOF;
|
EOF;
|
||||||
file_put_contents($strMapIndexFile, $strContent, FILE_APPEND);
|
file_put_contents($strMapIndexFile, $strContent, FILE_APPEND);
|
||||||
// }
|
// }
|
||||||
// }
|
// }
|
||||||
// }
|
// }
|
||||||
@@ -412,4 +441,98 @@ EOF;
|
|||||||
file_put_contents($strMapIndexFile, $strContent, FILE_APPEND);
|
file_put_contents($strMapIndexFile, $strContent, FILE_APPEND);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function generateVideoJsonAll(): void
|
||||||
|
{
|
||||||
|
$arrResult = $this->VideoModel->findPaginatedWithCache([], 1, 1);
|
||||||
|
$this->intTotal = $arrResult['total'];
|
||||||
|
|
||||||
|
$intTotalPage = ceil($this->intTotal / $this->intPageSize);
|
||||||
|
|
||||||
|
for ($intPage = 1; $intPage <= $intTotalPage; $intPage++) {
|
||||||
|
$this->generateVideoJsonByPage($intPage);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 分页生成 Video JSON(与 sitemap-videos-* 完全一致)
|
||||||
|
*
|
||||||
|
* 每个 JSON 文件格式:
|
||||||
|
* [
|
||||||
|
* {
|
||||||
|
* "keyword": "...",
|
||||||
|
* "site": "...",
|
||||||
|
* "href": "...",
|
||||||
|
* "url": "#"
|
||||||
|
* }
|
||||||
|
* ]
|
||||||
|
*/
|
||||||
|
public function generateVideoJsonByPage(int $intPage): void
|
||||||
|
{
|
||||||
|
$intStart = ($intPage - 1) * $this->intPageSize;
|
||||||
|
|
||||||
|
foreach ($this->getDomain() as $DomainModel) {
|
||||||
|
|
||||||
|
$strDomainDir = $this->strSiteMapPath . $DomainModel->d_domain;
|
||||||
|
if (!is_dir($strDomainDir)) {
|
||||||
|
mkdir($strDomainDir, 0755, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
$strJsonFile = sprintf(
|
||||||
|
'%s/video-list-%d.json',
|
||||||
|
$strDomainDir,
|
||||||
|
$intPage
|
||||||
|
);
|
||||||
|
|
||||||
|
$fp = fopen($strJsonFile, 'w');
|
||||||
|
|
||||||
|
// JSON 数组开始
|
||||||
|
fwrite($fp, "[\n");
|
||||||
|
|
||||||
|
$isFirst = true;
|
||||||
|
|
||||||
|
foreach ($this->fetchVideosByBatch($intStart, $this->intPageSize) as $Video) {
|
||||||
|
|
||||||
|
$strUri = $DomainModel->getFomartUrlEx(
|
||||||
|
"VIDEO_INFO_URL",
|
||||||
|
$DomainModel->d_domain,
|
||||||
|
'',
|
||||||
|
'',
|
||||||
|
[
|
||||||
|
'intVId' => $Video->v_id,
|
||||||
|
'strPinYin' => $Video->v_name_en,
|
||||||
|
]
|
||||||
|
);
|
||||||
|
|
||||||
|
$strFullUrl = sprintf(
|
||||||
|
'https://www.%s%s',
|
||||||
|
$DomainModel->d_domain,
|
||||||
|
$strUri
|
||||||
|
);
|
||||||
|
|
||||||
|
$row = [
|
||||||
|
'keyword' => $Video->v_name,
|
||||||
|
'site' => $DomainModel->d_domain,
|
||||||
|
'href' => $strFullUrl,
|
||||||
|
'url' => '#',
|
||||||
|
];
|
||||||
|
|
||||||
|
if (!$isFirst) {
|
||||||
|
fwrite($fp, ",\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
fwrite(
|
||||||
|
$fp,
|
||||||
|
json_encode($row, JSON_UNESCAPED_UNICODE)
|
||||||
|
);
|
||||||
|
|
||||||
|
$isFirst = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// JSON 数组结束
|
||||||
|
fwrite($fp, "\n]");
|
||||||
|
fclose($fp);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user