debug
This commit is contained in:
@@ -78,10 +78,13 @@ class Site extends BaseController
|
||||
|
||||
$arrDomain['t_cfg'] = json_encode($TCfgTemplate, JSON_UNESCAPED_UNICODE);
|
||||
|
||||
/** @var DomainModel **/
|
||||
$DomainModel = DomainModel::where('d_domain', $arrDomain['d_domain'])->findOrEmpty();
|
||||
|
||||
$DomainModel->fill($arrDomain);
|
||||
$DomainModel->save();
|
||||
|
||||
DomainModel::flushAllDomianOnCache();
|
||||
}
|
||||
|
||||
|
||||
@@ -179,6 +182,7 @@ class Site extends BaseController
|
||||
$this->validate($arrData, $arrRule);
|
||||
|
||||
if ($arrData['d_id']) {
|
||||
/** @var DomainModel **/
|
||||
$DomainModel = DomainModel::where('d_id', $arrData['d_id'])->findOrEmpty();
|
||||
} else {
|
||||
$DomainModel = new DomainModel;
|
||||
@@ -187,6 +191,8 @@ class Site extends BaseController
|
||||
$DomainModel->fill($arrData);
|
||||
|
||||
$DomainModel->save();
|
||||
DomainModel::flushAllDomianOnCache();
|
||||
|
||||
return $this->success();
|
||||
}
|
||||
|
||||
@@ -347,13 +353,15 @@ class Site extends BaseController
|
||||
|
||||
SubjectFomartGroupModel::whereIn('sfg_id', $arrSfgId)->delete();
|
||||
|
||||
SubjectFomartModel::whereIn('sfg_id', $arrSfgId)->delete();
|
||||
|
||||
return $this->success();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
/**
|
||||
* 替换模板分组列表
|
||||
*
|
||||
* @param Request $Request
|
||||
@@ -387,7 +395,7 @@ class Site extends BaseController
|
||||
});
|
||||
}
|
||||
if (!empty($arrData['sfg_id'])) {
|
||||
$SubjectFomartModel->where('sf.sfg_id',$arrData['sfg_id']);
|
||||
$SubjectFomartModel->where('sf.sfg_id', $arrData['sfg_id']);
|
||||
}
|
||||
|
||||
$Paginate = $SubjectFomartModel->paginate([
|
||||
|
||||
@@ -5,6 +5,7 @@ declare(strict_types=1);
|
||||
namespace app\model;
|
||||
|
||||
use think\Request;
|
||||
use think\exception\HttpException;
|
||||
|
||||
class AutoSwitchViewModel
|
||||
{
|
||||
@@ -14,14 +15,24 @@ class AutoSwitchViewModel
|
||||
|
||||
$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->TemplatesModel = $TemplatesModel;
|
||||
|
||||
return [
|
||||
|
||||
@@ -17,20 +17,57 @@ class DomainModel extends BaseModel
|
||||
|
||||
protected $json = ['t_cfg'];
|
||||
|
||||
static public $arrAllDomain = [];
|
||||
|
||||
static public function getDomainByCache($strDomain)
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
static public function getAllDomainOnCache(): array
|
||||
{
|
||||
$strKey = "D:" . $strDomain;
|
||||
return DomainModel::where('d_domain', $strDomain)->cache($strKey, 24 * 3600)->find();
|
||||
if (empty(self::$arrAllDomain)) {
|
||||
$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
|
||||
@@ -59,19 +96,20 @@ class DomainModel extends BaseModel
|
||||
*/
|
||||
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'];
|
||||
// $SubjectFomartCol = SubjectFomartModel::where('sfg_id', $intSfgId)->select();
|
||||
|
||||
$SubjectFomartModel = SubjectFomartModel::where('sfg_id', $intSfgId)->select()->first();
|
||||
// var_dump($SubjectFomartModel->toArray());
|
||||
// $SubjectFomartModel = SubjectFomartModel::where('sfg_id', $intSfgId)->select()->first();
|
||||
$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;
|
||||
|
||||
return $SubjectFomartModel->sf_val;
|
||||
// return $SubjectFomartModel->sf_val;
|
||||
}
|
||||
|
||||
|
||||
@@ -79,14 +117,11 @@ class DomainModel extends BaseModel
|
||||
* Undocumented function
|
||||
*
|
||||
* @param array $arrArgs
|
||||
* @return void
|
||||
* @return string
|
||||
*/
|
||||
static public function getPageUrl($strKey, array $arrArgs): string
|
||||
{
|
||||
$Request = request();
|
||||
// $strKey = $Request->controller(false, true) . '@' .
|
||||
// $Request->action(true) . '@URL';
|
||||
// $strKey = strtoupper($strKey);
|
||||
|
||||
$strSfVal = $Request->DomainModel->getFomartSubject($strKey);
|
||||
|
||||
|
||||
@@ -14,4 +14,43 @@ class SubjectFomartModel extends BaseModel
|
||||
{
|
||||
protected $name = 'subject_fomart';
|
||||
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);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -32,29 +32,55 @@ class TemplatesModel extends BaseModel
|
||||
// }
|
||||
// }
|
||||
|
||||
static public $arrAllTemplate = [];
|
||||
|
||||
static $arrTemplates = [];
|
||||
|
||||
static public function getTemplateOnCache($intTId)
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
static public function getAllTemplateOnCache(): array
|
||||
{
|
||||
if (self::$arrTemplates == []) {
|
||||
self::$arrTemplates = Cache::get('Templates');
|
||||
|
||||
if (empty(self::$arrTemplates)) {
|
||||
self::flushCache();
|
||||
self::$arrTemplates = Cache::get('Templates');
|
||||
if (empty(self::$arrAllTemplate)) {
|
||||
$strKey = 'Template:All';
|
||||
self::$arrAllTemplate = Cache::get($strKey);
|
||||
if (empty(self::$arrAllTemplate)) {
|
||||
self::flushAllTemplateOnCache();
|
||||
}
|
||||
}
|
||||
|
||||
return self::$arrTemplates[$intTId] ?? NULL;
|
||||
return self::$arrAllTemplate;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user