修复代码增加统计,增加redis
This commit is contained in:
@@ -6,7 +6,8 @@ namespace app\index\controller;
|
||||
use think\App;
|
||||
use think\facade\View;
|
||||
use think\facade\Request;
|
||||
use think\facade\Config;
|
||||
use think\facade\Db;
|
||||
use app\service\VisitStatsService;
|
||||
|
||||
/**
|
||||
* 前台控制器基础类
|
||||
@@ -18,6 +19,7 @@ abstract class BaseController
|
||||
* @var \think\Request
|
||||
*/
|
||||
protected $request;
|
||||
protected $visitStats;
|
||||
|
||||
/**
|
||||
* 应用实例
|
||||
@@ -34,6 +36,7 @@ abstract class BaseController
|
||||
{
|
||||
$this->app = $app;
|
||||
$this->request = $this->app->request;
|
||||
$this->visitStats = new VisitStatsService();
|
||||
|
||||
// 控制器初始化
|
||||
$this->initialize();
|
||||
@@ -44,20 +47,25 @@ abstract class BaseController
|
||||
*/
|
||||
protected function initialize()
|
||||
{
|
||||
// 记录访问
|
||||
$this->visitStats->recordVisit($this->getControllerName());
|
||||
|
||||
// 获取配置
|
||||
$configList = Db::table('yz_admin_config')
|
||||
->where('config_status', 1)
|
||||
->order('config_sort DESC')
|
||||
->select()
|
||||
->toArray();
|
||||
|
||||
// 将配置数据转换为键值对形式
|
||||
$config = [];
|
||||
foreach ($configList as $item) {
|
||||
$config[$item['config_name']] = $item['config_value'];
|
||||
}
|
||||
|
||||
// 设置通用变量
|
||||
View::assign([
|
||||
'site_name' => '网站名称',
|
||||
'site_description' => '网站描述',
|
||||
'site_keywords' => '网站关键词',
|
||||
'config' => [
|
||||
'admin_name' => Config::get('site.name', '云泽科技'),
|
||||
'admin_phone' => Config::get('site.phone', '400-123-4567'),
|
||||
'admin_email' => Config::get('site.email', 'admin@example.com'),
|
||||
'admin_wechat' => Config::get('site.wechat_qrcode', '/static/images/wechat_qrcode.jpg'),
|
||||
'logo' => Config::get('site.logo', '/static/images/logo.png'),
|
||||
'logo1' => Config::get('site.logo1', '/static/images/logo1.png'),
|
||||
'admin_route' => Config::get('site.admin_route', '/admin/')
|
||||
]
|
||||
'config' => $config
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user