This commit is contained in:
Default
2025-04-07 20:12:34 +08:00
parent 46fbd69470
commit ba168ff55c
6 changed files with 159 additions and 41 deletions

View File

@@ -78,10 +78,13 @@ class Site extends BaseController
$arrDomain['t_cfg'] = json_encode($TCfgTemplate, JSON_UNESCAPED_UNICODE); $arrDomain['t_cfg'] = json_encode($TCfgTemplate, JSON_UNESCAPED_UNICODE);
/** @var DomainModel **/
$DomainModel = DomainModel::where('d_domain', $arrDomain['d_domain'])->findOrEmpty(); $DomainModel = DomainModel::where('d_domain', $arrDomain['d_domain'])->findOrEmpty();
$DomainModel->fill($arrDomain); $DomainModel->fill($arrDomain);
$DomainModel->save(); $DomainModel->save();
DomainModel::flushAllDomianOnCache();
} }
@@ -179,6 +182,7 @@ class Site extends BaseController
$this->validate($arrData, $arrRule); $this->validate($arrData, $arrRule);
if ($arrData['d_id']) { if ($arrData['d_id']) {
/** @var DomainModel **/
$DomainModel = DomainModel::where('d_id', $arrData['d_id'])->findOrEmpty(); $DomainModel = DomainModel::where('d_id', $arrData['d_id'])->findOrEmpty();
} else { } else {
$DomainModel = new DomainModel; $DomainModel = new DomainModel;
@@ -187,6 +191,8 @@ class Site extends BaseController
$DomainModel->fill($arrData); $DomainModel->fill($arrData);
$DomainModel->save(); $DomainModel->save();
DomainModel::flushAllDomianOnCache();
return $this->success(); return $this->success();
} }
@@ -347,13 +353,15 @@ class Site extends BaseController
SubjectFomartGroupModel::whereIn('sfg_id', $arrSfgId)->delete(); SubjectFomartGroupModel::whereIn('sfg_id', $arrSfgId)->delete();
SubjectFomartModel::whereIn('sfg_id', $arrSfgId)->delete();
return $this->success(); return $this->success();
} }
/** /**
* 替换模板分组列表 * 替换模板分组列表
* *
* @param Request $Request * @param Request $Request
@@ -387,7 +395,7 @@ class Site extends BaseController
}); });
} }
if (!empty($arrData['sfg_id'])) { if (!empty($arrData['sfg_id'])) {
$SubjectFomartModel->where('sf.sfg_id',$arrData['sfg_id']); $SubjectFomartModel->where('sf.sfg_id', $arrData['sfg_id']);
} }
$Paginate = $SubjectFomartModel->paginate([ $Paginate = $SubjectFomartModel->paginate([

View File

@@ -5,6 +5,7 @@ declare(strict_types=1);
namespace app\model; namespace app\model;
use think\Request; use think\Request;
use think\exception\HttpException;
class AutoSwitchViewModel class AutoSwitchViewModel
{ {
@@ -14,11 +15,21 @@ class AutoSwitchViewModel
$strDomain = $Request->rootDomain(); $strDomain = $Request->rootDomain();
// var_dump($strDomain); $DomainModel = DomainModel::getDomainOnCacheByDomain($strDomain);
$DomainModel = DomainModel::getDomainByCache($strDomain); if (empty($DomainModel)) {
throw new HttpException(404, 'Site config not Found');
}
$TemplatesModel = TemplatesModel::getTemplateOnCache($DomainModel->t_id); // echo $DomainModel->getFomartSubject('NV_SHENG_URL');
// exit;
$TemplatesModel = TemplatesModel::getTemplateOnCacheByTId($DomainModel->t_id);
if (empty($DomainModel)) {
throw new HttpException(500, 'Site template not Found');
}
$Request->DomainModel = $DomainModel; $Request->DomainModel = $DomainModel;

View File

@@ -17,20 +17,57 @@ class DomainModel extends BaseModel
protected $json = ['t_cfg']; protected $json = ['t_cfg'];
static public $arrAllDomain = [];
static public function getDomainByCache($strDomain) /**
* Undocumented function
*
* @return array
*/
static public function getAllDomainOnCache(): array
{ {
$strKey = "D:" . $strDomain; if (empty(self::$arrAllDomain)) {
return DomainModel::where('d_domain', $strDomain)->cache($strKey, 24 * 3600)->find(); $strKey = 'Domain:All';
self::$arrAllDomain = Cache::get($strKey);
if (empty(self::$arrAllDomain)) {
self::flushAllDomianOnCache();
}
}
return self::$arrAllDomain;
} }
static public function flushDomainCache($strDomain) /**
* Undocumented function
*
* @return void
*/
static public function flushAllDomianOnCache()
{ {
$strKey = "D:" . $strDomain;
return Cache::delete($strKey); self::$arrAllDomain = [];
$strKey = 'Domain:All';
$DomainModelAll = DomainModel::select();
foreach ($DomainModelAll as $DomainModel) {
self::$arrAllDomain[$DomainModel->d_domain] = $DomainModel;
}
return Cache::set($strKey, self::$arrAllDomain);
} }
/**
* Undocumented function
*
* @param string $strDomain
* @return DomainModel|NULL
*/
static public function getDomainOnCacheByDomain($strDomain): DomainModel|NULL
{
if (key_exists($strDomain, self::getAllDomainOnCache())) {
return self::getAllDomainOnCache()[$strDomain];
}
return NULL;
}
/** /**
* Undocumented function * Undocumented function
@@ -59,19 +96,20 @@ class DomainModel extends BaseModel
*/ */
public function getFomartSubject($strKey) //, $intNum = 1, $boolRand = false) public function getFomartSubject($strKey) //, $intNum = 1, $boolRand = false)
{ {
// echo $strKey;
// exit;
// echo '<pre>';
// var_dump($this->t_cfg);
// exit;
$intSfgId = $this->t_cfg->{$strKey}['sfg_id']; $intSfgId = $this->t_cfg->{$strKey}['sfg_id'];
// $SubjectFomartCol = SubjectFomartModel::where('sfg_id', $intSfgId)->select();
$SubjectFomartModel = SubjectFomartModel::where('sfg_id', $intSfgId)->select()->first(); // $SubjectFomartModel = SubjectFomartModel::where('sfg_id', $intSfgId)->select()->first();
// var_dump($SubjectFomartModel->toArray()); $arrAllSubjectFomartModel = SubjectFomartModel::getAllSubjectFomartOnCacheBySfgId($intSfgId);
$SubjectFomartModel = (is_array($arrAllSubjectFomartModel) && !empty($arrAllSubjectFomartModel)) ? reset($arrAllSubjectFomartModel) : null;
return empty($SubjectFomartModel) ? '' : $SubjectFomartModel->sf_val;
// echo '<pre>';
// print_r($SubjectFomartModel);
// exit; // exit;
return $SubjectFomartModel->sf_val; // return $SubjectFomartModel->sf_val;
} }
@@ -79,14 +117,11 @@ class DomainModel extends BaseModel
* Undocumented function * Undocumented function
* *
* @param array $arrArgs * @param array $arrArgs
* @return void * @return string
*/ */
static public function getPageUrl($strKey, array $arrArgs): string static public function getPageUrl($strKey, array $arrArgs): string
{ {
$Request = request(); $Request = request();
// $strKey = $Request->controller(false, true) . '@' .
// $Request->action(true) . '@URL';
// $strKey = strtoupper($strKey);
$strSfVal = $Request->DomainModel->getFomartSubject($strKey); $strSfVal = $Request->DomainModel->getFomartSubject($strKey);

View File

@@ -14,4 +14,43 @@ class SubjectFomartModel extends BaseModel
{ {
protected $name = 'subject_fomart'; protected $name = 'subject_fomart';
protected $pk = 'sf_id'; protected $pk = 'sf_id';
static public $arrAllSubjectFomart = [];
/**
* Undocumented function
*
* @param integer $intSfgId
* @return SubjectFomartModel[]
*/
static public function getAllSubjectFomartOnCacheBySfgId(int $intSfgId): array
{
if (empty(self::$arrAllSubjectFomart)) {
$strKey = 'SubjectFomart:All';
self::$arrAllSubjectFomart = Cache::get($strKey);
if (empty(self::$arrAllSubjectFomart)) {
self::flushAllSubjectFomartOnCache();
}
}
return self::$arrAllSubjectFomart[$intSfgId] ?? [];
}
/**
* Undocumented function
*
* @return void
*/
static public function flushAllSubjectFomartOnCache()
{
self::$arrAllSubjectFomart = [];
$strKey = 'SubjectFomart:All';
$SubjectFomartModelAll = SubjectFomartModel::select();
foreach ($SubjectFomartModelAll as $SubjectFomartModel) {
self::$arrAllSubjectFomart[$SubjectFomartModel->sfg_id][] = $SubjectFomartModel;
}
return Cache::set($strKey, self::$arrAllSubjectFomart);
}
} }

View File

@@ -32,29 +32,55 @@ class TemplatesModel extends BaseModel
// } // }
// } // }
static public $arrAllTemplate = [];
static $arrTemplates = []; /**
* Undocumented function
static public function getTemplateOnCache($intTId) *
* @return array
*/
static public function getAllTemplateOnCache(): array
{ {
if (self::$arrTemplates == []) { if (empty(self::$arrAllTemplate)) {
self::$arrTemplates = Cache::get('Templates'); $strKey = 'Template:All';
self::$arrAllTemplate = Cache::get($strKey);
if (empty(self::$arrTemplates)) { if (empty(self::$arrAllTemplate)) {
self::flushCache(); self::flushAllTemplateOnCache();
self::$arrTemplates = Cache::get('Templates');
} }
} }
return self::$arrAllTemplate;
return self::$arrTemplates[$intTId] ?? NULL;
} }
static public function flushCache() /**
* Undocumented function
*
* @return void
*/
static public function flushAllTemplateOnCache()
{ {
$TemplatesModelAll = self::select();
$TemplatesCol = $TemplatesModelAll->column(null, 't_id'); self::$arrAllTemplate = [];
$strKey = 'Template:All';
$TemplateModelAll = self::select();
foreach ($TemplateModelAll as $TemplateModel) {
self::$arrAllTemplate[$TemplateModel->t_id] = $TemplateModel;
}
Cache::tag('Templates')->set('Templates', $TemplatesCol); return Cache::set($strKey, self::$arrAllTemplate);
}
/**
* Undocumented function
*
* @param int $intTId
* @return TemplatesModel|NULL
*/
static public function getTemplateOnCacheByTId(int $intTId): TemplatesModel|NULL
{
if (key_exists($intTId, self::getAllTemplateOnCache())) {
return self::getAllTemplateOnCache()[$intTId];
}
return NULL;
} }
} }

View File

@@ -9,7 +9,6 @@ class WordsEntities
static public function getWords($strWords) static public function getWords($strWords)
{ {
if (!isset(self::$arrZiKu[$strWords])) { if (!isset(self::$arrZiKu[$strWords])) {
self::$arrZiKu[$strWords] = customEntities($strWords); self::$arrZiKu[$strWords] = customEntities($strWords);
} }