2020-01-01 13:17:19 +08:00
|
|
|
<?php
|
|
|
|
declare (strict_types = 1);
|
|
|
|
|
|
|
|
namespace app\common\controller;
|
|
|
|
|
|
|
|
use think\App;
|
|
|
|
use think\facade\View;
|
|
|
|
use think\facade\Db;
|
|
|
|
use think\facade\Session;
|
|
|
|
use think\facade\Cache;
|
2021-07-16 17:42:07 +08:00
|
|
|
use app\BaseController as BaseCtrl;
|
2020-01-01 13:17:19 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* 控制器基础类
|
|
|
|
*/
|
2021-07-16 17:42:07 +08:00
|
|
|
class BaseController extends BaseCtrl
|
2020-01-01 13:17:19 +08:00
|
|
|
{
|
|
|
|
// 初始化
|
|
|
|
protected function initialize()
|
|
|
|
{
|
2021-07-16 17:42:07 +08:00
|
|
|
$this->uid = Session::get('user_id');
|
2020-01-01 13:17:19 +08:00
|
|
|
//系统配置
|
|
|
|
$this->showSystem();
|
|
|
|
//显示分类导航
|
|
|
|
$this->showNav();
|
2021-07-22 10:54:03 +08:00
|
|
|
$this->showUser($this->uid);
|
2020-01-01 13:17:19 +08:00
|
|
|
|
2021-07-16 17:42:07 +08:00
|
|
|
}
|
2020-01-01 13:17:19 +08:00
|
|
|
|
|
|
|
//判断是否已登录?
|
|
|
|
protected function isLogged()
|
|
|
|
{
|
|
|
|
if(Session::has('user_id')){
|
|
|
|
$this->success('您已登录','/index/index/index');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//判断是否需要登录?
|
|
|
|
protected function isLogin()
|
|
|
|
{
|
|
|
|
if(!Session::has('user_id')){
|
|
|
|
$this->error('请登录','/index/user/login');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* //判断密码找回是否已进行了邮件发送?
|
|
|
|
protected function isMailed()
|
|
|
|
{
|
|
|
|
if(Cache::get('repass') != 1){
|
|
|
|
$this->error('错误请求,请正确操作!','/index/user/forget');
|
|
|
|
}
|
|
|
|
}*/
|
|
|
|
|
|
|
|
// 显示导航
|
|
|
|
protected function showNav()
|
|
|
|
{
|
|
|
|
//1.查询分类表获取所有分类
|
2020-03-13 22:59:38 +08:00
|
|
|
$cateList = Db::name('cate')->where(['status'=>1,'delete_time'=>0])->order('sort','asc')->cache('catename',3600)->select();
|
2020-01-01 13:17:19 +08:00
|
|
|
|
|
|
|
//2.将catelist变量赋给模板 公共模板nav.html
|
|
|
|
View::assign('cateList',$cateList);
|
2021-08-03 17:33:48 +08:00
|
|
|
return $cateList;
|
2020-01-01 13:17:19 +08:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2020-05-15 17:04:04 +08:00
|
|
|
//显示当前登录用户
|
2021-07-22 10:54:03 +08:00
|
|
|
protected function showUser($id)
|
2020-01-01 13:17:19 +08:00
|
|
|
{
|
2020-05-15 17:04:04 +08:00
|
|
|
$user = Cache::get('user'.$id);
|
|
|
|
if(!$user){
|
|
|
|
//1.查询用户
|
2021-08-07 15:50:50 +08:00
|
|
|
$user = Db::name('user')->field('id,name,nickname,user_img,sex,area_id,auth,city,email,active,sign,point,vip,create_time')->find($id);
|
2020-05-15 17:04:04 +08:00
|
|
|
Cache::tag('user')->set('user'.$id,$user,600);
|
|
|
|
}
|
|
|
|
|
2020-03-05 20:15:01 +08:00
|
|
|
//2.将User变量赋给模板 公共模板nav.html
|
|
|
|
View::assign('user',$user);
|
2021-07-22 10:54:03 +08:00
|
|
|
return $user;
|
2020-01-01 13:17:19 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
//显示网站设置
|
|
|
|
protected function showSystem()
|
|
|
|
{
|
|
|
|
//1.查询分类表获取所有分类
|
2020-03-13 22:59:38 +08:00
|
|
|
$sysInfo = Db::name('system')->cache('system',3600)->find(1);
|
2021-07-07 17:17:58 +08:00
|
|
|
//头部链接
|
|
|
|
$head_links = Cache::get('headlinks');
|
|
|
|
if(!$head_links){
|
2021-07-22 10:43:48 +08:00
|
|
|
$head_links = Db::name('slider')->where(['slid_status'=>1,'delete_time'=>0,'slid_type'=>10])->whereTime('slid_over','>=',time())->field('slid_name,slid_img,slid_href')->select();
|
2021-07-07 17:17:58 +08:00
|
|
|
Cache::set('headlinks',$head_links,3600);
|
|
|
|
}
|
|
|
|
//页脚链接
|
|
|
|
$foot_links = Cache::get('footlinks');
|
|
|
|
if(!$foot_links){
|
2021-07-22 10:43:48 +08:00
|
|
|
$foot_links = Db::name('slider')->where(['slid_status'=>1,'delete_time'=>0,'slid_type'=>11])->whereTime('slid_over','>=',time())->field('slid_name,slid_href')->select();
|
2021-07-07 17:17:58 +08:00
|
|
|
Cache::set('footlinks',$foot_links,3600);
|
|
|
|
}
|
|
|
|
View::assign(['sysInfo'=>$sysInfo,'headlinks'=>$head_links,'footlinks'=>$foot_links]);
|
2021-08-03 17:33:48 +08:00
|
|
|
return $sysInfo;
|
2020-01-01 13:17:19 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|