From 4d60f87c45ab99da4bbfafa4b44bf408e7160217 Mon Sep 17 00:00:00 2001 From: Default Date: Thu, 10 Apr 2025 17:05:46 +0800 Subject: [PATCH] debug --- code/app/model/ConfigSubjectFomartModel.php | 147 ++++++++++++++++++ code/app/model/DomainModel.php | 40 ++++- .../migrations/config_subject_fomart.php | 10 ++ code/database/schema/mysql-schema.dump | 4 +- 4 files changed, 191 insertions(+), 10 deletions(-) create mode 100644 code/app/model/ConfigSubjectFomartModel.php create mode 100644 code/database/mongo/migrations/config_subject_fomart.php diff --git a/code/app/model/ConfigSubjectFomartModel.php b/code/app/model/ConfigSubjectFomartModel.php new file mode 100644 index 0000000..6e89ed5 --- /dev/null +++ b/code/app/model/ConfigSubjectFomartModel.php @@ -0,0 +1,147 @@ + [ + '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); + } + + +} diff --git a/code/app/model/DomainModel.php b/code/app/model/DomainModel.php index 5157848..b5f5e78 100644 --- a/code/app/model/DomainModel.php +++ b/code/app/model/DomainModel.php @@ -94,22 +94,46 @@ class DomainModel extends BaseModel * @param string $strKey * @return void */ - public function getFomartSubject($strKey) //, $intNum = 1, $boolRand = false) + public function getFomartSubject($strKey, $strDiff = '') { $intSfgId = $this->t_cfg->{$strKey}['sfg_id']; - // $SubjectFomartModel = SubjectFomartModel::where('sfg_id', $intSfgId)->select()->first(); + $SubjectFomartModel = NULL; + $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 '
';
-        // print_r($SubjectFomartModel);
-        // exit;
+        $arrConfigSubjectFomart = ConfigSubjectFomartModel::getInstance()->getConfigSubjectFomartByCfsKey($strUUId);
 
-        // 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;
     }
 
 
diff --git a/code/database/mongo/migrations/config_subject_fomart.php b/code/database/mongo/migrations/config_subject_fomart.php
new file mode 100644
index 0000000..2277de8
--- /dev/null
+++ b/code/database/mongo/migrations/config_subject_fomart.php
@@ -0,0 +1,10 @@
+ 'config_subject_fomart',
+    'indexes' => [
+        [
+            'key' => ['csf_key' => 1],
+            'options' => ['unique' => true]
+        ],
+    ]
+];
diff --git a/code/database/schema/mysql-schema.dump b/code/database/schema/mysql-schema.dump
index 44572e0..3339c1e 100644
--- a/code/database/schema/mysql-schema.dump
+++ b/code/database/schema/mysql-schema.dump
@@ -71,8 +71,8 @@ CREATE TABLE `domain` (
   `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_logo_type` tinyint(1) DEFAULT NULL,
-  `d_text_log` 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_text_logo` varchar(255) 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',
   `t_cfg` json DEFAULT NULL,
   PRIMARY KEY (`d_id`),