debug
This commit is contained in:
147
code/app/model/ConfigSubjectFomartModel.php
Normal file
147
code/app/model/ConfigSubjectFomartModel.php
Normal file
@@ -0,0 +1,147 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace app\model;
|
||||||
|
|
||||||
|
|
||||||
|
use Exception;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @mixin think\Model
|
||||||
|
*/
|
||||||
|
class ConfigSubjectFomartModel extends MongoModel
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Undocumented variable
|
||||||
|
*
|
||||||
|
* @var self
|
||||||
|
*/
|
||||||
|
static public $obj;
|
||||||
|
|
||||||
|
static public function getInstance(): self
|
||||||
|
{
|
||||||
|
if (self::$obj == NULL) {
|
||||||
|
self::$obj = new self;
|
||||||
|
}
|
||||||
|
return self::$obj;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Undocumented variable
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
protected $strCollection = 'config_subject_fomart';
|
||||||
|
|
||||||
|
static public $arrOptions = [
|
||||||
|
'typeMap' => [
|
||||||
|
'root' => 'array',
|
||||||
|
'document' => 'array',
|
||||||
|
'array' => 'array',
|
||||||
|
],
|
||||||
|
'projection' => [
|
||||||
|
'_id' => 0,
|
||||||
|
],
|
||||||
|
];
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 直接读库查询大量小说
|
||||||
|
*
|
||||||
|
* @param integer $intNId
|
||||||
|
* @return null|array
|
||||||
|
*/
|
||||||
|
public function findMany(array $arrFilter, int $intCount = 10, array $arrSort = [], array $arrOptions = []): null|array
|
||||||
|
{
|
||||||
|
if (empty($arrOptions)) {
|
||||||
|
$arrOptions = self::$arrOptions;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($intCount > 0) {
|
||||||
|
$arrOptions['limit'] = $intCount;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (empty($arrSort)) {
|
||||||
|
$arrOptions['sort'] = $arrSort;
|
||||||
|
}
|
||||||
|
|
||||||
|
$Cursor = $this->getCol()->find($arrFilter, $arrOptions);
|
||||||
|
|
||||||
|
$arrResult = iterator_to_array($Cursor);
|
||||||
|
|
||||||
|
return $arrResult;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 查询多条数据并缓存
|
||||||
|
*
|
||||||
|
* @param array $arrFilter
|
||||||
|
* @param integer $intCount
|
||||||
|
* @param array $arrSort
|
||||||
|
* @param array $arrOptions
|
||||||
|
* @param string $strKey
|
||||||
|
* @param integer $intLifeTime
|
||||||
|
* @return null|array
|
||||||
|
*/
|
||||||
|
public function findManyWithCache(
|
||||||
|
array $arrFilter,
|
||||||
|
int $intCount = 0,
|
||||||
|
array $arrSort = [],
|
||||||
|
array $arrOptions = [],
|
||||||
|
string $strKey = '',
|
||||||
|
int $intLifeTime = 24 * 3600,
|
||||||
|
): null|array {
|
||||||
|
try {
|
||||||
|
|
||||||
|
$arrResult = $this->checkCacheByKey($strKey);
|
||||||
|
if ($arrResult !== NULL) {
|
||||||
|
return $arrResult;
|
||||||
|
}
|
||||||
|
|
||||||
|
$arrResult = $this->findMany($arrFilter, $intCount, $arrSort, $arrOptions);
|
||||||
|
|
||||||
|
$this->setCacheByKey($strKey, $arrResult, $intLifeTime);
|
||||||
|
|
||||||
|
return $arrResult;
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* find one novel
|
||||||
|
*
|
||||||
|
* @param array $arrFilter
|
||||||
|
* @param array $arrOptions
|
||||||
|
* @return null|array
|
||||||
|
*/
|
||||||
|
public function findOne(array $arrFilter, array $arrOptions = []): null|array
|
||||||
|
{
|
||||||
|
if (empty($arrOptions)) {
|
||||||
|
$arrOptions = self::$arrOptions;
|
||||||
|
}
|
||||||
|
|
||||||
|
$arrNovel = $this->getOne($arrFilter, $arrOptions);
|
||||||
|
|
||||||
|
|
||||||
|
return $arrNovel;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据小说ID查询指定小说
|
||||||
|
*
|
||||||
|
* @param integer $intNId
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function getConfigSubjectFomartByCfsKey(string $intNId): null|array
|
||||||
|
{
|
||||||
|
$arrFilter = ['cfs_key' => $intNId];
|
||||||
|
return $this->findOne($arrFilter);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
@@ -94,22 +94,46 @@ class DomainModel extends BaseModel
|
|||||||
* @param string $strKey
|
* @param string $strKey
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function getFomartSubject($strKey) //, $intNum = 1, $boolRand = false)
|
public function getFomartSubject($strKey, $strDiff = '')
|
||||||
{
|
{
|
||||||
$intSfgId = $this->t_cfg->{$strKey}['sfg_id'];
|
$intSfgId = $this->t_cfg->{$strKey}['sfg_id'];
|
||||||
|
|
||||||
// $SubjectFomartModel = SubjectFomartModel::where('sfg_id', $intSfgId)->select()->first();
|
$SubjectFomartModel = NULL;
|
||||||
|
|
||||||
$arrAllSubjectFomartModel = SubjectFomartModel::getAllSubjectFomartOnCacheBySfgId($intSfgId);
|
$arrAllSubjectFomartModel = SubjectFomartModel::getAllSubjectFomartOnCacheBySfgId($intSfgId);
|
||||||
|
if (empty($arrAllSubjectFomartModel)) {
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
|
||||||
$SubjectFomartModel = (is_array($arrAllSubjectFomartModel) && !empty($arrAllSubjectFomartModel)) ? reset($arrAllSubjectFomartModel) : null;
|
$strDomain = request()->DomainModel->d_domain;
|
||||||
|
$strController = request()->controller();
|
||||||
|
$strAction = request()->action();
|
||||||
|
|
||||||
return empty($SubjectFomartModel) ? '' : $SubjectFomartModel->sf_val;
|
$strUUId = sprintf('%s-%s-%s-%s-%s', $strDomain, $strController, $strAction, $strKey, $strDiff);
|
||||||
|
|
||||||
// echo '<pre>';
|
$arrConfigSubjectFomart = ConfigSubjectFomartModel::getInstance()->getConfigSubjectFomartByCfsKey($strUUId);
|
||||||
// print_r($SubjectFomartModel);
|
|
||||||
// exit;
|
|
||||||
|
|
||||||
// return $SubjectFomartModel->sf_val;
|
if (empty($arrConfigSubjectFomart)) {
|
||||||
|
|
||||||
|
$intKey = array_rand($arrAllSubjectFomartModel);
|
||||||
|
|
||||||
|
$SubjectFomartModel = $arrAllSubjectFomartModel[$intKey];
|
||||||
|
|
||||||
|
ConfigSubjectFomartModel::getInstance()->insert([
|
||||||
|
'cfs_key' => $strUUId,
|
||||||
|
'sf_id' => $SubjectFomartModel->sf_id,
|
||||||
|
]);
|
||||||
|
} else {
|
||||||
|
$intSfId = $arrConfigSubjectFomart['sf_id'];
|
||||||
|
|
||||||
|
foreach ($arrAllSubjectFomartModel as $objTemp) {
|
||||||
|
if ($objTemp->sf_id == $intSfId) {
|
||||||
|
$SubjectFomartModel = $objTemp;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $SubjectFomartModel->sf_val;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
10
code/database/mongo/migrations/config_subject_fomart.php
Normal file
10
code/database/mongo/migrations/config_subject_fomart.php
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
<?php
|
||||||
|
return [
|
||||||
|
'collection' => 'config_subject_fomart',
|
||||||
|
'indexes' => [
|
||||||
|
[
|
||||||
|
'key' => ['csf_key' => 1],
|
||||||
|
'options' => ['unique' => true]
|
||||||
|
],
|
||||||
|
]
|
||||||
|
];
|
||||||
@@ -71,8 +71,8 @@ CREATE TABLE `domain` (
|
|||||||
`d_index_description` varchar(1000) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT '首页description模板',
|
`d_index_description` varchar(1000) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT '首页description模板',
|
||||||
`d_statis` text CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci COMMENT '单域名统计',
|
`d_statis` text CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci COMMENT '单域名统计',
|
||||||
`d_logo_type` tinyint(1) DEFAULT NULL,
|
`d_logo_type` tinyint(1) DEFAULT NULL,
|
||||||
`d_text_log` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
|
`d_text_logo` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
|
||||||
`d_img_log` varchar(500) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
|
`d_img_logo` varchar(500) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
|
||||||
`d_content_encode` tinyint unsigned DEFAULT '0',
|
`d_content_encode` tinyint unsigned DEFAULT '0',
|
||||||
`t_cfg` json DEFAULT NULL,
|
`t_cfg` json DEFAULT NULL,
|
||||||
PRIMARY KEY (`d_id`),
|
PRIMARY KEY (`d_id`),
|
||||||
|
|||||||
Reference in New Issue
Block a user