debug
This commit is contained in:
81
code/app/model/ConverterMovel.php
Normal file
81
code/app/model/ConverterMovel.php
Normal file
@@ -0,0 +1,81 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace app\model;
|
||||
|
||||
use DateTime;
|
||||
use think\facade\Cache;
|
||||
use think\Model;
|
||||
|
||||
/**
|
||||
* @mixin think\Model
|
||||
*/
|
||||
class ConverterMovel
|
||||
{
|
||||
static private $arrMap = [
|
||||
'{strSiteTitle}' => '',
|
||||
'{strSiteKeywords}' => '',
|
||||
'{strSiteDescription}' => '',
|
||||
'{strNovelName}' => '',
|
||||
'{strNovelChapterName}' => '',
|
||||
'{strNovelCategoryName}' => '',
|
||||
];
|
||||
|
||||
static public $arrDescription = [
|
||||
'{strSiteTitle}' => '这个是网站标题',
|
||||
'{strSiteKeywords}' => '这个是网站关键字',
|
||||
'{strSiteDescription}' => '这个是网站描述',
|
||||
'{strNovelName}' => '当前页面小说标题',
|
||||
'{strNovelChapterName}' => '当前页面小说章节名字',
|
||||
'{strNovelCategoryName}' => '当前页面小说分类名字',
|
||||
];
|
||||
|
||||
static private function getKey($strKey): string
|
||||
{
|
||||
return '{' . $strKey . '}';
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @param string|array $mixedKey 全局动态变量键或者数组
|
||||
* @param string $strVal 全局动态变量值
|
||||
* @return void
|
||||
*/
|
||||
static public function setVal(string | array $mixedKey, $strVal = NULL)
|
||||
{
|
||||
if (is_string($mixedKey)) {
|
||||
self::$arrMap[self::getKey($mixedKey)] = $strVal;
|
||||
} else if (is_array($mixedKey)) {
|
||||
foreach ($mixedKey as $strKey => $strVal) {
|
||||
if (key_exists(self::getKey($strKey), self::$arrMap)) {
|
||||
self::$arrMap[self::getKey($strKey)] = $strVal;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @param string $strKey
|
||||
* @return void
|
||||
*/
|
||||
static public function getVal(string $strKey)
|
||||
{
|
||||
return self::$arrMap[self::getKey($strKey)];
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @param string $strSubject
|
||||
* @return string
|
||||
*/
|
||||
static public function convert(string $strSubject): string
|
||||
{
|
||||
return str_replace(array_keys(self::$arrMap), array_values(self::$arrMap), $strSubject);
|
||||
}
|
||||
}
|
||||
@@ -53,6 +53,94 @@ class NovelModel extends MongoModel
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @param string $strKey
|
||||
* @param int $intLifeTime
|
||||
* @param integer $intCount
|
||||
* @param integer $intType
|
||||
* @param string $strStatus
|
||||
* @param array $arrSort
|
||||
* @return array
|
||||
*/
|
||||
public function getCommonNovelPageOnCache(
|
||||
string $strKey,
|
||||
int $intPage = 1,
|
||||
int $intLimit = 20,
|
||||
int $intLifeTime = 24 * 3600,
|
||||
int $intType = 0,
|
||||
$strStatus = NULL,
|
||||
array $arrSort = ['n_level' => -1]
|
||||
): array {
|
||||
try {
|
||||
|
||||
$arrResult = Cache::get($strKey);
|
||||
|
||||
// if (empty($arrResult)) {
|
||||
if (true) {
|
||||
$arrFilter = [];
|
||||
|
||||
switch ($intType) {
|
||||
case 1:
|
||||
$arrCategory = array_values(CategoryModel::getManCategory());
|
||||
$arrFilter['og_novel_category'] = ['$in' => $arrCategory];
|
||||
break;
|
||||
case 2:
|
||||
$arrCategory = array_values(CategoryModel::getWomenCategory());
|
||||
$arrFilter['og_novel_category'] = ['$in' => $arrCategory];
|
||||
break;
|
||||
}
|
||||
|
||||
if ($strStatus !== NULL) {
|
||||
$arrFilter['og_novel_status'] = $strStatus;
|
||||
}
|
||||
|
||||
$arrOptions = [
|
||||
'sort' => $arrSort,
|
||||
// 'limit' => $intCount * 3,
|
||||
'skip' => ($intPage - 1) * $intLimit,
|
||||
'limit' => $intLimit,
|
||||
'projection' => [
|
||||
'n_id' => 1,
|
||||
'og_novel_book_name' => 1,
|
||||
'og_novel_pin_yin' => 1,
|
||||
'n_cover_path' => 1,
|
||||
'og_novel_author' => 1,
|
||||
'og_novel_category' => 1,
|
||||
'og_description' => 1,
|
||||
'og_novel_latest_chapter_name' => 1,
|
||||
'og_novel_update_time' => 1,
|
||||
],
|
||||
];
|
||||
|
||||
$Cursor = $this->getCol()->find($arrFilter, $arrOptions);
|
||||
$intTotal = $this->getCol()->countDocuments($arrFilter);
|
||||
|
||||
$arrResult = iterator_to_array($Cursor);
|
||||
|
||||
shuffle($arrResult);
|
||||
|
||||
$arrResult = [
|
||||
'data' => $arrResult,
|
||||
'total' => $intTotal,
|
||||
'page' => $intPage,
|
||||
'limit' => $intLimit,
|
||||
'pages' => ceil($intTotal / $intLimit)
|
||||
];
|
||||
|
||||
if (!empty($arrResult)) {
|
||||
Cache::set($strKey, $arrResult, $intLifeTime);
|
||||
}
|
||||
}
|
||||
|
||||
return $arrResult;
|
||||
} catch (\Exception $e) {
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user